Archived

This topic is now archived and is closed to further replies.

how do you use glPushMatrix() and glPopMatrix efficiently

This topic is 6357 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

basically it boils down to this the official opengl programming book sorta said something about them being faster and then went on. exactly when should these things be used over glLoadIdentity take for example modelview and projection viewport all the necessary stuff is set up for your standard 3d rendering you render your crap then you need to write the text like your score and whatever trying to to use the 3d modelview and projection with text would be a nightmare in my view so a simple way would be to change the matrixes to ortho temporaryily now would this be an example of when to use pop and push take the pseudo code below it seems to me that for text it would probably be better to use loadidentity init() { glViewport(0,0,...) glMatrixMode(persp) // yes i know i''m lazy with the argument glFrustum(yah right too long) glMatrixMode(modeview) } frame() { //whatever rotate trans scale //render 3d stuff glMatrixMode(persp) glPushMatrix() glOrtho(too long) glMatrixMode(modeview) glPushMatrix() //render 2d text glPopMatrix() glMatrixMode(presp) glPopMatrix() glMatrixMode(modeview) // or instead, which one? glMatrixMode(persp) glLoadIdentity() glOrtho() glMatrixMode(modeview) glLoadIdentity() //2d render

Share this post


Link to post
Share on other sites
glLoadIdentity is quick i think u meant glLoadMatrix

i go like this

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(cameraPERSPECTIVE, 1/1, 10, 1000
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// draw 3d stuff

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,SCREENWIDTH,0,SCREENHEIGHT,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// draw 2d stuff

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Use glPushMatrix/glPopMatrix whenever you need to change a matrix only temporariuly and then restore it to its original state.

It''s especially useful if you are doing hierarchical models.

Beware though that the matrix-stack is not unlimited, if I remember correctly 32 entries is the minimum an implementation must support, but more than this is up to the implementation.

Share this post


Link to post
Share on other sites