I’ve got a little problem using “colorkey” and “alpha” in the pixel format struct in a surface.
Let’s be sure first that I understand these values corret: When using colorkey on a surface, e.g. through mysurface->format->colorkey = 0xFF00FF (bright pink), would that mean, that each pixel on the (24 bit) surface, which is exactly that color, skipped, and so invisible when drawing on the screen? And would alpha mean, whether to draw the surface normal (255), 50% transparent (128), invisible (0) etc.?
Here is some of my code, but anyhow colorkey and alpha doesn’t have any affect:
Code:
…
#define SCREEN_DEPTH 24
SDL_Init(SDL_INIT_VIDEO);
SDL_Surface *screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, SDL_HWSURFACE|SDL_ANYFORMAT);
SDL_Surface *bitmap1 = loadMySprite(); // this loads my 24 bit sprite
// pink pixels in my sprite should be transparent when drawing on screen, so:
bitmap1->format->colorkey = 0xFF00FF;
// when using SDL_BlitSurface() to draw my sprite on screen, all pixels are visible, even no matter whether I set the surface flas SDL_SRCCOLORKEY or not
// let’s try to make a bitmap transparent
SDL_Surface *bitmap2 = loadMyBitmap(); // this loads my 24 bit bitmap, having the SDL_SRCALPHA flag
SDL_SetAlpha(bitmap2, SDL_SRCALPHA, 64);
// SDL_BlitSurface(…); // put bitmap on screen, but it’s 100% visible
Am I doing anything wrong?