title: Messed Up OpenGL Depth Buffer?
body: <p>I have something rather strange going on at the moment with my code. I am running this on a BlackBerry Playbook and it is OpenGL ES 1.1</p>
  
  <p>EDIT 4: I deleted everything I have posted to simplify my question.</p>
  
  <p>I took the code and simplified it to drawing two overlapping triangles. Here is the array containing the coordinates as well as an array containing colours:</p>
  
  <pre><code>GLfloat vertices[] =
  {
            // front
             175.0f, 200.0f, -24.0f,
             225.0f, 200.0f, -24.0f,
             225.0f, 250.0f, -24.0f,
  
            // back
             200.0f, 200.0f, -25.0f,
             250.0f, 200.0f, -25.0f,
             250.0f, 250.0f, -25.0f
  };
  
  
  static const GLfloat colors[] =
  {
         /* front  */  1.0f,0.0f,0.0f,1.0f,1.0f,0.0f,0.0f,1.0f,1.0f,0.0f,0.0f,1.0f, //Red
         /* back  */  0.0f,1.0f,0.0f,1.0f,0.0f,1.0f,0.0f,1.0f,0.0f,1.0f,0.0f,1.0f //Green
  };
  </code></pre>
  
  <p>Please note that my coordinates are 0 to 1024 in the x direction and 0 to 600 in the y direction as well as 0 to -10000 in the z direction.</p>
  
  <p>Here is my setup code which reflects this:</p>
  
  <pre><code>    glClearDepthf(1.0f);
      glClearColor(1.0f,1.0f,1.0f,1.0f);
      glEnable(GL_DEPTH_TEST);
      glDepthMask(GL_TRUE);
      glShadeModel(GL_SMOOTH);
  
      glViewport(0, 0, surface_width, surface_height);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
  
      glOrthof(0, surface_width, 0, surface_height, 0, 10000);
  
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();
  
      glEnable(GL_DEPTH_TEST);
      glDepthMask(GL_TRUE);
  </code></pre>
  
  <p>I have depth enabling in two places as I was trying to rule out the possibility that it was supposed to be used while a certain matrix mode was chosen.</p>
  
  <p>Lastly here is my render code:</p>
  
  <pre><code>void render()
  {
      //Typical render pass
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
      glEnableClientState(GL_VERTEX_ARRAY);
      glVertexPointer(3, GL_FLOAT, 0, vertices);
  
      glEnableClientState(GL_COLOR_ARRAY);
      glColorPointer(4, GL_FLOAT, 0, colors);
  
      glDrawArrays(GL_TRIANGLES, 0 , 6);
  
      glDisableClientState(GL_VERTEX_ARRAY);
      glDisableClientState(GL_COLOR_ARRAY);
  
      //Use utility code to update the screen
      bbutil_swap();
  }
  </code></pre>
  
  <p>The issue is that no matter what I do the green triangle is always overlayed over the red one. Changing z values either way has no effect on the finished image. I cannot figure this out.</p>