title: Can't use glLoadIdentity as expected after a translation in JOGL
body: <p>I'm just starting with JOGL, and there's something I haven't been able to do: There's an example of basic drawing and rotation in <a href="http://nehe.gamedev.net/tutorial/rotation/14001/" rel="nofollow">NeHe tutorials</a>, and everything works just fine, except the  <code>glLoadIdentity();</code> used after the first triangle and before the next quad. The JOGL code is the next:</p>
  
  <pre><code>float rtri  = 0.0f;
  float rquad = 0.0f;
  
  @Override
  public void display(GLAutoDrawable drawable) {
  
      final GL2 gl = drawable.getGL().getGL2();
  
      gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
  
      gl.glMatrixMode(GL2.GL_MODELVIEW);
      gl.glLoadIdentity();
  
      gl.glTranslatef(-1.5f,0.0f,-6.0f);
      gl.glRotatef(rtri, 0.0f, 1.0f, 0.0f);
  
      gl.glBegin(GL2.GL_TRIANGLES);
      {
          gl.glColor3f(1.0f,0.0f,0.0f);
          gl.glVertex3f( 0.0f, 1.0f, 0.0f);
  
          gl.glColor3f(0.0f,1.0f,0.0f);
          gl.glVertex3f(-1.0f,-1.0f, 0.0f);
  
          gl.glColor3f(0.0f,0.0f,1.0f);
          gl.glVertex3f( 1.0f,-1.0f, 0.0f);
      }
      gl.glEnd();
  
      // Here seems to be the problem
      gl.glLoadIdentity();
  
      gl.glTranslatef(3.0f, 0.0f, 0.0f);
      gl.glRotatef(rquad, 1.0f, 0.0f, 0.0f);
  
      gl.glBegin(GL2.GL_QUADS);
      {
          gl.glColor3f(0.5f, 0.5f, 1.0f);
          gl.glVertex3f(-1.0f, 1.0f, 0.0f);
          gl.glVertex3f( 1.0f, 1.0f, 0.0f);
          gl.glVertex3f( 1.0f,-1.0f, 0.0f);
          gl.glVertex3f(-1.0f,-1.0f, 0.0f);
      }
      gl.glEnd();
  
      gl.glFlush();
  
      rtri    += 0.15f;
      rquad   -= 0.5f;
  }
  </code></pre>
  
  <p>As you can see, there is a <code>gl.glLoadIdentity();</code> before the Quad is defined. If this line is commented, the final program renders the first triangle rotating, and the quad translating around the triangle, but the quad has it's own rotation too.</p>
  
  <p>If that line is NOT commented, the quad is not rendered at all, and only the triangle is rendered, with it's defined colors and rotation.</p>
  
  <p>All examples I've seen so far seem to use the <code>gl.glLoadIdentity();</code> to restore the default state for current matrix mode (GL_MODELVIEW), but in this case, something else seems to be happening.</p>
  
  <p>I've tested with <code>gl.glPushMatrix();</code> and <code>gl.glPopMatrix();</code> before each drawing operation, surrounding all the drawing code, with and without the <code>gl.glLoadIdentity();</code> in the middle, but nothing seems to help.</p>
  
  <p>I've checked other examples' init and reshape method, but everything seems just fine:</p>
  
  <pre><code>@Override
  public void init(GLAutoDrawable drawable) {
      final GL2 gl = drawable.getGL().getGL2();
      gl.glShadeModel(GL2.GL_SMOOTH);
      gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
      gl.glClearDepth(1.0f);
      gl.glEnable(GL2.GL_DEPTH_TEST);
      gl.glDepthFunc(GL2.GL_LEQUAL);
      gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST);
  }
  
  @Override
  public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
      final GL2 gl = drawable.getGL().getGL2();
      if (height &lt;= 0) {
          height = 1;
      }
      float h = (float) width / (float) height;
      gl.glMatrixMode(GL2.GL_PROJECTION);
      gl.glLoadIdentity();
      glu.gluPerspective(50.0f, h, 1.0, 1000.0);
      gl.glMatrixMode(GL2.GL_MODELVIEW);
      gl.glLoadIdentity();
  }
  </code></pre>
  
  <p>I'd like to keep learning OpenGL, while using Java (I'd love Java, and a long time ago I don't use C++), but I'm supposed to be in the very basics of OpenGL, and I wouldn't like to go on missing such a "basic" thing. Thank you all for your help, and sorry if my english has errors.</p>