Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can "See through" objects in openGL

Tags:

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?

like image 907
Derek Avatar asked Sep 02 '25 11:09

Derek


1 Answers

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

like image 114
starrify Avatar answered Sep 04 '25 11:09

starrify