glPushMatrix and glPopMatrix Intuition

Started by
13 comments, last by Septimra 13 years, 1 month ago
Now that i understand the modelview matrix, i must understand pop and push! :D
When you push and pop a matrix from the stack, what operations are done to make it happen? blink.gif

I no it does 'things to the matrix stack, takes things off and on and stuff'...but how?

W8, i no..When are coordinates multiplied by the current modelview matrix?
Is it when they are created and/or when the current modelview matrix changes?

that would mean, some coordinates are multiplied several timesby the modelview matrix!smile.gif
Am i correct?
Advertisement
You have to render something. The vertex shader process the vertices.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
could you please explain it a little more...i am really confusedblink.gif
All that stuff is described here.
You don't really need to understand pop and push, this is old and deprecated methodology. You would be much better served by forgetting these deprecated functions and learning correct shader techniques.

But if you're interested, pushing and popping don't actually 'do' anything to the matrix, its just a way to store the matrices to retrieve them later.

glPushMatrix = save this matrix for later
glPopMatrix = I'm done with my current matrix, retrieve the last matrix that I pushed.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game

You don't really need to understand pop and push, this is old and deprecated methodology. You would be much better served by forgetting these deprecated functions and learning correct shader techniques.

But if you're interested, pushing and popping don't actually 'do' anything to the matrix, its just a way to store the matrices to retrieve them later.

glPushMatrix = save this matrix for later
glPopMatrix = I'm done with my current matrix, retrieve the last matrix that I pushed.


http://www.opengl.org/wiki/FAQ#glTranslate.2C_glRotate.2C_glScale
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
[color=#1C2837][size=2]
correct shader techniques. [/quote]
[color="#1C2837"][size=2]What do you mean? How does glPush and glPop effect the shader?
[color="#1C2837"][size=2]Does it not affect the coordinates? Or does it effect both?blink.gif
[color="#1C2837"][size=2]

[color="#1C2837"][size=2]
But if you're interested, pushing and popping don't actually 'do' anything to the matrix, its just a way to store the matrices to retrieve them later.[/quote]
[color="#1C2837"][size=2]I'm srry, i meant, what does it do to the coordinates?
Pushing and popping matrices does nothing to neither vertices nor shaders. It just saves and restores the matrices so you can manipulate them and then reverting any changes made at the time you popped them.
So, lets say you had a coordinate [1,2,3,1]

loadIdentityMatrix
glpushMatrix
then you scale the matrix x 2
Vertex3f(coordinate)
//now the coordinate is [1,2,3,1] , right?
glPopMatrix
//but now the coordinate is [2,4,6,1], right?

So, im asking is that, when you Pop the matrix does it force the coordinate to be multiplied by the popped matrix, then by the current matrix?
If not, how does it work?mellow.gif
Oh, and what are render functions?blink.gif
Why don't you just read the link that haegarr gave you, it actually explains this stuff.

http://fly.cc.fer.hr/~unreal/theredbook/chapter03.html

You obviously have a very poor understanding of how this all works, and while I don't mean that as anything negative towards you, you need to do some research on your own instead of just flooding the forum with 1000 questions.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game

This topic is closed to new replies.

Advertisement