title: Understanding glPushMatrix() and glPopMatrix()
body: <p>I have the following code:</p>
  
  <pre><code>void drawObj1(){    
      glPushMatrix();
              glTranslatef(rBaseInitPos + (rBaseDim[0] / 2), rBaseDim[1] + baseIncrement + rBaseDim[1] / 2, rBaseDim[2] / 2);
              glRotatef(rBaseArmRotateAngle, 0, 1, 0);
              /*
                      glPushMatrix();
      */
              drawRobotBaseArm();
              /*
                      glPopMatrix();
      */
              glPushMatrix();
                  glRotatef(90, 1, 0, 0);
                  glEnable(GL_TEXTURE_2D);
                  glBindTexture(GL_TEXTURE_2D, rCamouflage[0]);
                  gluQuadricTexture(obj, GL_TRUE);
                  gluQuadricDrawStyle(obj, GLU_FILL);
                  gluDisk(obj, 0, (rBaseDim[0] / 2) - 0.5, 16, 4);
                  gluCylinder(obj, (rBaseDim[0] / 2) - 0.5, (rBaseDim[0] / 2) - 0.5, rBaseDim[1] / 2, 16, 4);
                  glDisable(GL_TEXTURE_2D);
              glPopMatrix();                      
          glPopMatrix();
      }
  
  
  void drawScene(){
      glTranslatef(X, Y, Z);
      drawObj0();
      drawObj1();
  }
  </code></pre>
  
  <p>With the above code, since there is one translation inside <code>drawRobotBaseArm();</code> both the <code>Disk</code>and the  <code>Cylinder</code> are also translated. Since I don't want that, I´ve uncomment the code up and down of <code>drawRobotBaseArm();</code></p>
  
  <p>Doing this, the following code:</p>
  
  <pre><code>glTranslatef(rBaseInitPos + (rBaseDim[0] / 2), rBaseDim[1] + baseIncrement + rBaseDim[1] / 2, rBaseDim[2] / 2);
  glRotatef(rBaseArmRotateAngle, 0, 1, 0);
  </code></pre>
  
  <p>Only acts upon <code>drawRobotBaseArm();</code> and now, the <code>Disk</code>and the  <code>Cylinder</code> are not translated and rotated.</p>
  
  <p>I can't seem to understand how <code>glPushMatrix()</code> and <code>glPopMatrix()</code> work. Any idea how can I achieve what I'm looking for?</p>