title: OpenGL - how to fit a window on resize
body: <p>I have a shape that is centered on the window screen. For now on window resize it remains the same (same width and height).
  What is the best way to fit it to the window on resize, and also keep it's aspect ratio?</p>
  
  <pre><code>const int WIDTH = 490;
  const int HEIGHT = 600;
  
  /**
  * render scene
  */
  void renderScene(void)
  {
      //clear all data on scene
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
      //set white bg color
      glClearColor(1, 1, 1, 1);
  
      glColor3ub(153, 153, 255);
      glBegin(GL_POLYGON);
          glVertex2f(60, 310);
          glVertex2f(245, 50);
          glVertex2f(430, 310);
          glVertex2f(245, 530);
      glEnd();
  
      glutSwapBuffers();
  }
  
  /**
  * reshape scene
  */
  void reshapeScene(GLint width, GLint height)
  {
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
  
      glViewport(0, 0, width, height);
      gluOrtho2D(0, width, height, 0);
      glMatrixMode(GL_MODELVIEW);
  
      glutPostRedisplay();
  }
  
  /**
  * entry point
  */
  int main(int argc, char **argv)
  {
      //set window properties
      glutInit(&amp;argc, argv);  
  
      glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
      glutInitWindowSize(WIDTH, HEIGHT);
      glutInitWindowPosition((glutGet(GLUT_SCREEN_WIDTH)-WIDTH)/2, (glutGet(GLUT_SCREEN_HEIGHT)-HEIGHT)/2);
      glutCreateWindow("Test Window");
  
      //paste opengl version in console
      printf((const char*)glGetString(GL_VERSION));
  
      //register callbacks
      glutDisplayFunc(renderScene);
      glutReshapeFunc(reshapeScene);
  
      //start animation
      glutMainLoop();
  
      return 0;
  }
  </code></pre>
  
  <p>Thanks</p>