Jump to content
  • Advertisement
Sign in to follow this  
Eddy999999

[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.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!