Jump to content
  • Advertisement
Sign in to follow this  
peous

OpenGL Rendering an object as transparent

This topic is 3171 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I'm stuck in my OpenGL game project, maybe some expert of openGl could help me. I want to render a mesh with a given alpha value (let's say 0.5) The common way is to use glColor4f(1,1,1,0.5) (and to but the pixel blend function correctly) The problem is that that object already has vertex color values, ie for each vertex, I already call glColor4f(...), that resets the alpha value. (actually these values are in a vertex buffer so I can't change them for each object) I tried to use - glMaterialColor(1,1,1,0.5) - glMaterial(GL_FROMT, GL_AMBIENT, {1,1,1,0.5}) - glMaterial(GL_FROMT, GL_DIFFUSE, {1,1,1,0.5}) ... But the last values seems only to fade the material to the black, not to transparent... Any idea ?

Share this post


Link to post
Share on other sites
Advertisement
Thank you, but I already use glBlendFunc()
(that works with transparent vertex colors)
for information I use a classic "glBlendFunc(SRC_ALPHA, ONE_MINUS_SRC_ALPHA)"

Hmmm I see in
http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/lightmodel.html
"The alpha component of the resulting lighted color is set to the alpha value of the material diffuse reflectance."

But is it replaced by the glColor() applied to each vertex ? mystery...

Share this post


Link to post
Share on other sites
My tests seems to show that
glMaterialfv(GL_FRONT, GL_DIFFUSE, ...)
is *replaced* by
glColor(...)

So I see no way to render an object with a "transparent multitplier" if this object has vertex colors.

Share this post


Link to post
Share on other sites
Your code is somewhat missing the part where you enable GL_COLOR_MATERIAL. At least the code you posted.

But since you do seem to see a difference: You realize that you need to draw your stuff in the right order? If your background is black and you render your object first, cull backfaces and don't disable depth writes (or depth test for everything else) the result can only be fade-to-black, since nothing behind the object can pass the z-test.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!