The viewport transformation
corresponds to the stage where the size of the developed photograph is
chosen.
The viewport is the rectangular region of the window where
the image is drawn.
The viewport is measured in window coordinates, which reflect the
position of pixels on the screen relative to the lower-left corner of the
window.
Keep in mind that all vertices have been transformed by the modelview and projection matrices by this point, and vertices outside the viewing volume have been clipped.
By default the viewport is set to the entire pixel rectangle of the window that is opened. You use the glViewport() command to choose a smaller drawing region; for example, you can subdivide the window to create a split-screen effect for multiple views in the same window.
void glViewport( GLint x, GLint y,
GLsizei width, GLsizei height );
It defines a
pixel rectangle in the window into which the final image is mapped. The (x, y)
parameter specifies the lower-left corner of the viewport, and width and height
are the size of the viewport rectangle. By default, the initial viewport values
are (0, 0, winWidth, winHeight), where winWidth and winHeight are the size of
the window.
The aspect ratio of a viewport should generally equal the aspect ratio of the viewing volume. If the two ratios are different, the projected image will be distorted when mapped to the viewport.
Viewport command needs to be called within myReshape() - if the window changes size, the viewport needs to change accordingly.