Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Push/Pop Problem

  1. #1
    Newbie Newbie
    Join Date
    Feb 2013
    Posts
    2

    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.
    Code :
    // 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!

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,224
    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:

    Code cpp:
    // 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();

  3. #3
    Newbie Newbie
    Join Date
    Feb 2013
    Posts
    2
    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.

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,224
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •