title: Understanding opengl's (glut) resize
body: <p>I'm reading the sample code for the bezier curve on the online version of opengl's tutorial. </p>
  
  <p>I'm curious about how is resize being handled in the example cause I figure I might use it on my own version of this program , I placed my questions on its comments:</p>
  
  <pre><code>void reshape(int w, int h)
  
  {
     glViewport(0, 0, (GLsizei) w, (GLsizei) h); // what's GLsizei? Why is it called inside glViewPort?
     glMatrixMode(GL_PROJECTION); // is it necessary to reset the projection matrix?
     glLoadIdentity();
     if (w &lt;= h)  // is this calculation universal, could I use it on another program? 
        glOrtho(-5.0, 5.0, -5.0*(GLfloat)h/(GLfloat)w, 
                 5.0*(GLfloat)h/(GLfloat)w, -5.0, 5.0);
  
     else
        glOrtho(-5.0*(GLfloat)w/(GLfloat)h, 
                 5.0*(GLfloat)w/(GLfloat)h, -5.0, 5.0, -5.0, 5.0);
     glMatrixMode(GL_MODELVIEW); // why do I set to GL_MODELVIEW at the end?
     glLoadIdentity(); // why does it get a reset?
  }
  </code></pre>
  
  <p>Full code:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;GL/glut.h&gt;
  
  GLfloat ctrlpoints[4][3] = {
      { -4.0, -4.0, 0.0}, { -2.0, 4.0, 0.0}, 
      {2.0, -4.0, 0.0}, {4.0, 4.0, 0.0}};
  
  
  void init(void)
  {
     glClearColor(0.0, 0.0, 0.0, 0.0);
     glShadeModel(GL_FLAT);
     glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &amp;ctrlpoints[0][0]);
     glEnable(GL_MAP1_VERTEX_3);
  }
  
  void display(void)
  
  {
     int i;
  
     glClear(GL_COLOR_BUFFER_BIT);
     glColor3f(1.0, 1.0, 1.0);
     glBegin(GL_LINE_STRIP);
        for (i = 0; i &lt;= 30; i++) 
           glEvalCoord1f((GLfloat) i/30.0);
     glEnd();
     /* The following code displays the control points as dots. */
  
     glPointSize(5.0);
     glColor3f(1.0, 1.0, 0.0);
     glBegin(GL_POINTS);
        for (i = 0; i &lt; 4; i++) 
           glVertex3fv(&amp;ctrlpoints[i][0]);
     glEnd();
     glFlush();
  
  }
  
  void reshape(int w, int h)
  
  {
     glViewport(0, 0, (GLsizei) w, (GLsizei) h); // what's GLsizei? Why is it called inside glViewPort?
     glMatrixMode(GL_PROJECTION); // is it necessary to reset the projection matrix?
     glLoadIdentity();
     if (w &lt;= h)  // is this calculation universal, could I use it on another program? 
        glOrtho(-5.0, 5.0, -5.0*(GLfloat)h/(GLfloat)w, 
                 5.0*(GLfloat)h/(GLfloat)w, -5.0, 5.0);
  
     else
        glOrtho(-5.0*(GLfloat)w/(GLfloat)h, 
                 5.0*(GLfloat)w/(GLfloat)h, -5.0, 5.0, -5.0, 5.0);
     glMatrixMode(GL_MODELVIEW); // why do I set to GL_MODELVIEW at the end?
     glLoadIdentity(); // why does it get a reset?
  }
  
  void keyboard(unsigned char key, int x, int y)
  
  {
     switch (key) {
        case 27:
           exit(0);
           break;
     }
  }
  
  int main(int argc, char** argv)
  {
     glutInit(&amp;argc, argv);
     glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
  
     glutInitWindowSize (500, 500);
     glutInitWindowPosition (100, 100);
     glutCreateWindow (argv[0]);
     init ();
     glutDisplayFunc(display);
     glutReshapeFunc(reshape); // el reshape funciona correctamente 
     glutKeyboardFunc (keyboard);
  
     glutMainLoop();
     return 0;
  }
  </code></pre>