Edward Suh Assignment 1 Questions
1. In a GLUT program, how is control passed back to the programmer? How is this set up during initialization?
In a GLUT program, callback functions are used to pass control back to the programmer. During initialization, the glutDisplayFunc() is passed a function pointer that is called whenever the contents of the window need to be redisplayed. There are other examples of GLUT routines that take callback functions, including glutReshapeFunc(), which is responsible for resizing the window, glutKeyboardFunc() and glutMouseFunc(), which are responsible for managing keyboard and mouse inputs, respectively, and glutMotionFunc(), which is invoked when the mouse is dragged.
2. What does the parameter to glutInitDisplayMode() in main() specify?
glutInitDisplayMode() takes an unsigned int as a parameter, which can specify a variety of configurations. First, the parameter specifies whether to use an RGBA or color-index color model. The parameter can also specify whether to use a single or double-buffered window. Finally, it can indicate for the window to have an associated depth, stencil, multisampling, and/or accumulation buffer. These various configurations are passed via GLUT state variables separated by bitwise OR operators. For example, calling glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) initializes a window with double buffering, the RGBA color model, and a depth buffer.
3. What do the calls to glOrtho() and glViewport() in the reshape() function accomplish? If the window is to be resized, why might we want to change this?
glViewport() specifies what part of the window to render to. It takes four arguments. The first two GLint's specify the coordinates of the lower left corner of the viewport. The next two GLsizei's specify the width and height of the viewport. glOrtho() sets the coordinate system of the image that is drawn on the screen by calculating a projection matrix. The function takes six GLdouble's as parameters. The first two specify the coordinates of the left and right edges of the rendering, respectively. The next two specify the bottom and top edges, respectively. The last two specify a range of Z-coordinates, which are used for depth-sorting. They are labelled 'near' and 'far', to correspond to the positive and negative Z-axes in Cartesian coordinates.
If a window is resized, the coordinate system may have to change to accomodate the new size of the window. The width and height parameters that are passed to glViewport(), for example, will have to change according to the new size of the window.