From 92a4fbb74a151038391ddc03cb48e6b567776a0d Mon Sep 17 00:00:00 2001 From: Silvan Jegen Date: Sun, 13 Jan 2019 17:42:01 +0100 Subject: Fix pixel format issues --- game.c | 3 --- level.c | 34 +++++++++++++++------------------- main.c | 2 ++ render.c | 4 +++- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/game.c b/game.c index 45c029f..ced2f60 100644 --- a/game.c +++ b/game.c @@ -148,11 +148,8 @@ int play_level(SDL_Renderer* renderer, struct level_struct *currentlevel, SDL_Te // Show a losing screen if applicable if (player_status == PLAYER_IS_DEAD) render_a_losingscreen(renderer, currentlevel, surf_screen); } - } - - // The code running play_level needs to know if too advance to the next level // or just repeat the current one ( if the player has died ) return player_status; diff --git a/level.c b/level.c index 8e47bf2..6097f23 100644 --- a/level.c +++ b/level.c @@ -102,13 +102,23 @@ void eat_until_newline( FILE *currentfile ) void level_load_resources(SDL_Renderer* renderer, struct level_struct *level ) { // Load the images for things into their own 'surfaces' - level->surf_entities = IMG_Load( "entities.png" ); + SDL_Surface* surf_entities = IMG_Load( "entities.png" ); + level->surf_entities = SDL_ConvertSurfaceFormat(surf_entities, + SDL_PIXELFORMAT_ARGB8888, 0); - level->surf_tiles = IMG_Load( "tiles.png" ); + SDL_Surface* surf_tiles = IMG_Load( "tiles.png" ); + level->surf_tiles = SDL_ConvertSurfaceFormat(surf_tiles, + SDL_PIXELFORMAT_ARGB8888, 0); // Do the same for the losing screens - level->surf_losingscreens[0] = IMG_Load("failscreen_01.png"); - level->surf_winning_screen = IMG_Load("winningscreen.png"); + + SDL_Surface* surf_losing = IMG_Load("failscreen_01.png"); + level->surf_losingscreens[0] = SDL_ConvertSurfaceFormat(surf_losing, + SDL_PIXELFORMAT_ARGB8888, 0); + + SDL_Surface* surf_win = IMG_Load("winningscreen.png"); + level->surf_winning_screen = SDL_ConvertSurfaceFormat(surf_win, + SDL_PIXELFORMAT_ARGB8888, 0); } @@ -149,7 +159,7 @@ void level_load( int level_number, struct level_struct *level ) /* Ieterate through the file and load the squares into the level's structure * Each row/line in the file represents a row of squares in the level * Each square is represented in the rows by a number from 0 to 255 - * Open up one of the level files with a text editor to study its structure further + * Open up one of the level files with a text editor to study its structure further */ /* WARNING: This code assumes the file is structured correctly in the first place! @@ -206,8 +216,6 @@ void level_load( int level_number, struct level_struct *level ) } - - // Replace every tile in the level of firsttype with secondtype // Useful for eg opening doors void level_replace_tiles( struct level_struct *currentlevel, char firsttype, char secondtype ) @@ -222,15 +230,3 @@ void level_replace_tiles( struct level_struct *currentlevel, char firsttype, cha } } } - - - - - - - - - - - - diff --git a/main.c b/main.c index 2a458d6..02b3e36 100644 --- a/main.c +++ b/main.c @@ -76,6 +76,8 @@ int main(int argc, char *argv[]) if (!surf_title) { error_sdl("could not get title surface\n"); } + surf_title = SDL_ConvertSurfaceFormat(surf_title, + SDL_PIXELFORMAT_ARGB8888, 0); SDL_Texture *surf_title_tex = SDL_CreateTextureFromSurface(renderer, surf_title); if (!surf_title_tex) { diff --git a/render.c b/render.c index 2e8e97d..4e5db41 100644 --- a/render.c +++ b/render.c @@ -87,6 +87,8 @@ 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 + // 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); @@ -122,7 +124,7 @@ 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, + SDL_UpdateTexture(surf_screen, &destination, currentlevel->surf_entities->pixels, currentlevel->surf_entities->pitch); } -- cgit v1.2.1-18-gbd029