another question i ahve is regarding the glPopMatrix and glPushMatrix…when exactly do i use these matrices…is there a rule to follow?
i understand they are used to save the state of the current matrix…but i am still sorta confused how to go about using them in coding…should i use it before i rotate a matrix, only?
You use glPushMatrix and glPopMatrix around a block of drawing code in which you temporarily want to do some additional translates/rotates/scales or whatever and then later want to undo these actions without having to keep exact track of what you did.
For example: when positioning the limbs of a character you would
- glTranslate/glRotate to the location of the body
- glPushMatrix
- glTranslate/glRotate to the left limb
- draw the left limb
- glPopMatrix
- glPushMatrix
- glTranslate/glRotate to the right limb
- draw the right limb
- glPopMatrix
etc.
Do keep a close look on the number of Push and Pops you do, they absolutely have to be balanced at all times!
HTH
Jean-Marc.