PNG + alpha image loading

Hi!

Does anyboby know how to load PNG image with aplha channel into SDL_Surface
using SLD_image IMG_* routines?

I want to use alpha blitting with this images.

Thanks.–
Best regards,
Leo
Solvo Ltd.
St.Petersburg, Russia

Hi!

Does anyboby know how to load PNG image with aplha channel into SDL_Surface
using SLD_image IMG_* routines?

I want to use alpha blitting with this images.

surf = IMG_Load(file);
if (surf == NULL)
… /* abort! */

That should do it!!!

If you want to ignore the alpha channel (say for a 100% opaque tile),
then you would call:

SDL_SetAlpha(surf, 0, 0);

But if you want the alpha from the PNG kept, don’t do that! :slight_smile:

-bill!

Hi!On Tue, May 23, 2000 at 08:45:22AM -0700, William Kendrick wrote:

Hi!

Does anyboby know how to load PNG image with aplha channel into SDL_Surface
using SLD_image IMG_* routines?

I want to use alpha blitting with this images.

surf = IMG_Load(file);
if (surf == NULL)
… /* abort! */

That should do it!!!

If you want to ignore the alpha channel (say for a 100% opaque tile),
then you would call:

SDL_SetAlpha(surf, 0, 0);

But if you want the alpha from the PNG kept, don’t do that! :slight_smile:

Ok, i do the same thing, but it doesn’t work :frowning:
I need to have alpha channel from PNG image with different values in it.
I created simple PNG with transparency in GIMP and try to load and blit it
using IMG_Load. Everything loads ok, but when i blit surface to the screen
then it blits without any transparency :frowning:

Here is a piece of my code:

SDL_Surface *LoadImage(char *datafile)
{
SDL_Surface *image, *surface;

image = IMG_Load(datafile);
if ( image == NULL )
{
fprintf(stderr, “Couldn’t load image %s: %s\n”,
datafile, IMG_GetError());
return(NULL);
}

if((image->flags & SDL_SRCALPHA)==SDL_SRCALPHA)
fprintf(stderr,“Image surface has ALPHA channel\n”);
else
fprintf(stderr,“Image surface doesn’t have ALPHA channel\n”);

surface = SDL_DisplayFormat(image);

if((image->flags & SDL_SRCALPHA)==SDL_SRCALPHA)
fprintf(stderr,“Surface has ALPHA channel\n”);
else
fprintf(stderr,“Surface doesn’t have ALPHA channel\n”);

SDL_FreeSurface(image);
return(surface);
}

SDL_BlitSurface(image,pimagerect,video,pvideorect);
SDL_UpdateRect(video,x,y,w,h);

After running program prints that both (image and converted surface) surfaces
has ALPHA channel, but on the screen there is no transparency.

If i set SDL_SetAlpha(image,SDL_SRCALPHA,128) then all image became half
transparent on the screen. But i need REAL transparency from the image.

It seems that IMG_png routines don’t load ALPHA channel.

Help me, please!

Best regards,
Leo
Solvo Ltd.
St.Petersburg, Russia

surface = SDL_DisplayFormat(image);

This kills it, unfortunately…

Any particular reason why, Sam?

-bill!

surface = SDL_DisplayFormat(image);

This kills it, unfortunately…

Any particular reason why, Sam?

The display surface doesn’t have an alpha channel, so when you convert
to it, you lose alpha information. You’re better off leaving the surface
in 32-bit RGBA (or ARGB or whatever) because the blitters are optimized
for that format anyway.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software