Correct way to set transparency?

Hi,

I’ve got a function to set the transparent part of my images to black. This
works fine on 8 and 16 bit depths, but apparently if you move to 24 or 32
bit the transparency is lost. My function looks like this,

SDL_Surface *setTransparent(SDL_Surface *sprite)
{
SDL_SetColorKey(sprite, (SDL_SRCCOLORKEY|SDL_RLEACCEL),
SDL_MapRGB(sprite->format, 0, 0, 0));
return sprite;
}

This is just something I need to sort out since I use a 16 bit desktop but
users of a 24 or 32 bit desktop lose all transparency.

Any thoughts?

Steve :slight_smile:

Sweeney, Steven (FNB) wrote:

Hi,

I’ve got a function to set the transparent part of my images to black. This
works fine on 8 and 16 bit depths, but apparently if you move to 24 or 32
bit the transparency is lost. My function looks like this,

SDL_Surface *setTransparent(SDL_Surface *sprite)
{
SDL_SetColorKey(sprite, (SDL_SRCCOLORKEY|SDL_RLEACCEL),
SDL_MapRGB(sprite->format, 0, 0, 0));
return sprite;
}

This is just something I need to sort out since I use a 16 bit desktop but
users of a 24 or 32 bit desktop lose all transparency.

Any thoughts?

Steve :slight_smile:


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

my thought is that the 24 and 32 bit images yu have don’t have pure black…
as in, the RGB values all zero.
check the exact pixel values that are in the image file, and the ones that
are loaded into your surface to make sure.–
-==-
Jon Atkins
http://jonatkins.org/