title: OpenGL ES 2.0 Buffer Setup
body: <p>I noticed that if I bind my depth buffer before the color buffer, the application works as intended:</p>
  
  <pre><code>glGenRenderbuffers(1, &amp;_depthbuffer);
  glBindRenderbuffer(GL_RENDERBUFFER, _depthbuffer);
  glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, _sw, _sh);
  glGenRenderbuffers(1, &amp;_renderbuffer);
  glBindRenderbuffer(GL_RENDERBUFFER, _renderbuffer);
  [_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:_eaglLayer];
  </code></pre>
  
  <p>However, binding the depth buffer afterwards causes nothing to render, even my glClearColor setting is ignored:</p>
  
  <pre><code>glGenRenderbuffers(1, &amp;_renderbuffer);
  glBindRenderbuffer(GL_RENDERBUFFER, _renderbuffer);
  [_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:_eaglLayer];
  glGenRenderbuffers(1, &amp;_depthbuffer);
  glBindRenderbuffer(GL_RENDERBUFFER, _depthbuffer);
  glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, _sw, _sh);
  </code></pre>
  
  <p>I've gotten to understand some of the flow of how OpenGL ES 2.0 works by researching the individual components thoroughly, but this seems as if it's the only thing that everyone just does in their tutorials/books, but doesn't explain why. Any ideas? Is this even an issue, or <em>possibly</em> something wrong in the rest of my setup? (if so I'll include all the code)</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>@cli_hlt - the depth buffer is already being added to the framebuffer:</p>
  
  <pre><code>glGenFramebuffers(1, &amp;_framebuffer);
  glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer);
  glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _depthbuffer);
  glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, _renderbuffer);
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>Depth bound before:</p>
  
  <p><img src="https://i.stack.imgur.com/a9poi.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/pdL72.png" alt="enter image description here"></p>
  
  <p>Depth bound after:</p>
  
  <p><img src="https://i.stack.imgur.com/0y32O.png" alt="enter image description here"></p>