How do you use transparency in OPENGL

Started by
6 comments, last by GameDev.net 18 years, 4 months ago
I tried setting one of the colors I use in my program to be highly transparent.. glColor4f( .25f, .25f, .25f, .95f ); however the color doesn't show up as transparent at all! What is the cause of this?
Advertisement
Did you call glEnable() with GL_BLEND? Did you call glBlendFunc() to set the blending mode?
You need to have enabled blending for the alpha channel (your 0.95f value) to be used.

Take a look at some of Nehe's tutorials ( http://nehe.gamedev.net )

Mainly tutorials:
8 - http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=08
19 - http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=19
20 - http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=20

Or try looking up glEnable(GL_BLEND) and glBlendFunc();

Note when GL_BLEND is enabled you must also disable GL_DEPTH_TEST.
And finally proper rendering of blended areas should always be rendered after the solid object (no transparencies) and should be sorted from back (rendered first) to front (rendered last) since blending uses what is allready rendered on the screen.

And don't worry its not as hard as it sounds :P
for alpha to be calculated, you need to use glEnable(GL_BLEND);

and you probably need to use glDepthFunc but i dont know if its needed :O

also, it isn't really necessary to disable depth testing when blend is enabled, that I can tell.
|aaap.penopticon.com| My website, including game projects. Collaboration/comments are welcome, please visit :)
Hi and thanks for the help. I added the following to my InitGL() code.

//////////////////////////////////////////////////////////
glBlendFunc(GL_SRC_ALPHA, GL_ONE);

glEnable( GL_BLEND );
glDisable(GL_DEPTH_TEST);
//////////////////////////////////////////////////////////

however, this time the colors are all screwed up. My object and its shadow are drawn in WHITE, and the other colors are different too. LOL all I want is to have a transparent object I never thought it would be so difficult...
ok, check this out.

the 4th value in glColor4f, is alpha, as you know.

the lower the 4th value, the more transparent the object will be.

so for instance, a value of 1 would be fully opaque, and 0 would be invisible.

also, its possibly that the blendfunc you used would create an opaque effect as well. I'm not TOO familiar with blendfunc, but i know that most of the experimenting i did resulted in weird/unwanted effects, so the only one i use is this:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
ah that was me. ><
|aaap.penopticon.com| My website, including game projects. Collaboration/comments are welcome, please visit :)
Thank you that worked very well!

This topic is closed to new replies.

Advertisement