reshape

can anyone explain what does this code??


void reshape (int w,int h)
{ 
glViewPort(0,0 (GLsizei) w, (GLsizei) h);
glLoadIdentity();
gluPerspective(65.0, (GLfloat) w/ (GLfloat) h, 1.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslate(0.0, 0.0, -5.0);
}
.....
glutReshapeFunc (reshape) 

not the individuals commands, but what does the reshape function?? is it necessary for my program??

What about reading and understanding the documentation about glutReshapeFunc ?
http://www.opengl.org/documentation/specs/glut/spec3/node48.html
If you don’t need the reshape callback, no need to use it of course…

The reshape function is called once when the program first launches and everytime your window is reshaped/resized. The most important command is glViewport, which usually maps to the new size of the window.

It’s important as if you didn’t have this function, nothing would ever let your display function know when your screen size changes. If you don’t provide a reshape function, a default one is usually provided (at least in GLUT) which just changes the viewport. You can add in any of your own code that needs to be run when the window resizes but not necessary every frame render.