Question

Im using glScalef() for zooming in my program, now when i revert it back to the original size with code:

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

It doesnt work very well in high zooms... (maybe because of the lost decimals?)

How i can revert it back perfectly to the original size without any calculations like above?

Was it helpful?

Solution

You could either do it like this:

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 before zooming:

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

OTHER TIPS

You can simply save your projection matrix. glPushMatrix(), glScalef(), ..., glPopMatrix()

Use glPushMatrix() before your first glScalef() to push the current model matrix onto the stack, and then glPopMatrix() when you want to get back the original scale, that way there won't be any rounding errors as there are no calculations being done.

Store the previous size somewhere, say in a stack, and use that.

(animating the transition back to a previous zoom, pan and rotate setting is quite fun rather than zooming)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top