Derek
Derek

Reputation: 892

Can "See through" objects in openGL

enter image description here

I'm not sure why this is happening, I'm only rendering a few simple primitive QUADS. The red is meant to be in front of the yellow.

The yellow always goes in-front of the red, even when it's behind it.

Is this a bug or simply me seeing the cube wrongly?

Upvotes: 4

Views: 5513

Answers (2)

Michael M
Michael M

Reputation: 961

I had the same problem but it was unrelated to the depth buffer, although I did see some change for the better when I enabled that. It had to do with the blend functions used which combined pixel intensities at the last step of rendering. So I had to turn off glBlendFunc()

Upvotes: 0

starrify
starrify

Reputation: 14751

Turn the depth buffer and depth test on, or OpenGL would draw what is latter on the top.

Your application needs to do at least the following to get depth buffering to work:

Ask for a depth buffer when you create your window.

Place a call to glEnable (GL_DEPTH_TEST) in your program's initialization routine, after a context is created and made current.

Ensure that your zNear and zFar clipping planes are set correctly and in a way that provides adequate depth buffer precision.

Pass GL_DEPTH_BUFFER_BIT as a parameter to glClear, typically bitwise OR'd with other values such as GL_COLOR_BUFFER_BIT.

See here http://www.opengl.org/resources/faq/technical/depthbuffer.htm

Upvotes: 14

Related Questions