I draw a polygon in a square window. When I resize the window, for example, when fully shielded, the aspect ratio is violated. From the link, I found one way to keep the aspect ratio. Here is the code:
void reshape (int width, int height) {
float cx, halfWidth = width*0.5f;
float aspect = (float)width/(float)height;
glViewport (0, 0, (GLsizei) width, (GLsizei) height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(cx-halfWidth*aspect, cx+halfWidth*aspect, bottom, top, zNear, zFar);
glMatrixMode (GL_MODELVIEW);
}
Here cx is the center of the eye space of the zNear plane in X. I ask if someone can explain how I could calculate this. I believe this should be the middle of the first two first arguments to glFrustum (). I'm right? Any help would be greatly appreciated.
source
share