# [SDL] 16-bit colorkey

This topic is 3806 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I was having some low frame rates in my SDL app, so I tried changing the bpp from 32 to 16. This increased my frame rates substantially, but now my transparency isn't working for some reason. I'm using this line to set the transparency for a surface:
SDL_SetColorKey(surface,SDL_SRCCOLORKEY|SDL_RLEACCEL,0xFF00FF);
It works just fine when I run it at 32bpp, but it doesn't work when I run it at 16bpp (the pink rectangle still shows). Does anyone have any idea why it might be doing this?

Anyone?

##### Share on other sites
int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key);

As you can see the key (the actual rgb color) is referenced as a 32 bit integer. In 32 bit mode your hex works fine (for now) as your colors are mapped accordingly. I use the word map here because you will need to map the 32 bit color to a 16 bit color or more specifically the same format as the surface using SDL_MapRGB.

Uint32 SDL_MapRGBA(SDL_PixelFormat *fmt, Uint8 r, Uint8 g, Uint8 b, Uint8 a);

The final product would look something like:
SDL_SetColorKey(surface,SDL_SRCCOLORKEY|SDL_RLEACCEL, SDL_MapRGB( surface->format, 0xff, 0x00, 0xff ) );

I actually find decimal numbers to work a little easier for me here but since you used hex...

##### Share on other sites
That did the trick. Thanks =D

1. 1
2. 2
Rutin
23
3. 3
JoeJ
20
4. 4
5. 5

• 24
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631734
• Total Posts
3001933
×