Matrix stack operations

Hi all,

When a vertex is drawn is it multiplied with only the top matrix in the matrix stack (e.g MODELVIEW) or all of them? Or am I completely on the wrong track?

For example, If my stack had these 3 transformations on it:

  1. Identity
  2. Translate to a point somewhere (camera)
  3. Translate slightly to another point (object offset)

And then I rendered my object, would every vector be adjusted by all transformations on the stack?

Thanks in advance,

yes the vector will b transformed by all the transformation in the stack.

Is there some way I can mark this post as being answered?

To be more precise, the vertices are only transformed by current matrices, which are the Top Of Stack matrices:
v’ = ProjectionTOS * ModelviewTOS * v;

If you generated this with something like

then the top of stack is the concatenation of the two translations, so it’s transformed by both translations.
Though this is not the case if you add a glLoadIdentity() or glLoadMatrix() in between.

oh, right. Because ‘push’ operations make a copy of the last matrix on the stack, and any subsequent operations on the top of the stack will concatenate with that copy…

That makes a lot of sense now.

Thanks very much

Note that the above code is academic and does the same if no glPushMatrix would have been used.
The interesting part could follow after “…” when you use glPopMatrix and glPushMatrix again to build transformations hierarchies.

Yes, but using pushMatrix means you can easily revert to a previous transformation just by popping the stack, doesnt it? I woild say this is very handy.