View Full Version : maintaining perspective when window resized

11-02-2000, 09:35 AM
I am drawing an opengl object into a display window that can be resized. When the user resizes the window it messes up the perspective since the window may no longer be square. I was wondering what is the correct way to handle this problem. If I center the viewport and make sure it is square then there will be areas outside the viewport but still considered the display window that the model will not be able to get panned into.
Is my only option to always make sure that when a user resizes the window that it maintains a square perspective?

Thanks in advance,


11-02-2000, 10:32 AM
This is how I do it. It seems to work well for me.

//Change the window size
void ChangeSize(GLsizei w, GLsizei h) {
//Prevent divide by zero
if (h==0) { h = 1;}

//Affects camera

//Set viewport

//Feild of view, ratio, start distance, end distance
gluPerspective(45, w / h, 1, 1000);
//Affects models

11-02-2000, 10:43 AM
better also watch out for the case where the window is higher than it is wide
eg w/h | | h/w