Archived

This topic is now archived and is closed to further replies.

Terran Marine

OpenGL Sprites and transparency in OpenGL...

Recommended Posts

Hi, Can anyone explain to me how to go about billboarding in OpenGL? The openGL User''s Guide says to use AlphaFunc(), but my images are 24-bits and don''t contain any alpha values. Thanks in advance.

Share this post


Link to post
Share on other sites
change the blending function to glBlendFunc(GL_SRC_ALPHA, GL_ONE); and enable blending when
you draw the sprite... Of course, it makes the sprite more transparent all over which is rather annoying
I figured this out the hard way the other day... Alpha channels are a really nice thing to have in
your sprites.

------------------------------
Trent (ShiningKnight)
E-mail me
OpenGL Game Programming Tutorials

Share this post


Link to post
Share on other sites
alphafunc has nothing to do with billboarding. billboard is when u make a polygon face the screen, i believe theres a recent thread in nehe that has a bt of info about possible methods

Share this post


Link to post
Share on other sites
tga is easy to load
png is difficult to load (use a library) but handles all formats and does good lossless compression

Share this post


Link to post
Share on other sites
It depends. If you have multiple levels of transparency in that alpha channel, you''ll need GL_RGBA (or something specific like GL_RGBA8). You might also be able to get away with a format like GL_RGB5_A1 (if you do this, chances are that the display adapter will store that texture in its native format, which would probably be GL_RGBA8) So, again, it depends on the image.

If you want to use the standard sort of sprites where a certain color value represents transparency, you can create the alpha channel at runtime. In the function you use to load images into a buffer (right before using that buffer to make a texture), analyze the RGB value to determine if it is. If so, make the alpha value 0, otherwise, make it 255 (assuming that you''re using an 8-bit byte per component). Then make the texture as in the paragraph above.

To make the alpha channel useful, you have to enable blending and use some blending such as glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) (that''s how I''ve always done it, though GL_SRC_ALPHA, GL_ONE might work as well).

So, then you have to draw the billboard. Since it needs to face the camera always, you just use the camera''s angle to determine the angle necessary to make the billboard parallel to it. Then just draw the billboard using the sprite texture and blending mode.

Share this post


Link to post
Share on other sites