Well, people have mentioned most options for real alpha; I’d just like
to add one possibility: glSDL. ( http://olofson.net/mixed.html ) The
point with this is basically that you can keep using the SDL API, which
means that you can still run without OpenGL if you have to. However, note
that this is an alpha proof-of-concept hack! Use at your own risk.
As to software rendering, why use alpha in the first place? If you just
need to darken and/or tint the background with a solid color before
rendering some text, alpha isn’t exactly the most efficient method. Just
shift and mask some…
Darken 50%:
r >>= 1;
g >>= 1;
b >>= 1;
or, to do it all with one SHR + one AND:
out = (in & mask) >> 1;
where 'mask' can be calculated from the SDL_PixelFormat
of the surface you're messing with. It's supposed to have
1's for all bits you wan't to keep; ie all bits except the
ones that should be "shifted out". For xRGB 8:8:8:8 (x
being the unused 8 bits), the mask would be 0x00fefefe.
Note that doing this will give you a known “headroom”, so you can safely
apply additive blending on top of the result - no exponsize saturation
branches needed. Just make sure the maximum possible result fits in the
channel range. In the above example, you could for example give the area
a red tint by adding 0x00800000 (or any smaller value) after the "darken"
operation.
Finally, an important note: DO NOT perform operations like this on a
hardware surface! Writing to VRAM is slow, but reading is slower than you
could possibly imagine. (This impacts SDL’s software alpha blitter as
well, BTW.)
Do your rendering in a software surface instead, and then blit that to
the screen.
//David Olofson — Programmer, Reologica Instruments AB
.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |
-------------------------------------> http://olofson.net -'On Thursday 18 April 2002 13:14, tony Tong wrote:
Hi,everbody
I am planning to make a semi-transparent menu for a
game. The menu should be able to be looked through .
The effect I wanna get is just like what you see in
this link
–http://www.cadsoft.de/people/kls/vdr/software.htm
The menu should not cover the ongoing game video.and
at the same time I can write something on this menu
and select menu bars with keyboard
I am learned SDL can provide some function.But I dont
know how i can start .
could someone give me some help ?
thanks in advance!