user942502
user942502

Reputation: 111

Rendering transparent objects in OpenGL

Iam trying to render some 3d objects using opengl. Requirement is that i need to hide all the transparent objects which are z-behind another transparent object. All the triangles are in single triangle buffer and will be drawn at once. Please throw some light.

Upvotes: 3

Views: 7943

Answers (2)

fintelia
fintelia

Reputation: 1211

Try using glDepthMask():

    //Render all opaque objects
    glDepthMask(false); //disable z-testing
    //Render all transparent objects*
    glDepthMask(true); //enable z-testing (for the next frame)

*Technically, you should render the transparent objects from back to front, but it is rarely noticeable if you don't.

Upvotes: 5

geofftnz
geofftnz

Reputation: 10102

You can do this by sorting your scene, which is what you have to do anyway to get transparency working correctly.

Here's what you need to do:

  1. Enable z-buffer writes and tests
  2. Render all opaque objects
  3. Render all transparent objects front to back. The z-buffer will prevent transparent objects from being displayed behind other transparent objects.

Upvotes: 3

Related Questions