Question

I'm using Ray Wenderlich's tutorials to make a simple OpenGlES 2 app using GLKit, and I've come across some problems.

I changed the sample code to display two cubes by adding vertex and indices data to the existing vertex and indices data structs. It works, and draws two cubes to the screen.

The problem is that when the new cube is behind the old one, it shows through. However, when the old cube is behind the new one, it doesn't show through.

Perhaps my depth testing is messed up?

I can't post images because of my reputation :( Here's a link to the source code though: https://www.dropbox.com/s/4xrq3gmnmbcz02m/EthanGillCubeSnap.zip

Any help is much appreciated!

Was it helpful?

Solution

On line 279 of HelloGLKitViewController.m I added the line below and it rendered correctly:

view.drawableDepthFormat = GLKViewDrawableDepthFormat24;

You need to make sure to set the depth buffer size on your GLKView or else no buffer will be created, which is what was happening to you before.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top