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: Question about glPushMatrix?

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2011
    Posts
    8

    Question about glPushMatrix?

    Hey all, I'm a beginner here so bear with me. As far as I understand it when you push a new matrix on it's kinda like creating a copy of your current scene and then you can act accordingly and then you can pop it off and be left your original scene. (this may be wrong, please correct me if so) What I don't get is how come this code:

    Code :
    //position is an array of random values, this is a while loop which goes through all the points and creates a cube
    glPushMatrix();
            glTranslated(-positionx[i], -positiony[i] - 3, -positionz[i]); //translate the cube
     
            glColor3f (1.0f, 0.0f, 0.0f);   
            glutSolidCube(2); //draw the cube
            glPopMatrix();

    doesn't work without the push and pop of the matrix. Could someone clarify this for me? Thanks!

  2. #2
    Intern Contributor
    Join Date
    Jan 2010
    Location
    Japan - Greece
    Posts
    99

    Re: Question about glPushMatrix?

    Hello interwound!

    Well glPushMatrix() actually saves the current matrix. So that means that all depends on your previous call of glMatrixMode(). So because everything depends on that can you tell us what was the parameter of your previous call to this function? Make sure that it was GL_MODELVIEW because what you are trying to achieve concerns the modelview matrix.
    My Blog

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2011
    Posts
    8

    Re: Question about glPushMatrix?

    Oh I think I'm starting to understand, do I have to save the current matrix so that after each translation and adding of cube I can go back to my original starting point so that each cube is added from the same origin?

  4. #4
    Intern Contributor
    Join Date
    Jan 2010
    Location
    Japan - Greece
    Posts
    99

    Re: Question about glPushMatrix?

    Yep, that's pretty much it.
    Even though the code is kind of outdated, you can observe a nice example of hierarchical usage of push/pop matrix in order to draw a complex model in the link below.

    http://www.gamedev.net/page/resource...ierarchy-r1267

    Just as an additional note though, remember that from openGL 3.0 and up both glPush() and glPop Matrix have been deprecated, which means you would have to have your own implementation of them.
    My Blog

Posting Permissions

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