I am doing a project which involves displaying 3D objects. I have used the line primitive to draw the object. My problem is to remove the hidden lines of the object to get a understandable form of the object. I tried enabling the GL_DEPTH_TEST and using the depth function but it did not work. Is it possible to do depth test for objects which are drawn using GL_LINES or GL_LINE_LOOP. I haven’t used shading is it necessary? how can we get a 3D view of the object?
this is the code segment that i have used:
My Z axis is away from the user
Please help me out
OpenGL is a state machine, there is not really a difference in the above code if glEnable is moved there.
I would recommend to always set values and then enable things, this avoids some pitfalls.
Of course wireframes alone are depth tested against each other but you can look through the interior of faces. To remove hidden lines in a 3D drawing with depth test you need to draw something into the faces occluding them.
The standard method is (from top of my head, not compiled):
Draw the model shaded into the depth buffer first fo get occluders:
glPolygonOffset(1.0f, 1.0f); // Move shaded back (in screen space depth).
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glDepthFunc(GL_LESS); // default;
Draw depth tested wireframes on top of that, only the frontmost remain.
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
This is probably a little different than using lines. Polygon offset is only working with polygonal geometry (all OpenGL primitives except GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP). To get correct results you should not use it mixing lines and polygons, but only with switching polygon mode.
But the idea is the same. Experiment.
[This message has been edited by Relic (edited 08-12-2003).]
glClearDepth(1.0) doesn’t actually clear the depth buffer, but sets the clear value for the depth buffer. You must also call glClear(GL_COLOR_BUFFER | GL_DEPTH_BUFFER) to clear the depth buffer. From the code snippet you gave, it isn’t clear whether you are doing this.