# 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).

``````void Display (void)
{
glMatrixModel  (GL_MODELVIEW);

glTranslatef   (5,3,1);
glRotatef      (30, 1,0,0);
glScalef       (2.1, 1.0, 2.1);

glBegin (GL_POINTS);
glVertex2d (5,2);
glEnd ();

}
``````

Thanx.

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.

``````glLoadIdentity();
glTranslatef(5,3,1);
glRotatef(30, 1,0,0);
glScalef(2.1, 1.0, 2.1);

``````

BTW, mathematically that translates to M[SUB]Modelview[/SUB] = M[SUB]I[/SUB]* M[SUB]T[/SUB]* M[SUB]R[/SUB]* M[SUB]S[/SUB] 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.

Thanks for the replies. This clarifies things quite a bit for me.