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.
-
Can you comment on how your objects are transparent and what version(s) of OpenGL you are dealing with?– masebaseOct 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.– user942502Oct 5, 2011 at 1:31
2 Answers
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.
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:
- Enable z-buffer writes and tests
- Render all opaque objects
- Render all transparent objects front to back. The z-buffer will prevent transparent objects from being displayed behind other transparent objects.
-
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. 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?– geofftnzOct 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. Oct 5, 2011 at 3:05
-
You don't need to know that... I mean split buffer into opaque triangles and transparent ones.– geofftnzOct 5, 2011 at 3:16
-
2Just out of interest, why should transparent objects behind other transparent objects not be displayed?– geofftnzOct 5, 2011 at 3:21