Problem enabling OpenGL ES depth test on iPhone. What steps are necessary?
I remember running into this problem when开发者_Go百科 I started using OpenGL in OS X. Eventually I solved it, but I think that was just by using glut and c++ instead of Objective-C...
The lines of code I have in init
for the ES1Renderer
are as follows:
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
Then in the render
method, I have this:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
I assume I'm missing something specific to either the iPhone or ES. What other steps are required to enable the depth test?
Thanks
The instructions are here, if anyone else has this problem. The code is also below:
glGenRenderbuffersOES(1, &depthRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, 320, 480);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) ;
if(status != GL_FRAMEBUFFER_COMPLETE_OES) {
NSLog(@"failed to make complete framebuffer object %x", status);
}
You need to allocate the depth buffer itself. Allocate a new renderbuffer with the internal format DEPTH_COMPONENT16 or DEPTH_COMPONENT24, and attach it to the framebuffer object.
#define USE_DEPTH_BUFFER 1
if you're using the OpenGL ES project template. This sets up a depth buffer somewhere in EAGLView.m.
精彩评论