Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Since your working with 2D and ortho I find that it helps to have a viewport with coordinates that match your resolution, so this will keep things more readable:</p> <pre><code>CGRect rect = self.view.bounds; if (ORTHO) { if (highRes &amp;&amp; (retina == 1)) { glOrthof(0.0, rect.size.width/2, 0.0 , rect.size.height/2, -1, 1000.0); } else { glOrthof(0.0, rect.size.width, 0.0 , rect.size.height, -1, 1000.0); } glViewport(0, 0, rect.size.width*retina, rect.size.height*retina); } </code></pre> <p>Notice that I always use 320x480 coordinates even on retina, this way I can use the same coordinates for both res, and a .5 will give me pixel perfect on retina, but you can go the other way.</p> <p>Regarding depth I use a -1 to 1000 depth, so I can draw up to -1000 Z.</p> <p>Make sure you're binding the depth buffer correctly, something like this:</p> <pre><code> // Need a depth buffer glGenRenderbuffersOES(1, &amp;depthRenderbuffer); glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer); glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, framebufferWidth, framebufferHeight); glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer); </code></pre> <p>Or your problem can be as simple as using a depth that's behind your camera and lights or bigger than your buffer, try to use a depth between 0 and -1 (-0.5 for ex.), with my glOrthof you can go up to -1000;</p> <p><strong>EDIT</strong></p> <p>Values in glOrthof for near and far specify a quantity (distance), not coordinates, this can be confusing when specifying depth values. When you specify 1000 for the far parameter, what we are actually saying is the far clipping plane is a 1000 units distant from the viewer, the same with the near field, unfortunately specifying a clipping plane behind the viewer will take negative values, which contributes to the confusion. </p> <p>So when it comes drawing time we have a clipping plane that's 1000 units from the viewer in front (far or into the screen), in terms of coordinates Z is negative when bellow the viewing plane (into the screen), our actually drawing world is between Z = 1 and Z = -1000, being -1000 the farthest we can go with these parameters.</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