Sign in to follow this  
Conqueran

How do you use transparency in OPENGL

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this