Alpha blending

Is there a way to do per-pixel (as opposed to entire surface) alpha
blending with SDL? I’d like to use the alpha channel stored by an image
editor.

Thanks!
-Reeves–
J. Reeves Hall, Georgia Tech CS Major
Linux #5 SMP Mon Mar 20 21:56:31 EST 2000
1:42pm up 7 days, 23:28, 7 users, load average: 0.79, 0.40, 0.24

Is there a way to do per-pixel (as opposed to entire surface) alpha
blending with SDL? I’d like to use the alpha channel stored by an image
editor.

Yes, but there have been some bugs reported in that the conversion loses
alpha information. Take a look at the testalpha test program to see how
it can be done.

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

I was wondering about this too, I think you’d just have to use lots of small
surfaces or make your own alpha blending routine.On Sun, 02 Apr 2000, you wrote:

Is there a way to do per-pixel (as opposed to entire surface) alpha
blending with SDL? I’d like to use the alpha channel stored by an image
editor.

Thanks!
-Reeves


J. Reeves Hall, Georgia Tech CS Major
Linux #5 SMP Mon Mar 20 21:56:31 EST 2000
1:42pm up 7 days, 23:28, 7 users, load average: 0.79, 0.40, 0.24

-Garrett, WPI student majoring in Computer Science
"The fastest way to succeed is to look as if you’re playing by somebody
else’s rules, while quietly playing by your own." -Michael Konda

Sam Lantinga wrote:

Is there a way to do per-pixel (as opposed to entire surface) alpha
blending with SDL? I’d like to use the alpha channel stored by an image
editor.

Yes, but there have been some bugs reported in that the conversion loses
alpha information. Take a look at the testalpha test program to see how

it can be done.

I looked at the example, and that’s exactly what I want to do, except that I
want to load alpha information from an image file rather than specify it
manually (I’m loading PNG files saved by The GIMP, via the SDL_image
package). This does not seem to happen automatically though; I get an opaque
image when I blit it.

I think I can make do with per-surface alpha for now (it does look good),
but per-pixel would allow a lot of neat effects.

Thanks!
-Reeves–
J. Reeves Hall, Georgia Tech CS Major
Linux #5 SMP Mon Mar 20 21:56:31 EST 2000
4:08pm up 8 days, 1:54, 7 users, load average: 0.08, 0.05, 0.01

You can use targas which can have a second layer stored in the image
containing the alpha levels of each pixel.On Sun, 02 Apr 2000, you wrote:

Sam Lantinga wrote:

Is there a way to do per-pixel (as opposed to entire surface) alpha
blending with SDL? I’d like to use the alpha channel stored by an image
editor.

Yes, but there have been some bugs reported in that the conversion loses
alpha information. Take a look at the testalpha test program to see how

it can be done.

I looked at the example, and that’s exactly what I want to do, except that I
want to load alpha information from an image file rather than specify it
manually (I’m loading PNG files saved by The GIMP, via the SDL_image
package). This does not seem to happen automatically though; I get an opaque
image when I blit it.

I think I can make do with per-surface alpha for now (it does look good),
but per-pixel would allow a lot of neat effects.

Thanks!
-Reeves


J. Reeves Hall, Georgia Tech CS Major
Linux #5 SMP Mon Mar 20 21:56:31 EST 2000
4:08pm up 8 days, 1:54, 7 users, load average: 0.08, 0.05, 0.01

-Garrett, WPI student majoring in Computer Science
"The fastest way to succeed is to look as if you’re playing by somebody
else’s rules, while quietly playing by your own." -Michael Konda

Is there a way to do per-pixel (as opposed to entire surface) alpha
blending with SDL? I’d like to use the alpha channel stored by an image
editor.

Thanks!
-Reeves

PNG’s with alpha channel work fine (using 8,16 or 32bit displays) as long as
you don’t call SDL_DisplayFormat() (because it destroys alpha information).
So, don’t call SDL_DisplayFormat() for images with alpha information, until
this is fixed.

Dimitris

“J. Reeves Hall” wrote:

Is there a way to do per-pixel (as opposed to entire surface) alpha
blending with SDL? I’d like to use the alpha channel stored by an image
editor.

Thanks!
-Reeves

Problem solved. I didn’t realize that SDL_DisplayFormat() would drop the
alpha channel. It looks very nice now.

Thanks everyone!
-Reeves–
J. Reeves Hall, Georgia Tech CS Major
Linux #5 SMP Mon Mar 20 21:56:31 EST 2000
3:20pm up 1 day, 1:26, 8 users, load average: 0.08, 0.04, 0.01

With RGBA->RGBA blits with SDL_SRCALPHA, destination alpha is left
untouched. And with RGB->RGBA with SDL_SRCALPHA? Is it left untouched, too,
or set to opaque? I suppose the first one, right?–
Marco Iannaccone
marciann at tin.it
ICQ UIN: 18748121 MetalCoder

"I bei film drammatici fanno sentire intelligenti anche gli stupidi, i bei
film comici fanno tornare bambini anche le persone intelligenti.
Peccato che sia pi? facile trovare stupidi che vogliono sembrare
intelligenti che persone intelligenti col coraggio di saper tornare bambini"
Stan Laurel

With RGBA->RGBA blits with SDL_SRCALPHA, destination alpha is left
untouched. And with RGB->RGBA with SDL_SRCALPHA? Is it left untouched, too,
or set to opaque? I suppose the first one, right?

set to opaque. http://sdldoc.csn.ul.ie/sdlsetalpha.php

With RGBA->RGBA blits with SDL_SRCALPHA, destination alpha is left
untouched. And with RGB->RGBA with SDL_SRCALPHA? Is it left untouched,
too,

or set to opaque? I suppose the first one, right?

set to opaque. http://sdldoc.csn.ul.ie/sdlsetalpha.php
I had already chacked the docs before asking. It says it is set to opaque
for RGB->RGBA withOUT SDL_SRCALPHA, but doesn’t say anything about RGB->RGBA
WITH SDL_SRCALPHA.

Is it the same in this case, too?–
Marco Iannaccone
marciann at tin.it
ICQ UIN: 18748121 MetalCoder

"I bei film drammatici fanno sentire intelligenti anche gli stupidi, i bei
film comici fanno tornare bambini anche le persone intelligenti.
Peccato che sia pi? facile trovare stupidi che vogliono sembrare
intelligenti che persone intelligenti col coraggio di saper tornare bambini"
Stan Laurel

I had already chacked the docs before asking. It says it is set to opaque
for RGB->RGBA withOUT SDL_SRCALPHA, but doesn’t say anything about RGB->RGBA
WITH SDL_SRCALPHA.

ah, sorry, I misread you. Indeed the destination alpha is set to opaque
of the copied pixels. Thanks, I’ve fixed the docs in the CVS; they will
probably show up in the online version soon (and in the SDL tarball
shortly after that :slight_smile:

set to opaque. http://sdldoc.csn.ul.ie/sdlsetalpha.php
I had already chacked the docs before asking. It says it is set to opaque
for RGB->RGBA withOUT SDL_SRCALPHA, but doesn’t say anything about RGB->RGBA
WITH SDL_SRCALPHA.

Please read it again. The docs in the SDL source tarball had a misleading
formulation there but the online docs should be up-to-date

Ok, anyway, in this paragraph:
"Note: Note that RGBA->RGBA blits (with SDL_SRCALPHA set) keep the alpha of
the destination surface. This means that you cannot compose two arbitrary
RGBA surfaces this way and get the result you would expect from “overlaying"
them; the destination alpha will work as a mask.”

what does this sentence mean: “the destination alpha will work as a mask” ?

Simply, source alpha should not affect destination alpha, right?–
Marco Iannaccone
@Marco_Iannaccone
ICQ UIN: 18748121 MetalCoder

"I bei film drammatici fanno sentire intelligenti anche gli stupidi, i bei
film comici fanno tornare bambini anche le persone intelligenti.
Peccato che sia pi? facile trovare stupidi che vogliono sembrare
intelligenti che persone intelligenti col coraggio di saper tornare bambini"
Stan Laurel

"Note: Note that RGBA->RGBA blits (with SDL_SRCALPHA set) keep the alpha of
the destination surface. This means that you cannot compose two arbitrary
RGBA surfaces this way and get the result you would expect from “overlaying"
them; the destination alpha will work as a mask.”

what does this sentence mean: “the destination alpha will work as a mask” ?

exactly what it says - the result is effectively masked by the destination
alpha (only pixels where the destination alpha is nonzero will be visible
in the result). It’s a direct result of the destination alpha being
unaffected by the blit

exactly what it says - the result is effectively masked by the destination
alpha (only pixels where the destination alpha is nonzero will be visible
in the result).
you mean, when blitting the destination surface to another surface, right?

It’s a direct result of the destination alpha being
unaffected by the blit
In the blit from a surface to another, the color written on the second one
only depends by per-surface source alpha, source RGB, and destination RGB
(destination alpha is not considered during blit, right?), isn’it?–
Marco Iannaccone
@Marco_Iannaccone
ICQ UIN: 18748121 MetalCoder

"I bei film drammatici fanno sentire intelligenti anche gli stupidi, i bei
film comici fanno tornare bambini anche le persone intelligenti.
Peccato che sia pi? facile trovare stupidi che vogliono sembrare
intelligenti che persone intelligenti col coraggio di saper tornare bambini"
Stan Laurel

Hello !

I’ve got a rgba-surface which has some transparent parts and I want to
fade it with the screen. Unfortunately, I can’t use the per-surface alpha
as it is ignored when blitting a rgba-surface on a rgb one.

Is there any elegant solution or do I have to write my own blitter ?

Thx.

Billl

Olivier Rolland wrote:

I’ve got a rgba-surface which has some transparent parts and I want to
fade it with the screen. Unfortunately, I can’t use the per-surface alpha
as it is ignored when blitting a rgba-surface on a rgb one.

Colourkeying can be combined with per-surface alpha. Otherwise, you’ll have
to write your own blitter. (alternatively, render your image with low
alpha and blit it repeated times on the same spot. There are other
variations)

What is the procedure for making a surface semi-transparent and then
blitting it to the screen?

I load a surface, then use SDL_SetAlpha(surface, SDL_SRCALPHA, 128) and then
use SDL_DisplayFormatAlpha() to convert the surface. It appears to work for
like half a second and then the surface is blitted completely solid.

Anyone know what I could be doing wrong?

My guess… you’re not erasing the background, therefore every blit
of the semi-transparent part is actually “increasing the opacity” of
the previous blit.

Ing. Gabriel Gambetta
ARTech - GeneXus Development Team
ggambett at artech.com.uy> ----- Original Message -----

From: hahcoe [mailto:hahcoe@hahcoe.net]
Sent: Martes, 23 de Diciembre de 2003 02:45 p.m.
To: sdl at libsdl.org
Subject: [SDL] Alpha blending

What is the procedure for making a surface semi-transparent and then
blitting it to the screen?

I load a surface, then use SDL_SetAlpha(surface, SDL_SRCALPHA, 128) and
then use SDL_DisplayFormatAlpha() to convert the surface. It appears to
work for like half a second and then the surface is blitted completely
solid.

Anyone know what I could be doing wrong?


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