fixed cave flashing on open outbox for non-black cave background color
authorHolger Schemel <holger.schemel@virtion.de>
Sat, 11 May 2024 11:47:14 +0000 (13:47 +0200)
committerHolger Schemel <holger.schemel@virtion.de>
Sat, 11 May 2024 11:47:16 +0000 (13:47 +0200)
src/game_bd/bd_graphics.c
src/libgame/sdl.c
src/libgame/sdl.h

index aa091ba131b44404613d50aebcdde97ce18ee4d6..96e9b20c2fb277d542de9386d9082ee736ee440a 100644 (file)
@@ -466,8 +466,14 @@ static Bitmap *get_tile_bitmap_c64(GdCave *cave, SDL_Surface *surface)
   set_surface_palette_color(surface, 7, 0);
   set_surface_palette_color(surface, 8, 0);
 
+  // set background color to be transparent for masked tile bitmap
+  int bg_color = gd_color_get_rgb(cave->color0);
+  int bg_r = gd_color_get_r(bg_color);
+  int bg_g = gd_color_get_g(bg_color);
+  int bg_b = gd_color_get_b(bg_color);
+
   // create bitmap from C64 surface
-  tile_bitmap_c64 = SDLGetBitmapFromSurface(surface);
+  tile_bitmap_c64 = SDLGetBitmapFromSurface_WithMaskedColor(surface, bg_r, bg_g, bg_b);
 
   return tile_bitmap_c64;
 }
index a19defa37acc5a7f7cc8cc07eeb958db0eafe973..d664eecc01df267ae8a86aff5f04e29cb43abbdc 100644 (file)
@@ -502,7 +502,7 @@ SDL_Surface *SDLCreateNativeSurface(int width, int height, int depth)
   return surface;
 }
 
-Bitmap *SDLGetBitmapFromSurface(SDL_Surface *surface)
+Bitmap *SDLGetBitmapFromSurface_WithMaskedColor(SDL_Surface *surface, int r, int g, int b)
 {
   int width  = surface->w;
   int height = surface->h;
@@ -522,11 +522,16 @@ Bitmap *SDLGetBitmapFromSurface(SDL_Surface *surface)
   if (!SDLHasAlpha(bitmap->surface_masked) &&
       !SDLHasColorKey(bitmap->surface_masked))
     SDL_SetColorKey(bitmap->surface_masked, SET_TRANSPARENT_PIXEL,
-                   SDL_MapRGB(bitmap->surface_masked->format, 0x00, 0x00, 0x00));
+                   SDL_MapRGB(bitmap->surface_masked->format, r, g, b));
 
   return bitmap;
 }
 
+Bitmap *SDLGetBitmapFromSurface(SDL_Surface *surface)
+{
+  return SDLGetBitmapFromSurface_WithMaskedColor(surface, 0x00, 0x00, 0x00);
+}
+
 static SDL_Texture *SDLCreateTextureFromSurface(SDL_Surface *surface)
 {
   if (program.headless)
index bbbaa7675919640c264161d7f86a9a467b35669c..1545f6865fbc80317f3e53af68c6a6cf8b27da39 100644 (file)
@@ -400,6 +400,7 @@ const char *SDLGetRendererName(void);
 boolean SDLSetNativeSurface(SDL_Surface **);
 SDL_Surface *SDLGetNativeSurface(SDL_Surface *);
 SDL_Surface *SDLCreateNativeSurface(int, int, int);
+Bitmap *SDLGetBitmapFromSurface_WithMaskedColor(SDL_Surface *, int, int, int);
 Bitmap *SDLGetBitmapFromSurface(SDL_Surface *);
 void SDLCreateBitmapTextures(Bitmap *);
 void SDLFreeBitmapTextures(Bitmap *);