I have a problem with trasnparent surface and PNG images.
I need to create a transparent surface then blit images on it and
finally blit
this surface on screen.
The images are PNG with alpha channel and transparency, the problem is that
when I create the surface and blit images on it, the partially
transparent pixels
of the images disappear, losing so the AA and several details!
maybe i’m misunderstanding, but can’t you manually copy( memcpy() )
the pixels from the source to the destination, rather than using
SDL_BlitSurface() which loses the alpha values?
I am assuming that the image of the fortification is separate from the image
of its shadow, and that the shadow image is translucent (partial alpha). In
that case, SDL_BlitSurface is behaving according to doc:
RGBA->RGBA:
SDL_SRCALPHA set:
alpha-blend (using the source alpha channel) the RGB values;
leave destination alpha untouched.
SDL_SRCALPHA not set:
copy all of RGBA to the destination.
If you want the alpha channel to be transferred as well you need to remove
the SDL_SRCALPHA flag from the source image surfaces. But also keep in mind
that if the translucent pixels of your image surfaces overlap when blitted
to your transparent surface, you will not get a 100% correct result – they
will not be blended, and neither will translucent pixels with opaque ones.
You would need to write your own (transblending) blit for that.
-Alex.> ----- Original Message -----
From: Davide “M3xican” Coppola
Sent: Thursday, January 19, 2006 5:17 AM
To: sdl at libsdl.org
Subject: [SDL] transparent surface problem
[…snip…]
I need to create a transparent surface then blit images on it and finally
blit this surface on screen.
The images are PNG with alpha channel and transparency, the problem is that
when I create the surface and blit images on it, the partially transparent
pixels of the images disappear, losing so the AA and several details!
maybe i’m misunderstanding, but wouldn’t that not do what you expect
in some cases? (e.g., if src and dest are of different formats;
or one HW surface, the other SW surface)
-bill!On Fri, Jan 20, 2006 at 12:39:39AM +0000, Brian Barrett wrote:
maybe i’m misunderstanding, but can’t you manually copy( memcpy() )
the pixels from the source to the destination, rather than using
SDL_BlitSurface() which loses the alpha values?
maybe i’m misunderstanding, but wouldn’t that not do what you expect
in some cases? (e.g., if src and dest are of different formats;
or one HW surface, the other SW surface)
well lock the surface, and use the getpixel and putpixel code from the
docs, and is my suggestion any better?
anyway, looking at the original message, i think the pixel frmat will
be the same
"
SDL_Surface * temp = IMG_Load(file.c_str());
//snip…
img = SDL_DisplayFormatAlpha(temp);
//snip…
SDL_PixelFormat * format = img->format;
a_surface = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA,w,h,format->BitsPerPixel,
I have a problem with trasnparent surface and PNG images.
I need to create a transparent surface then blit images on it and
finally blit
this surface on screen.
The images are PNG with alpha channel and transparency, the problem is that
when I create the surface and blit images on it, the partially
transparent pixels
of the images disappear, losing so the AA and several details!