From dc9b56a7650dd65d574c0e33ea7cb9e1612622f7 Mon Sep 17 00:00:00 2001 From: Silvan Jegen Date: Mon, 7 Jan 2019 21:59:53 +0100 Subject: Start porting code to SDL2 (WIP) --- render.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 8a91b59..faea80f 100644 --- a/render.c +++ b/render.c @@ -49,7 +49,7 @@ void get_pixmap_level( char number, SDL_Rect * crop ) // render() paints everything onto the screen when called -void render( struct level_struct *currentlevel, SDL_Surface * surf_screen ) +void render(SDL_Renderer* renderer, struct level_struct *currentlevel, SDL_Texture * surf_screen ) { /* The picture on-screen is made in three steps: * 1) Draw the level onto the screen surface @@ -87,7 +87,9 @@ void render( struct level_struct *currentlevel, SDL_Surface * surf_screen ) destination.y = tiley * TILE_SIZE; /// Draw this tile onto the screen - SDL_BlitSurface ( currentlevel->surf_tiles, &pixmap_crop, surf_screen, &destination ); + //SDL_BlitSurface ( currentlevel->surf_tiles, &pixmap_crop, surf_screen, &destination ); + + SDL_UpdateTexture(surf_screen, &destination, currentlevel->surf_tiles, 640 * sizeof (Uint32)); } } @@ -98,7 +100,8 @@ void render( struct level_struct *currentlevel, SDL_Surface * surf_screen ) destination.y = currentlevel->py * TILE_SIZE; // Draw onto screen - SDL_BlitSurface ( currentlevel->surf_entities, &pixmap_crop, surf_screen, &destination ); + //SDL_BlitSurface ( currentlevel->surf_entities, &pixmap_crop, surf_screen, &destination ); + SDL_UpdateTexture(surf_screen, &destination, currentlevel->surf_entities, 640 * sizeof (Uint32)); // Now draw all of the echidnas int ech_no; // Echidna number @@ -117,21 +120,32 @@ void render( struct level_struct *currentlevel, SDL_Surface * surf_screen ) destination.y = current_echidna.ypos * TILE_SIZE; // Draw it onscreen - SDL_BlitSurface ( currentlevel->surf_entities, &pixmap_crop, surf_screen, &destination ); + // SDL_BlitSurface ( currentlevel->surf_entities, &pixmap_crop, surf_screen, &destination ); + SDL_UpdateTexture(surf_screen, &destination, currentlevel->surf_entities, 640 * sizeof (Uint32)); } } /// Flip screen, so everything we have 'blitted' can now be seen - SDL_Flip( surf_screen ); - + //SDL_Flip( surf_screen ); + + SDL_RenderClear(renderer); + SDL_RenderCopy(renderer, surf_screen, NULL, NULL); + SDL_RenderPresent(renderer); } -void render_a_losingscreen( struct level_struct *currentlevel, SDL_Surface * surf_screen ) +void render_a_losingscreen(SDL_Renderer* renderer, struct level_struct *currentlevel, SDL_Texture * surf_screen ) { // Render a losing screen - SDL_BlitSurface ( currentlevel->surf_losingscreens[0], NULL, surf_screen, NULL ); - SDL_Flip( surf_screen ); + //SDL_BlitSurface ( currentlevel->surf_losingscreens[0], NULL, surf_screen, NULL ); + + SDL_UpdateTexture(surf_screen, NULL, currentlevel->surf_losingscreens[0], 640 * sizeof (Uint32)); + + //SDL_Flip( surf_screen ); + + SDL_RenderClear(renderer); + SDL_RenderCopy(renderer, surf_screen, NULL, NULL); + SDL_RenderPresent(renderer); // Wait a second so the user can see the losing screen SDL_Delay(500); -- cgit v1.2.1-18-gbd029