Sign in to follow this  

reset the viewing volume

Recommended Posts

Wizumwalt_    122
Is it good practice to use glOrtho from my display() method rather than my redisplay() because my problem is that I don't know the size of the model till it's loaded. I've been working w/ a model I already know the size of. It works like this. 1. Empty canvas initializes (redisplay() sets size of new window frame and viewing volume). 2. User loads a model. 3. I calculate the size of the model (i.e. min/max x, y, z, centroid, etc...) 4. Now I need to reset glOrtho's viewing volume according to model and not the one I just used to initialize my canvas w/ in the redisplay method. What method is that done with, or is it ok to call glOrtho again?

Share this post

Link to post
Share on other sites
Dim_Yimma_H    557
glOrtho creates a transformation matrix used for orthogonal projection and multiplies it with the current transformation matrix (typically the projection matrix). When calling glOrtho again it creates a new matrix and multiplies it with the current matrix once again. Thus it stores two glOrtho-transformations. If you want to reset the current transformation matrix so it has only your new transformation you could call glLoadIdentity before glOrtho to reset the current matrix (load it with the identity matrix) and because of that also resetting the viewing volume.

glMatrixMode(GL_PROJECTION); //apply subsequent matrix multiplications to the current projection matrix
glLoadIdentity(); //reset it to a identity matrix - no transformation
glOrtho(/*new values...*/); //a new view volume is set

If the old matrix is important one can also save it with glPushMatrix() and later get it back with glPopMatrix().

\Jimmy H

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this