Push and Pop Matrix Operations

What is going on in the background with the pop and push operations? :confused:
when i do:

    //viewing transformation
    glLoadIdentity();
    glTranslatef(0,0,-7);
    glPushMatrix();
        glScalef(1.5,1.5,1.5);
        glutWireTeapot(1);
    glPopMatrix();
    glFlush(); //sends all pending information directly to the GPU

I know that it is taking the current modelview matrix and saving it in the stack of 32 matricies, and pop loads back the pushed matrix to be the current matrix.

But,lets say i had that tea pot, and the current model view matrix was translated(M). Then i pushed the matrix and then i scaled the matrix by 1.5 and drew my tea pot(S).

so my coordinates for the teapot are ©: one coordinate could be(1,2,3,1)
So my current matrix is right now is (MS)
So my teapot has been mapped to this matrix…MSc so the coordinate is now (2,4,6,1)

But then i pop and restore back to my old matrix…(M)
what happens to the coordinate? Why does it not pop back as well… :confused:

Or does it just take the current matrix
then save it into memory when i call glPush()
then does everything i want to do to the matrix, like glTranslatef(), or glRotatef()?
then when i gall glPopMatrix, it will multiply by the inverses of the matrices that glTranslatef(), or glRotatef() created and keep all of my coordinates the same?

Okay, the real question is! how does OpenGL restore matrices, and how does OpenGL find the new coordinate, in the ‘world plane’, for the coordinate that was within glPush and glPop? :smiley:

so my coordinates for the teapot are (c): one coordinate could be(1,2,3,1)
So my current matrix is right now is (MS)
So my teapot has been mapped to this matrix…MSc so the coordinate is now (2,4,6,1)

But then i pop and restore back to my old matrix…(M)
what happens to the coordinate? Why does it not pop back as well…

Your “coordinates” are vertex positions that are given with rendering calls. Like what happens in the glutWireTeapot function. They are only affected by the current state at the time of rendering; they cannot be affected by any changes you make after rendering.

When are vectors multiplied by the current modelview matrix?

When are vectors multiplied by the current modelview matrix?

When you call a rendering function.

what are rendering functions?
Could I please have some examples?

what are rendering functions?

All OpenGL functions can be placed within one of the following categories:

1: Functions that change the current state of the OpenGL context. This includes binding or unbinding objects, as well as those matrix functions.

2: Functions that retrieve the current state of the OpenGL context. These function always start with “glGet”.

3: Functions that change or retrieve the state of OpenGL objects independent of the state of the current context.

4: Functions that use the current state of the OpenGL context to cause rendering to happen. If you did not call one of these functions, you wouldn’t see anything.

Rendering functions include, but are not limited to, glClear, any function that begins with “glDraw”, and anything you do between glBegin and glEnd calls.

aha! i was right!
Thanks for the thorough answer! :slight_smile:

How about glPop, or glPush…are those rendering functions?