From: Holger Schemel Date: Mon, 27 Jun 2016 23:45:44 +0000 (+0200) Subject: fixed loading images with alpha channel or transparent color X-Git-Tag: 4.0.0.0~59 X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=commitdiff_plain;h=f44ab55ae6291508015eb306581f31d53c3cb5bd fixed loading images with alpha channel or transparent color --- diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 72bbc14a..30ca1794 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -2232,15 +2232,23 @@ Bitmap *SDLLoadImage(char *filename) return NULL; } + /* remove alpha channel from native non-transparent surface, if defined */ + SDLSetAlpha(new_bitmap->surface, FALSE, 0); + + /* remove transparent color from native non-transparent surface, if defined */ + SDL_SetColorKey(new_bitmap->surface, UNSET_TRANSPARENT_PIXEL, 0); + print_timestamp_time("SDL_DisplayFormat (opaque)"); UPDATE_BUSY_STATE(); - /* create native transparent surface for current image */ - if (sdl_image_tmp->format->Amask == 0) + /* set black pixel to transparent if no alpha channel / transparent color */ + if (!SDLHasAlpha(sdl_image_tmp) && + !SDLHasColorKey(sdl_image_tmp)) SDL_SetColorKey(sdl_image_tmp, SET_TRANSPARENT_PIXEL, SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00)); + /* create native transparent surface for current image */ if ((new_bitmap->surface_masked = SDLGetNativeSurface(sdl_image_tmp)) == NULL) { SetError("SDL_DisplayFormat(): %s", SDL_GetError());