[SDL] blitting from-to surface with per-pixel alpha doesn't work...

Stephane Marchesin stephane.marchesin at wanadoo.fr
Fri Nov 18 07:29:08 PST 2005


Gabriel wrote:
>>All of the images are PNGs with initial transparency fill from Gimp.
>>The blit is working great with per-pixel alpha but only when I blit the
>>parts into 'display', not to the 'tank' and then to 'display' surface.
> 
> 
> Wait, wait. When you said "screen<-tank<-parts" I assumed you meant
> "(screen <- tank) <- parts". If you meant "screen <- (tank <- parts)"
> then you're correct, SDL doesn't work as you expect - the SDL_SetAlpha
> docs say "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."
> 
> I have encountered this problem before, as many other people have; the
> general consensus seems to be to code that blit manually, using whatever
> alpha semantics you want. Since I only do this at load time, it doesn't
> matter that it isn't optimized. 
> 
> It may be a good idea to have at least a non-optimized function in SDL
> to do this. Everyone : what kind of operation should be done for an
> hypotethical SDL_ComposeSurface()?
> 

The Porter & Duff 'Over' operator as described there :
http://keithp.com/~keithp/porterduff/p253-porter.pdf

Stephane





More information about the SDL mailing list