Png and transparency

hi,
when I create a png image with gimp,
the background is transparency.
after,
I do imgLoad(“file.png”)
but, The transparency is black.
how to say that the transparency must be transparent

??

thanks.

a++

You probably want to do something like this:

SDL_surface *sprite, *temp; // Allocate two surface pointers
temp = IMG_Load(“file.png”); // Load the image
sprite = SDL_DisplaySurface(temp); // Convert the image to a format
matching the current display format
SDL_FreeSurface(temp); // We no longer need this copy of
the image
SDL_SetColorKey(sprite, SDL_SRCCOLORKEY, TRANSPARENT_COLOR);

A few notes:

You are responsible for the value represented by TRANSPARENT_COLOR. You
seem to want it to be black, so this would be the color value for
black. There’s a function for that. I don’t know what it is.

Also, you may want to check whether or not ‘temp’ successfully loaded,
or if there was enough memory to allocate 'sprite.'On Apr 10, 2005, at 3:09 PM, elekis wrote:

hi,
when I create a png image with gimp,
the background is transparency.
after,
I do imgLoad(“file.png”)
but, The transparency? is black.
how to say that the transparency must be transparent

??

thanks.

a++


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

This is the traditional way “ColorKey” for transparency.
However, the new way “alpha channel” is quite stronger.
Once you load a png file with alpha channel, you can
easily draw to to screen, and SDL internel would take
care the transparency process for you.

Would you please use the example ‘showimage’ in SDL_image
to load a png with alpha channel and have a look. :slight_smile:

“Donny Viszneki”
SDL_surface *sprite, *temp; // Allocate two surface pointers
temp = IMG_Load(“file.png”); // Load the image
sprite = SDL_DisplaySurface(temp); // Convert the image to a format
matching the current display format
SDL_FreeSurface(temp); // We no longer need this copy of
the image
SDL_SetColorKey(sprite, SDL_SRCCOLORKEY, TRANSPARENT_COLOR);

If you only want colorkey transparency, which is a binary test, you
shouldn’t arbitrarily upgrade to full alpha-channel transparency.
Traditionally, alpha-blending is much slower than color-key
transparency. However, newer graphics hardware – if supported by SDL’s
blitting functions – will most likely handle alpha-channel
transparency more quickly, since modern software (especially games)
utilizes blending, and colorkeying is pretty much dying out.On Apr 11, 2005, at 6:17 AM, RocWood wrote:

This is the traditional way “ColorKey” for transparency.
However, the new way “alpha channel” is quite stronger.
Once you load a png file with alpha channel, you can
easily draw to to screen, and SDL internel would take
care the transparency process for you.

Would you please use the example ‘showimage’ in SDL_image
to load a png with alpha channel and have a look. :slight_smile:

“Donny Viszneki”
SDL_surface *sprite, *temp; // Allocate two surface pointers
temp = IMG_Load(“file.png”); // Load the image
sprite = SDL_DisplaySurface(temp); // Convert the image to a format
matching the current display format
SDL_FreeSurface(temp); // We no longer need this copy of
the image
SDL_SetColorKey(sprite, SDL_SRCCOLORKEY, TRANSPARENT_COLOR);


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