Alpha channel

Is there any way to add an aplha channel to the blit? Ie another
greyscale image whose intensity determines a pixels alpha value?

emblem

Is there any way to add an aplha channel to the blit? Ie another
greyscale image whose intensity determines a pixels alpha value?

Yup. SDL doesn’t support a separate surface as an alpha map, but
you can create a surface with an alpha channel, and mix the alpha
data into that surface yourself.

Note that alpha blits are not accelerated at the moment and are
very slow. I don’t know of any 2D card on the market that currently
supports alpha blit acceleration, but next generation cards should.

See the testalpha test program for an example of using alpha.

See ya!
-Sam Lantinga (slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

Given this scenario:

Create a surface WITHOUT alpha channel (amask=0 in creatergbsurface)
Load an image WITH per pixel alpha channel
Blit the image over the surface

I've debugged this steps, and the curious thing is that the first

surface still lacks of an alpha channel, but the image is correctly seen
over the surface, with the alpha channel correctly set. How is this possible
?++++++++++++++++++++++++++++++++
ALBERT FERNANDEZ MARSAL
CIRSA INTERACTIVE CORP. SL
Analista senior y programador
++++++++++++++++++++++++++++++++

Given this scenario:

Create a surface WITHOUT alpha channel (amask=0 in creatergbsurface)
Load an image WITH per pixel alpha channel
Blit the image over the surface

I’ve debugged this steps, and the curious thing is that the first
surface still lacks of an alpha channel, but the image is correctly seen
over the surface, with the alpha channel correctly set. How is this possible
?

That’s how an alpha channel is supposed to work. What did you expect it
to do?–
Gabriel Gambetta
Mystery Studio - http://www.mysterystudio.com
Gabriel on Graphics - http://gabrielongraphics.blogspot.com

well, i’d expect an alpha channel to be added to the first surface
(it was created without it) so the per pixel alpha of the image is reflected
after the blit, but there’s no alpha channel. I don’t understand how the per
pixel alpha of the image is correctly seen on a surface that has no alpha
channel. Maybe the pixels of the blitted surface are represented only with
RGB channels (~16M colors can be represented with those three channels!),
but that’s just a guess++++++++++++++++++++++++++++++++
ALBERT FERNANDEZ MARSAL
CIRSA INTERACTIVE CORP. SL
Analista senior y programador
++++++++++++++++++++++++++++++++

-----Mensaje original-----
nombre de Gabriel
Enviado el: jueves, 20 de octubre de 2005 6:17
Para: SDL Mailing List
Asunto: [] Re: [SDL] Alpha channel

Given this scenario:

Create a surface WITHOUT alpha channel (amask=0 in creatergbsurface)
Load an image WITH per pixel alpha channel
Blit the image over the surface

I’ve debugged this steps, and the curious thing is that the first
surface still lacks of an alpha channel, but the image is correctly seen
over the surface, with the alpha channel correctly set. How is this
possible
?

Albert Fern?ndez Marsal wrote:

well, i’d expect an alpha channel to be added to the first surface
(it was created without it) so the per pixel alpha of the image is
reflected after the blit, but there’s no alpha channel.

SDL blitting functions will never change the source or destination surface
format, which is an expected behavior.

I don’t understand how the per pixel alpha of the image is correctly
seen on a surface that has no alpha channel.

That’s (relatively) simple – SDL does an alpha-blending blit from a source
RGBA surface to a destination RGB surface, if the source surface has
SDL_SRCALPHA flag set (which it should have set by default if you loaded the
image using SDL_image functions). In other words, SDL will blend the
overlapping pixels of both surfaces together, based on the source pixels’
alpha channel values, which, again, is an expected (and desired!) behavior
:).

-Alex.