From 4e3b66e4a82f7997ad9f1c2112e2af20728e406d Mon Sep 17 00:00:00 2001 From: Silvan Jegen Date: Sun, 13 Jan 2019 19:00:35 +0100 Subject: Use SDL_RenderCopy instead of SDL_UpdateTexture --- render.c | 53 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 13 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 4e5db41..a713d5e 100644 --- a/render.c +++ b/render.c @@ -87,14 +87,33 @@ void render(SDL_Renderer* renderer, struct level_struct *currentlevel, SDL_Textu /// Draw this tile onto the screen //SDL_BlitSurface ( currentlevel->surf_tiles, &pixmap_crop, surf_screen, &destination ); - // TODO: use pixmap_crop + // TODO: use pixmap_crop with SDL_RenderCopy? // printf("surf_tile format: %s\n", SDL_GetPixelFormatName(currentlevel->surf_tiles->format->format)); - SDL_UpdateTexture(surf_screen, &destination, - currentlevel->surf_tiles->pixels, - currentlevel->surf_tiles->pitch); + // SDL_UpdateTexture(surf_screen, &destination, + // currentlevel->surf_tiles->pixels, + // currentlevel->surf_tiles->pitch); + + printf("pixmap_crop x: %d, y: %d, w: %d, h: %d\n", + pixmap_crop.x, pixmap_crop.y, pixmap_crop.w, pixmap_crop.h); + + printf("destination x: %d, y: %d, w: %d, h: %d\n", + destination.x, destination.y, destination.w, destination.h); + + int ret = SDL_RenderCopy(renderer, currentlevel->surf_tiles_tex, + &pixmap_crop, + &destination); + printf("SDL_RenderCopy ret: %d\n", ret); + if (ret < 0 ) { + printf("Error (SDL): %s: %s\n", "could not render copy surf_tiles", SDL_GetError()); + } + + //printf("surf_tile pitch: %d\n", currentlevel->surf_tiles->pitch); } } - + + // SDL_RenderPresent(renderer); + // SDL_Delay(500); + /// Entity drawing // First of all the character get_pixmap_lemon( currentlevel->player_face, &pixmap_crop ); @@ -103,9 +122,13 @@ void render(SDL_Renderer* renderer, struct level_struct *currentlevel, SDL_Textu // Draw onto screen //SDL_BlitSurface ( currentlevel->surf_entities, &pixmap_crop, surf_screen, &destination ); - SDL_UpdateTexture(surf_screen, &destination, - currentlevel->surf_entities->pixels, - currentlevel->surf_entities->pitch); + //SDL_UpdateTexture(surf_screen, &destination, + // currentlevel->surf_entities->pixels, + // currentlevel->surf_entities->pitch); + + SDL_RenderCopy(renderer, currentlevel->surf_entities_tex, + &pixmap_crop, + &destination); // Now draw all of the echidnas int ech_no; // Echidna number @@ -124,17 +147,21 @@ void render(SDL_Renderer* renderer, struct level_struct *currentlevel, SDL_Textu // Draw it onscreen // SDL_BlitSurface ( currentlevel->surf_entities, &pixmap_crop, surf_screen, &destination ); - SDL_UpdateTexture(surf_screen, &destination, - currentlevel->surf_entities->pixels, - currentlevel->surf_entities->pitch); + // SDL_UpdateTexture(surf_screen, &destination, + // currentlevel->surf_entities->pixels, + // currentlevel->surf_entities->pitch); + + SDL_RenderCopy(renderer, currentlevel->surf_entities_tex, + &pixmap_crop, + &destination); } } /// Flip screen, so everything we have 'blitted' can now be seen //SDL_Flip( surf_screen ); - SDL_RenderClear(renderer); - SDL_RenderCopy(renderer, surf_screen, NULL, NULL); + //SDL_RenderClear(renderer); + //SDL_RenderCopy(renderer, surf_screen, NULL, NULL); SDL_RenderPresent(renderer); } -- cgit v1.2.1-18-gbd029