3

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.

2
  • Can you comment on how your objects are transparent and what version(s) of OpenGL you are dealing with?
    – masebase
    Oct 5, 2011 at 1:07
  • i am dealing with opengl 1.1 .. for example there are some glass vases inside a room which has glass doors. user should be able to see only opaque objects inside the room like wooden furniture through the glass door but not the glass vases inside the room.
    – user942502
    Oct 5, 2011 at 1:31

2 Answers 2

5

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.

3

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.
8
  • Thanks for the reply. yes i can achieve this by sorting the transparent triangles(front to back). but all the triangles of transparent objects are drawn in one go. when i rotate the scene, the effect should preserve. unfortunately sorting is not allowed in my task because i am dealing with half a million of triangles in a scene. do you think i can achieve this using some combimation of blendfunction.
    – user942502
    Oct 5, 2011 at 2:37
  • I'm not sure this is possible, at least with OpenGL 1.1 functionality. Can you split into 2 buffers?
    – geofftnz
    Oct 5, 2011 at 2:58
  • No i cannot split in to 2 buffers as i do not have classification of which triangles form vase and which triangles form door in my triangle buffer.
    – user942502
    Oct 5, 2011 at 3:05
  • You don't need to know that... I mean split buffer into opaque triangles and transparent ones.
    – geofftnz
    Oct 5, 2011 at 3:16
  • 2
    Just out of interest, why should transparent objects behind other transparent objects not be displayed?
    – geofftnz
    Oct 5, 2011 at 3:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.