Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Basic Question About Matrix Stack

  1. #1
    Junior Member Regular Contributor
    Join Date
    Apr 2012

    Basic Question About Matrix Stack

    Suppose this is the Display function for a very simple OpenGL, GLUT, program.
    How many matrices would this put on the matrix stack?
    I used to think it would be 4. However, now I'm leaning towards 1,
    which would be the product of the (Identity matrix) x (the Translation Matrix) x
    (the Rotation matrix) x (the Scale Matrix).

    Code :
    [FONT=Courier New]void Display (void)
        glMatrixModel  (GL_MODELVIEW);
        glLoadIdentity ();
        glTranslatef   (5,3,1);
        glRotatef      (30, 1,0,0);
        glScalef       (2.1, 1.0, 2.1);
        glBegin (GL_POINTS);
           glVertex2d (5,2);
        glEnd ();


  2. #2
    Member Regular Contributor
    Join Date
    Aug 2008
    Yeah, there's just 1 matrix manipulated by that code. All the transformation functions affect the matrix at the current stack depth. Matrices aren't put onto the stack unless you call glPushMatrix (duplicates current matrix + increases stack depth) + removed when you call glPopMatrix (reduces stack depth).
    OpenGL only guarantees that GL_MODELVIEW will have a stack >=32 matrices, GL_TEXTURE has depth >=2, GL_COLOR has depth >=2, GL_MODELVIEW has depth >=2, so you shouldn't call glPushMatrix too many times without glPopMatrix calls.

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Code :
    glRotatef(30, 1,0,0);     
    glScalef(2.1, 1.0, 2.1);

    BTW, mathematically that translates to MModelview = MI* MT* MR* MS so as you can see, the current matrix is computed by matrix commands concatenated in reverse order, with the first(right-most) matrix being specified by the last command and the last(left-most) matrix being specified by the first command.

  4. #4
    Junior Member Regular Contributor
    Join Date
    Apr 2012
    Thanks for the replies. This clarifies things quite a bit for me.

Posting Permissions

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