Sign in to follow this  
Modred

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

Recommended Posts

Short and simple: I create a 32 bit surface with alpha - channel (R8G8B8A8), and colorkeys stop working.
[code]
#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);
}[/code]

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

Share this post


Link to post
Share on other sites
[url="http://sdl.beuc.net/sdl.wiki/SDL_BlitSurface"]SDL_BlitSurface[/url] does not support simultaneous alpha channel and colour keying. One solution is to modify the colour keyed pixels to have a transparent alpha value.

Share this post


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

[code]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
}[/code]

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

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