How to return glScalef ()?

Im using glScalef () to scale my program, now that I get it back to its original size with code:

glScalef(1.0f/ZOOM, 1.0f/ZOOM, 1);

It doesn't work very well at high scales ... (maybe due to lost decimal places?)

How can I completely return it back to its original size without any calculations, e.g. above?

+5
source share
4 answers

You can do it as follows:

ZOOMSQRT = sqrt(ZOOM);
glScalef(1.0f/ZOOMSQRT, 1.0f/ZOOMSQRT, 1);
glScalef(1.0f/ZOOMSQRT, 1.0f/ZOOMSQRT, 1);

or use glPushMatrix / glPopMatrix to restore the original matrix to scale:

glPushMatrix();
glScalef(ZOOM, ZOOM, 1);
[do whatever you like here...]
glPopMatrix(); // now it at normal scale again
[do other things here...]
+8
source

You can just save the projection matrix. glPushMatrix (), glScalef (), ..., glPopMatrix ()

+5
source

Use glPushMatrix () before the first glScalef () to push the current model matrix onto the stack, and then glPopMatrix () when you want to return the original scale, so there will be no rounding errors, since no calculations are done there.

+4
source

Store the previous size somewhere, say on the stack, and use it.

(animating the transition to the previous zoom, setting the pan and rotation is pretty funny, not zooming)

+2
source

All Articles