views:

126

answers:

1

I have an iPhone OpenGL-ES 1.1 project that renders simple 3D models. If I do not attach a depth buffer, everything renders correctly (except with no depth awareness of course). When I attach the depth buffer however, all that renders is a magenta screen. The clear color is not set to magenta. It is blue. Anyone know what is going on here. This is my setup code =>

    glGenFramebuffersOES(1, &framebuffer);
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, framebuffer);

    glGenRenderbuffersOES(1, &colorRenderbuffer);
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
    glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGBA8_OES, screenWidth, screenHeight);
    glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorRenderbuffer);

    glGenRenderbuffersOES(1, &depthRenderbuffer);
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
    glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, screenWidth, screenHeight);
    glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);

This gives the magenta screen. Commenting out the last 4 lines will cause it to render the objects.

+1  A: 

probably your screenWidth / screenHeight aren't initialized yet?

check if the folllowing fixes your problem: glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, 320, 480);

Random
It wasn't quite that. They were initialized, but they did not match the dimensions of the UIView I was drawing to. Thanks, this got me looking in the right place
Joe Cannatti