title: Depth Buffer in OpenGL
body: <p>I am trying to draw a series of rectangles using OpenGL but some of the ones that should appear below a rectangle appear above it. </p>
  
  <p>To enable the depth function I am using</p>
  
  <pre><code>glClearDepth(1.0f);
  glDepthFunc(GL_LESS);
  glEnable(GL_DEPTH_TEST);
  </code></pre>
  
  <p>I am using gluLookAt at the begining of each draw. Here is an image of the problem. The blue rectangles are positioned with higher y values than the green rectangles.</p>
  
  <p><img src="https://i.stack.imgur.com/qigRm.png" alt="alt text">
  <img src="https://i.stack.imgur.com/ZusMK.png" alt="alt text"></p>
  
  <p>As you can see in the top image some of the green rectangles appear above the blue ones. Any idea why this is happening and what I can do to fix it? Could it have something to do with the order that I'm drawing the rectangles?</p>