Jump to content
  • Advertisement
Sign in to follow this  
Modred

[SDL] 32 bit Surface: Colorkey won't work

This topic is 2435 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

Short and simple: I create a 32 bit surface with alpha - channel (R8G8B8A8), and colorkeys stop working.

#include <SDL/SDL.h>
#include <iostream>
using namespace std;
int main(int argc, char **argv)
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_SetVideoMode(800, 480, 16, SDL_SWSURFACE);

//SDL_Surface *src = SDL_CreateRGBSurface(0, 400, 400, 32, 0xff<<16, 0xff<<8, 0xff, 0);
SDL_Surface *src = SDL_CreateRGBSurface(0, 400, 400, 32, 0xff<<24, 0xff<<16, 0xff<<8, 0xff<<0);


SDL_SetColorKey(src, SDL_SRCCOLORKEY, SDL_MapRGB(src->format, 255, 0, 128));
SDL_FillRect(src, NULL, SDL_MapRGB(src->format, 255, 0, 128));

SDL_BlitSurface(src, NULL, SDL_GetVideoSurface(), NULL);
SDL_Flip(SDL_GetVideoSurface());
SDL_Delay(2000);
}


...would I use the first, commented line to create the surface, everything works.

Share this post


Link to post
Share on other sites
Advertisement
Oha... Reffering to this:

if (source surface has SDL_SRCALPHA set) {
if (source surface has alpha channel (that is, format->Amask != 0))
blit using per-pixel alpha, ignoring any colour key
else {
if (source surface has SDL_SRCCOLORKEY set)
blit using the colour key AND the per-surface alpha value
else
blit using the per-surface alpha value
}
} else {
if (source surface has SDL_SRCCOLORKEY set)
blit using the colour key
else
ordinary opaque rectangular blit
}


I haven't set SDL_SRCALPHA(or is it set automaticly?), so following that code I should end with "blit using the colour key", shouldn't I?

Share this post


Link to post
Share on other sites
You can check if SDL is setting it automatically by inspecting the value of (src->flags & SDL_SRCALPHA). This is the case on my system.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!