title: OpenGL - maintaining aspect ratio upon window resize
body: <p>I am drawing a polygon in a square window. When I resize the window, for instance by fullscreening, the aspect ratio is disturbed. From a reference I found one way of preserving the aspect ratio. Here is the code:</p>
  
  <pre><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);
  }
  </code></pre>
  
  <p>Here, cx is the eye space center of the zNear plane in X. I request if someone could please explain how could I calculate this. I believe this should be the average of the initial first two arguments to glFrustum(). Am I right? Any help will be greatly appreciated.</p>