The function we register with GLUT to handle reshape events must be void and has two int parameters. GLUT passes respectively the width and height of the device window (canvas) after reshaping (resizing).

One of the important items that must be handled is resetting (reshaping) the viewport. If we do not register a reshape handler, then GLUT takes care of it by setting the viewport to the entire canvas. If we register a reshape handler, as we do in this example, then we must set the viewport(s).

We are setting the viewports in our display method. To do this, we capture the dimensions of the device window with our registered reshape handler. We store the parameters in two global variables, as seen in the code listing, to be used in our display function for setting the viewports. At least for now, this is the only purpose of our reshape functions and the width and height parameters.