3

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!

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Ethan Gill
  • 76
  • 1
  • 9

1 Answers1

8

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.

marchinram
  • 5,698
  • 5
  • 47
  • 59
  • Thank you thank you thank you! I knew it was something dumb I was forgetting. I would upvote, but no reputation.. – Ethan Gill Jun 19 '13 at 15:21
  • thank you!! This really saved me, afer an hour of struggle. I would do more upvotes than one if I could. – Lukas Petr Oct 28 '14 at 17:25