Sign in to follow this  

[SDL] 16-bit colorkey

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

If you intended to correct an error in the post then please contact us.

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?

Share this post


Link to post
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 this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this