Sprites and transparency in OpenGL...

Started by
5 comments, last by Terran Marine 22 years, 8 months ago
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.
Advertisement
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
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
Thanks for the info.
What texture format would you recommend? I need one that contains an alpha channel.
tga is easy to load
png is difficult to load (use a library) but handles all formats and does good lossless compression
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.
I think I''ll go with TGA. Thanks for the help.

This topic is closed to new replies.

Advertisement