0

As you can see: https://i.stack.imgur.com/ztM0v.png, certain polygons are simply being rendered over the other ones. Does anyone have any suggestions or related reading on rendering these in the correct order so that they do not overlap?

3 Answers 3

5

For opaque faces render order is not important as long as you use the depth buffer.

NeHe has a tutorial covering all the basics. Start here http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=02

See also Opengl Depth buffer and Culling and Depth Buffer in OpenGL .

0

You need to enable depth testing. Make sure that

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL); //Maybe not this line but try it anyway, GL_DEPTH_TEST is the important one

is in your initialisation code.

1
  • 3
    There's no such thing like "initialization" in OpenGL, it's all about state. Sure some things like textures, FBOs, PBOs and VBOs are created and then reused. But in any real OpenGL application this happens on demand, too. State like enabling/disabling depth testing and the depth func should be set in the rendering function right before the part that requires some particular state.
    – datenwolf
    Apr 30, 2011 at 10:41
0

You should make sure that you have set the matrix mode in projection view or 3d and work with 3d always.

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(p, (double) w / (double) h, arg1, arg2);

Then make sure you enable depths by this:

glEnable(GL_DEPTH_TEST);

Next, render using GL...3f or GL...3d to render through 3d, where ... is whatever function you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.