Question

I wrote some code to load a .obj file one triangle at a time in 3d. Each of these triangles are placed in the correct location, and are given a random color. When the full shape is loaded some triangles, even though they are placed in front of the others, go to the back and are not seen.

http://postimg.org/image/ln31rhabd/

The website above shows how the triangles Behind the cone are showing up OVER the ones in-front. the cone is being looked at from a top-front angle.

What do I have to do to make the ones on top actually show up on top? Do they stack in the order that each triangle was created?

Was it helpful?

Solution

At the outset, i believe the problem is related to Depth Buffering. Try enabling z-buffering in by calling the following functions:

glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);

And also, do check if you are clearing the z-buffers along with the color buffers.

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top