Jump to content
  • Advertisement
Sign in to follow this  
Steve Terry

OpenGL OpenGL Blending

This topic is 4904 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

I've written an .obj loader for OpenGL in C and I'm looking for some good tips or tutorials on how to acheive translucent objects with the materials file. I have several objects already with thier respective material files which can define translucent faces. The problem is how to render properly translucent objects with opaque ones. I've tried different methods such as rendering all opaque objects first, then z sorting all translucent objects, and rendering all translucent objects, but it never works, the translucent objects still show through opaque ones even though they should be covered up in areas, or opaque objects will show up above the translucent ones when they should be behind. Does anyone have any tips or pointers on how to handle these situations? Maybe a demo or example code that has a fully translucent object and a fully opaque object rotating around one another displaying properly?

Share this post


Link to post
Share on other sites
Advertisement
This is what I have so far:

if(m->tr < 1.0f){
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glColor4f(1.0f, 1.0f, 1.0f, m->tr);
}
else{
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
}

Is there something I missed? What is depth writes?

Ok I took out the glDisable(GL_DEPTH_TEST) and rendered all opaque objects first then all translucent objects based on m->tr, it seems to work... which is odd because I thought you had to have the depth test disabled to properly draw blended objects. But some objects that were transparent before are now opaque :-/

Share this post


Link to post
Share on other sites
Hi,

Have you forgotten to set glDepthMask to true or false?

If set to true true then the zbuffer will be written to for all polygons regardless whether they are opaque or transparent.

So the set up is

Render all opaque polygons using
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
So the zbuffer is both read and written to

Render all transparent polygons (preferably sorted)
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
So the zbuffer is only read, not written to

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!