Triangle Problem

I am constructing a figure from a set of points via a delaunay triangulation (the implementation I’m using is from MatLab 6.5). I then use a for loop to construct the figure (the delaunay alg returns an n x 3 array with the indices of points in another n x 3 array).

When I display this figure (it looks like a 30 degree segment of a sphere) there are no problems, however when I rotate the figure 90 degrees the side that is suppose to be hidden has some of its triangles superimposed over the nearest side’s triangles.

I have discussed this with someone else and they thought it was due to non-uniform normals (some of the triangles wind cw others ccw) but I believe it is due to something I am doing wrong with the depth buffer. I tried to eliminate the depth problem by playing with glDepthFunc(…) but no value helped. I tried to eliminate the normal problem by drawing the figure twice (once cyling forward through the triangle vertices and once backward) (with and without face culling) but that didn’t help either. So I’m left to believe there is a third possibility.

Any help would be appreciated.

Colby Toland

Have you enabled depth testing?

Dude

Yes depth testing is enabled.

NOTE: When I disable depth testing the problem persists.

Colby

I suppose this could be a z-fighting problem.

Are you using a 16-bit depth buffer or a 24-bit depth buffer? If you’re using a 16-bit depth buffer can you try using a 24-bit depth buffer and see if things improve? In either case, can you push your near plane out at all?

If necessary I can adjust my near plane but as for whether the depth buffer is 16 or 24 bit I’m not sure what you mean by that.

Colby

You can query the precision of the depth buffer with:

int depthBits;
glGetIntegerv(GL_DEPTH_BITS, &depthBits);

If depthBits is 16 try to choose a visual / pixelformat with a 24-bit depth buffer instead.

What your near plane and far plane values?