Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't see anything in your setup code that loads your shaders - I presume you are doing this somewhere in your code?</p> <p>In addition, in your setup code, you are creating your framebuffer. The <code>GLKView</code> does this for you - indeed you are telling the view to use a 24-bit depthbuffer in your <code>viewDidLoad</code> method:</p> <pre><code>GLKView *view = (GLKView *)self.view; view.context = self.context; view.drawableDepthFormat = GLKViewDrawableDepthFormat24; </code></pre> <p>So what your <code>glkView:drawInRect:</code> code above is doing is saying: "Bind my handmade framebuffer, and draw some stuff into it". The <code>GLKView</code> then automatically presents itself, but nothing has been drawn into it, you've only drawn into your handmade buffer. Unless you need additional framebuffer objects for tasks such as rendering to texture, then you don't need to concern yourself with framebuffer creation at all - let the <code>GLKView</code> do it automatically.</p> <p>What you should be doing in your <code>setupGL</code> method (or anywhere you like in the setup) is creating your vertex array object(s) that remember the openGL state required to perform a draw. Then, in the <code>glkView:drawInRect:</code> method you should:</p> <ol> <li>Clear using <code>glClear()</code>.</li> <li>Enable your program.</li> <li>Bind the vertex array object (or, if you didn't use a VAO, enable the appropriate vertex attrib pointers).</li> <li>Draw your data using <code>glDrawArrays()</code> or <code>glDrawElements()</code>.</li> </ol> <p>The <code>GLKView</code> automatically sets its context as current, and binds its framebuffer object before each draw cycle.</p> <p>Perhaps try to think of <code>GLKView</code> more like a regular <code>UIView</code>. It handles most of the openGL code behind the scenes for you, leaving you to simply tell it what it needs to draw. It has its <code>drawRect:</code> code just like a regular <code>UIView</code> - with a regular <code>UIView</code> in <code>drawRect:</code> you just tell it what it should draw, for example using Core Graphics functions - you don't then tell it to present itself.</p> <p>The <code>GLKViewController</code> is then best thought of as handling the mechanics of the rendering loop behind the scenes. You don't need to implement the timers, or even worry about pausing the animation on your application entering the background. You just need to override the <code>update</code> <em>or</em> <code>glkViewControllerUpdate:</code> method (depending on whether you're subclassing or delegating) to update the state of the openGL objects or view matrix.</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