PDA

View Full Version : How to do translucent graphics?



retrocoder
11-05-2010, 10:19 AM
I am using SDL to render my 2D game. I need to overlay a map when the user presses a key. I would like to show the map so that it is partly translucent. That was the user can still see what is going on under the map. Can this be done with SDL? If so, can someone give me some advice on what I need to set to do this.

Traveler
11-05-2010, 11:41 AM
Before you draw the map texture, set the alpha value of the glColor function (ie glcolor4ub(255,255,255,128)). I'm not entirely sure what the equivalent is in SDL, though.

Stoney
11-05-2010, 12:30 PM
If you are using pure SDL, before you blit the surface use SDL_SetAlpha(MyValue), where MyValue is a byte value and 0 is completely translucent and 255 is completely visible. Use 128 as the value as often as you can, because it has been optimized for that case.

retrocoder
11-05-2010, 03:13 PM
Thanks for your help, that command works a treat :)

WILL
12-05-2010, 02:43 AM
Hi and a late welcome to PGD!

I'm curious about your project, just a few pieces of information and it sounds interesting already. Maybe you can post about it in the 'My Projects' forum? :)

However getting back on topic, I'd like to note that while you *can* use SDL alone to do alpha fading, it will not be all that fast. If your map 'screen' will contain a single image or sprite then depending on the hardware it should be ok. However try to do several alpha blended sprites or images on the screen at a time and you'll quickly see that it slows down significantly. If your end goal is to make heavy usage of the alpha blend then you may be moving into OpenGL territory. Just a little caution on the alpha blending usage with SDL graphics.

Stoney
12-05-2010, 06:38 AM
However try to do several alpha blended sprites or images on the screen at a time and you'll quickly see that it slows down significantly.


I have to agree with you completely if you are using SDL_SWSURFACE or SDL_ANYFORMAT for your main window surface. In my experience slowdowns occur most of the time when SDL_DisplayFormat or SDL_DisplayFormatAlpha are not used.
And of course, the slowdowns are not as stark as with DelphiX and alpha sprites. :)

retrocoder
01-06-2010, 04:07 PM
Hi and a late welcome to PGD!

I'm curious about your project, just a few pieces of information and it sounds interesting already. Maybe you can post about it in the 'My Projects' forum? :)

Still lots to do but just added a short video on YouTube: http://www.youtube.com/watch?v=VMPG6McWAzw This is being written in Delphi 7 using JEDI SDL and BASS for the sound fx. I'll add mort detail in the projects section when I get some spare time :)