title: OpenGL glOrtho and GL_DEPTH_TEST
body: <p>I'm trying to draw a simple triangle and I've faced a problem combining <code>glEnable(GL_DEPTH_TEST)</code> and <code>glOrtho</code>. The triangle is displayed without depth test not depending on the <code>nearVal</code> argument but if the depth test is enabled and the <code>nearVal</code> is different from 0 then nothing is displayed. Here is the code.</p>
  
  <pre><code>@Override
  public void init(GLAutoDrawable drawable) {
      GL2 gl = drawable.getGL().getGL2();
  
      gl.glShadeModel(GL2.GL_SMOOTH);
      gl.glEnable(GL2.GL_DEPTH_TEST);
      gl.glDepthFunc(GL2.GL_LEQUAL);
      gl.glClearColor(0, 0, 0, 1);
      gl.glClearDepth(100.0);
  
      gl.glMatrixMode(GL2.GL_PROJECTION);
      gl.glLoadIdentity();
  
      // the nearVal = 1 and the triangle is not displayed
      // if we set the nearVal = 1 then the triangle is displayed
      gl.glOrtho(-1, 1, -1, 1, 1, 10); 
  }
  
  @Override
  public void display(GLAutoDrawable drawable) {      
      GL2 gl = drawable.getGL().getGL2();
  
      gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
  
      gl.glBegin(GL.GL_TRIANGLES);        
      gl.glColor3f(1, 0, 0);
      gl.glVertex3f(0.0f, 0.0f, 0);       
      gl.glColor3f(0, 1, 0);
      gl.glVertex3f(1, 0.0f, 0);      
      gl.glColor3f(0, 0, 1);
      gl.glVertex3f(0f, 1f, 0);       
      gl.glEnd();
  
      gl.glFlush();
  }
  </code></pre>