Changing znear and zfar every frame

Started by
4 comments, last by ma_hty 15 years, 10 months ago
Hi, I'm using gluPerspective() for my perspective projection. I need to change the znear and zfar values every frame, so I can move closer to a certain object without any limits. However, only the znear and zfar in the first time I call gluPerspective() seem to matter. Can anyone help me (providing an alternative solution maybe)? Michel
Advertisement
For zooming in you should only need to decrease the field of view. I don't understand why you need to change the near/far planes.
Quote:Original post by biggoron
For zooming in you should only need to decrease the field of view. I don't understand why you need to change the near/far planes.


Well, I actually meant moving closer.
If I understand you correctly, you zoom in by moving the camera towards the object and you want to adjust the near and far clipping planes to avoid clipping at the near plane and depth buffer imprecision. What's wrong with changing the fov? You should get the same result with that.

Regarding your question:
When do you call gluPerspective?
Did you call glMatrixMode(GL_PROJECTION) before calling gluPerspective?
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
You want to change znear and zfar so that objects don't clipped or because you want to zoom. Because znear and zfar have no effect on zooming.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Quote:Original post by Lord_Evil
... What's wrong with changing the fov? ...


Changing fov for zooming is not a good idea. We should use gluPickMatrix for zooming instead.

This topic is closed to new replies.

Advertisement