One of the two subwindows we use in this example is for displaying the graphical content. The responsibility for creating and displaying the content is built into the class CGWorld. In turn, we make a call to the class method that creates the subwindow (see createSubWindow in CGWorld.cpp). One of the parameters passed to the method is the main window handle. It is used in createSubWindow to identify the main window as the location of the subwindow.
We also pass the dimensions of the main window, namely those values stored in mainWindowWidth and mainWindowHeight. Our design in setting the location and dimensions of the subwindow involve the use of percentages of the main window dimensions versus fixed values. The first two parameters of the four (2 and 2 in this example) specify the location of the upper-left corner of the subwindow within the main window and are given as percentages of the width and height of the main window, respectively. The next two (60 and 96 in this example) specify the width and height of the subwindow as percentages of the main window's width and height, respectively. The use of percentages handles resizing the subwindow when a user resizes the main window (see the discussion on the main window's reshape function).
Last, we register a display function for the subwindow and call the class's init method, passing in the latter case the background (clear) color we want for that subwindow. Although the display function is one that is invoked when the subwindow's display area needs to be updated, it is not the actual function that creates the graphical content. When you look at the code for our registered display function, you see that it simply calls the class's display function. We need to use this indirect reference since the actual display function is imbedded in the memory allocated to the class. In turn, the function's address is not directly visible from the main function and, therefore, cannot be direclty referenced as required by GLUT.