Push/Pop Problem

For some reason, F is being placed relative to A instead of D even though E is placed relative to D. I don’t see why this problem is occurring. If I remove E, F is placed relative to D (as it should be), but I need them both where they are.

// A
glPushMatrix();
glTranslatef(0,0,0);
glCallList(x);

// B
glPushMatrix();
glTranslatef(0,195,-245);
glCallList(x);

glPopMatrix();

// C
glPushMatrix();
glTranslatef(274,272,0);
glCallList(x);

// D
glPushMatrix();
glTranslatef(0,0,0);

// E
glPushMatrix();
glTranslatef(140,440,75);
glCallList(x);

glPopMatrix();

// F
glPushMatrix();
glTranslatef(298,323,59);
glCallList(x);

glPopMatrix();

Thank you! :slight_smile:

I’m just going to re-post your source code with braces added for the Pushes and Pops. I think you’ll see what the problem is. You’ll notice that you’re missing about 3 levels of Pops for this to be balanced:


// A
glPushMatrix();
{
  glTranslatef(0,0,0);
  glCallList(x);

  // B
  glPushMatrix();
  {
    glTranslatef(0,195,-245);
    glCallList(x);
  }
  glPopMatrix();

  // C
  glPushMatrix();
  {
    glTranslatef(274,272,0);
    glCallList(x);
    
    // D
    glPushMatrix();
    {
      glTranslatef(0,0,0);

      // E
      glPushMatrix();
      {
        glTranslatef(140,440,75);
        glCallList(x);
      }
      glPopMatrix();

      // F
      glPushMatrix();
      {
        glTranslatef(298,323,59);
        glCallList(x);
      }
      glPopMatrix();

Thank you for your response! I would like to add that, oddly enough, the problem occurs even with the pops. I should have posted that code first. I haven’t the slightest idea why it is occurring. With or without the pops, F is being positioned relative to A instead of D. Everything else is positioned correctly except for this one, which is why I am so baffled.

Check for GL errors. If your pushes and pops are imbalanced, you should eventually trigger an error with pushing on a full stack or popping an empty one (GL_STACK_OVERFLOW, GL_STACK_UNDERFLOW). Also, all bets are off for interpreting what’s happening.