I’m having a problem while rendering a 3d model in OpenGL. I am able to render it, but when it does the triangles look like they’re fighting to be on top. I’m not really sure why this would be happening.
Here’s a video of what I’m talking about: Jittery Triangles. I’m using immediate mode in this video, but it was doing the same thing using VBOs.
*EDIT: Well Thanks Tim! I for some reason had my near plane set to 0.00001 and changing it to 0.1 fixed the problem.
This is known as z-fighting and it occurs when precision is lost in the z-buffer. The usual causes are:
I’d say that #3 is the most likely cause of your problems. You always have to keep an eye out for floating point errors!
#4 is another possible problem, but it usually only crops up if you have a camera transformation very far from the origin, and can be solved by using matrices of doubles and converting them to floats just before passing them to the gpu.
Here is a good article on projection matrix Z-buffer math.