Surface alpha and per pixel alpha combined blitting (was Re: SDL digest, Vol 1 #233 - 30 msgs)

Chip Collier wrote:

Hi all,
I’m drawing directly to an offscreen buffer that is 32bits. The surface is
created and if my pointer isn’t NULL I go ahead and SDL_SetAlpha(buffer,
SDL_SRCALPHA, 255). But it only uses per-surface alpha blending when I blit
it to the screen.
simplified drawing code:

if(you have to lock the surface)
{
lock the surface
}

draw the pixels with colors selected from the color_buffer[]

if(you had to lock it)
{
unlock it
}

blit the surface to the screen.
update the screen.

Pretty basic and just about right out of a tutorial somewhere…but like I
said it doesn’t use the alpha values from the colors I generated.

For testing purposes I’m making an array of 256 colors (white to black /
opaque to transparent) and including alpha information.
So what I’m asking is basically: Is it possible to draw onto a surface and
use alpha information that will be taken care of when you blit to the screen?
Thanks,
Chip Collier

Per surface alpha takes precedence over per-pixel alpha…SDL doesn’t have a Blit routine that can combine the two at the same time.
If you need to do both at once, you have to make your own blitter. Another route that has been taken is to use OpenGL, which can combine texture per-pixel alpha and surface alpha both at the same time, as seen in Chromium II I believe. OpenGL also benefits from hardware acceleration on systems that support OpenGL in hardware.–
-==-
Jon Atkins
http://jcatki.2y.net/

Jonathan Atkins wrote:

Per surface alpha takes precedence over per-pixel alpha

Incorrect. See the docs