openGL and alpha blended surfaces

Hi,

I am programming a SDL / openGL based 3D real time strategy game
and I want to use the 2D blitting functions of SDL.

But when I draw an alpha blended surface to the openGL context,
the surface has a white background and not the openGL scene
as background.
When I blit several alpha blended 2D surfaces to screen, they are
correct blended but there is the same error with the openGL scene

It seems that SDL uses a different graphic context than openGL. and blit
only the content of the SDL context with alpha blending to screen ??

I am using SDL_OPENGLBLIT as videoflag.

system: SDL 1.1.8 precompiled for mingw32
Windows 98
nVidia riva TNT

cu
Johannes

I have this same problem (in Linux though) and havent found any way to fix
it yet after ages playing around ;). Using SDL_FillRect to draw
translucent areas seems to work how I expect it to though…

anyone got any ideas about the surface blitting?On Sat, 3 Mar 2001, Johannes Schmidt wrote:

But when I draw an alpha blended surface to the openGL context,
the surface has a white background and not the openGL scene
as background.


Adam
@af7567_at_bris.ac.uk
adamf at one2one.net
adamf at snika.uklinux.net

I have this same problem (in Linux though) and havent found any way to fix
it yet after ages playing around ;). Using SDL_FillRect to draw
translucent areas seems to work how I expect it to though…

Can somebody post sample code for this? Somebody did in the past, but
I’ve lost the e-mail. It’s something I definitely want to fix for SDL 1.2

Thanks!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Well… I dont really know how this is meant to be done because
everything I have tried has never worked :slight_smile: but hopefully something in
this code should be coming up translucent.

When I run this on my machine, only the FillRect with the color returned
from MapRGBA is translucent, everything else is 100% opaque (I think
thats the right way of describing it :slight_smile: ). I do, however, know very
little about graphics stuff… Anyone have any code example of how to
really blit translucent stuff over a GL screen?On Sat, 3 Mar 2001, Sam Lantinga wrote:

I have this same problem (in Linux though) and havent found any way to fix
it yet after ages playing around ;). Using SDL_FillRect to draw
translucent areas seems to work how I expect it to though…

Can somebody post sample code for this? Somebody did in the past, but
I’ve lost the e-mail. It’s something I definitely want to fix for SDL 1.2

Thanks!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software


Adam
@af7567_at_bris.ac.uk
adamf at one2one.net
adamf at snika.uklinux.net
-------------- next part --------------
A non-text attachment was scrubbed…
Name: glblit.tar.gz
Type: application/octet-stream
Size: 13129 bytes
Desc:
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20010304/518f001e/attachment.obj

Well… I dont really know how this is meant to be done because
everything I have tried has never worked :slight_smile: but hopefully something in
this code should be coming up translucent.

When I run this on my machine, only the FillRect with the color returned
from MapRGBA is translucent, everything else is 100% opaque (I think
thats the right way of describing it :slight_smile: ). I do, however, know very
little about graphics stuff… Anyone have any code example of how to
really blit translucent stuff over a GL screen?

Okay, there are two problems here.

First, the alpha value in SDL_SetAlpha() is ignored when working with RGBA
surfaces, all you can do with the function is affect the blit semantics, as
documented in SDL_video.h next to the entry for SDL_BlitSurface().

Second, there was a bug in the blit code for ARGB -> ARGB surfaces, where
if the source alpha was opaque, the destination alpha was overwritten
instead of preserved. This has been fixed in the ARGB32 -> ARGB32 case,
but Yorick, I suspect that it’s broken for some of the other blitters as
well, can you check it out?

Anyway, grab the latest CVS snapshot and change your first SDL_SetAlpha()
call to:
SDL_FillRect(screen, NULL, SDL_MapRGBA(screen->format, 255, 255, 255, 64));

Then everything should work as expected.

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

Second, there was a bug in the blit code for ARGB -> ARGB surfaces, where
if the source alpha was opaque, the destination alpha was overwritten
instead of preserved. This has been fixed in the ARGB32 -> ARGB32 case,
but Yorick, I suspect that it’s broken for some of the other blitters as
well, can you check it out?

looks ok now. The RGBA->RGBA semantics of preserving destination alpha
aren’t very useful but a correct (alpha-composing) implementation would
be very slow. In 1.3 we should consider allowing premultiplied alpha,
which would enable fast compositioning

looks ok now. The RGBA->RGBA semantics of preserving destination alpha
aren’t very useful

They are very useful for the SDL_OPENGLBLIT case. It allows you to set
the “background” image and alpha blend elements on top of it, preserving
the alpha channel of the entire “screen” texture. Anyway, it’s a moot
point until 1.3 and the new blitter API.

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

Yes, this looks like it works now. thanks for your helpOn Sun, 4 Mar 2001, Sam Lantinga wrote:

Anyway, grab the latest CVS snapshot and change your first SDL_SetAlpha()
call to:
SDL_FillRect(screen, NULL, SDL_MapRGBA(screen->format, 255, 255, 255, 64));


Adam
@af7567_at_bris.ac.uk
adamf at one2one.net
adamf at snika.uklinux.net