Cocoa Design Patterns
Learning OpenGL ES for iOS
Presentations
Buy at Amazon Now
  • Cocoa Design Patterns
    Cocoa Design Patterns
    by Erik M. Buck, Donald A. Yacktman
  • Learning OpenGL ES for iOS: A Hands-on Guide to Modern 3D Graphics Programming
    Learning OpenGL ES for iOS: A Hands-on Guide to Modern 3D Graphics Programming
    by Erik M. Buck

Errata > Ch 8 - Boat model incorrectly drawn

In Chapter 8, the examples with the Skybox show up some problems with the boat model. Some parts (such as deck hatches) appear in front of everything and one part of the mast (towards the top) always appears behind the mast and sails. Is there a fix for these issues ? My own models using GLKit have shown the same types of problem where a model is spoilt by a few depth problems.

Regards Graham
June 15, 2013 | Unregistered CommenterGraham Randall
You have indeed found a problem!

I am uploading revised code for OpenGLES_Ch8_1 and OpenGLES_Ch8_2. Although both sample have a depth buffer attachment, neither sample enabled GL_DEPTH_TEST. The depth buffer attachment is not used without enabling GL_DEPTH_TEST.

Once GL_DEPTH_TEST is enabled, there is a second problem: The skybox effect should not write to the depth buffer because the skybox simulates a distant sky rendered on the inside of a nearby cube. The following sequence of code is needed to draw the skybox:
[self.skyboxEffect prepareToDraw];
glDepthMask(false); // prevent writes to the depth buffer
[self.skyboxEffect draw];

Drawing everything else should write to the depth buffer:
[self.baseEffect prepareToDraw];
glDepthMask(true); // reenable depth buffer writes
[self.boatModel draw];
June 19, 2013 | Registered CommenterErik Buck