Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing depth buffer on iOS with OpenGL ES 1.1
    text
    copied!<p>I'm trying to get a depth buffer working so I can start making a game for iOS. I'm fine with OpenGL and Objective-C for OSX but this is my first time making an iphone application.</p> <p>I removed the ES1Renderer and ES2Renderer classes and moved the ES1 code into the EAGLView class. The default animation worked when I did that. When I tried to use perspective it went wrong. I get a white screen now. Can someone tell me what I'm doing wrong?</p> <p>In the initialisation method:</p> <pre><code>// Create default framebuffer object. glGenFramebuffersOES(1, &amp;defaultFramebuffer); glGenRenderbuffersOES(1, &amp;colorRenderbuffer); glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer); glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer); glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorRenderbuffer); //Initialisation code for the game's graphics and to develop the scene glEnable(GL_DEPTH_TEST); //Enables Depth Testing glDepthFunc(GL_LEQUAL); glDepthMask(GL_TRUE); //glEnable(GL_CULL_FACE); //glCullFace(GL_FRONT); //Setup projection matrix glMatrixMode(GL_PROJECTION); glLoadIdentity(); double xmax = 0.04142135624 * ((float) backingWidth)/backingHeight; glFrustumf(-xmax, xmax, -0.04142135624, 0.04142135624, 0.1, 2000); //The ymax and min have been precalculated glMatrixMode(GL_MODELVIEW); //Select The Modelview Matrix glLoadIdentity(); </code></pre> <p>In the drawView method:</p> <pre><code> static const GLfloat squareVertices[] = { 1, 1,-0.1f, -1, 1,-0.1f, 1, -1,0.1f, -1, -1,0.1f, }; static const GLubyte squareColors[] = { 0,0,200,255, 40,90,250,255, 0,0,200,255, 50,100,230,255, }; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClear(GL_DEPTH_BUFFER_BIT); glVertexPointer(3, GL_FLOAT, 0, squareVertices); glEnableClientState(GL_VERTEX_ARRAY); glColorPointer(4, GL_UNSIGNED_BYTE, 0, squareColors); glEnableClientState(GL_COLOR_ARRAY); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); [context presentRenderbuffer:GL_RENDERBUFFER_OES]; </code></pre> <p>In the layoutSubviews method:</p> <pre><code>// Allocate color buffer backing based on the current layer size glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer); [context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*) self.layer]; glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &amp;backingWidth); glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &amp;backingHeight); glGenRenderbuffersOES(1, &amp;depthRenderbuffer); glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer); glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight); glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer); if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) { NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) ); return NO; } return YES; [self drawView:nil]; </code></pre> <p>I've done everything it seems I have to do. I don't know why it's so much more complicated for iOS.</p> <p>Thankyou for any help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload