• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# SDL & SDL_SetColorKey()

## Recommended Posts

i''m getting a really wierd problem. i can get SDL_SetColorKey() to work perfectly on surface "surface". But, if i make an identical (int size && depth) surface, blit from "surface" to "tempSurface", then blit from "tempSurface" to "surface", the ColorKey doesnt work anymore... So, i tried resetting the color key, and nothing. Still the ugly pink (supposed to be clear) background on my surface.... Any suggestions?? <the getting madder fast> MadProgrammer

##### Share on other sites
Why are you blitting to a surface and then back again? Are you altering the surface format at all? Could you post a small example of what you''re doing?

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]

##### Share on other sites
  surface = SDL_LoadBMP(temp);SDL_SetColorKey(surface, SDL_SRCCOLORKEY, SDL_MapRGB(surface->format, br, bg, bb));SDL_Surface *surf = SDL_CreateRGBSurface(SDL_HWSURFACE, surface->w, surface->h, surface->format->BytesPerPixel, surface->format->Rmask, surface->format->Gmask, surface->format->Bmask, surface->format->Amask);SDL_BlitSurface(surface, 0, surf, 0);SDL_BlitSurface(surf, 0, surface, 0);SDL_FreeSurface(surf);SDL_SetColorKey(surface, SDL_SRCCOLORKEY, SDL_MapRGB(surface->format, br, bg, bb));

w/ or w/o that last color key, "surface" is NOT color keyed
if i just do the first 2 lines (loadBMP & SetColorKey), the surface IS color keyed

i'm stumped 100%

Edited by - MadProgrammer on January 30, 2002 4:31:50 PM [/source]

Edited by - MadProgrammer on January 30, 2002 4:32:19 PM

##### Share on other sites
The color key is not applied until you blit or convert the surface. Perhaps the surface is being converted when you first blit from it, such that your color key is no longer valid. This could be because your image is being loaded in a different bit depth to your video resolution. I don''t see why this wouldn''t work following the last line, but the problem might be something like this. I suggest you post on the SDL mailing list (http://www.libsdl.org/mailman/listinfo/sdl) and see what they say. If you get a good answer, post it back up here so we can see what it was.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627651
• Total Posts
2978404

• 10
• 12
• 22
• 13
• 33