Weston
Weston

Reputation: 1491

OpenGL ES 2.0 Z-Axis not effecting occlusion

So I am doing some OpenGL experimentation using this tutorial but I am running into an issue, for some reason the depth of my vertices doesn't seem to matter in how they are drawn. In the screenshot below the cubes have the same size, however the larger cube is closer to the screen. I believe it should be occluding the smaller cube, but it is not. I have followed the code in the tutorial almost exactly, is there anything obviously wrong?

http://games.ianterrell.com/opengl-basics-with-glkit-in-ios5-encapsulated-drawing-and-animation/

screenshot http://dl.dropbox.com/u/2396540/image.png

Upvotes: 1

Views: 266

Answers (1)

Nikolai Ruhe
Nikolai Ruhe

Reputation: 81878

You probably set up your GLKView without a depth buffer. GLKView has a propery drawableDepthFormat that controls creation and precision of the drawable's depth buffer. The default value is GLKViewDrawableDepthFormatNone which is good for 2D compositing.

When you want to draw 3D objects you should set it to GLKViewDrawableDepthFormat16 or GLKViewDrawableDepthFormat24 if you need more depth precision.

Upvotes: 2

Related Questions