You are not allowed to edit this page.


Paolo Bezoari CS148 Assignment 1

1. In a GLUT program, how is control passed back to the programmer? How is this set up during initialization?

In a GLUT program, control is passed back to the programmer using callback functions that we specify for certain events. For example, we use the glutKeyboardFunc() function to set the function to call when a keyboard press is detected and we use the glutReshapeFunc() function to set the function to call when the display is resized.

2. What does the parameter to glutInitDisplayMode() in main() specify?

GLUT_RGBA sets the window mode to RGBA (red-green-blue-alpha) and GLUT_DOUBLE enables double buffering of the window. By OR-ing these 2 parameters, we enable them both.

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?

glOrtho() performs an orthographic projection of the space, thereby flattening it. The different parameters to glOrtho() specify the location of the projection plane in space. glViewport() specifies the area of the window where we should draw. If the window is resized, we might want to change the parameters to glOrtho() and glViewport() so that the aspect ratio of the scene stays the same for example. We can modify the parameters to these functions to do the opposite too: when the window is resized, the scene doesn't change scale.

4. Write up and submit your program. Your write up should contain both the answers to the questions and any notes we should know about running your program.

My program draws a rectangle using GL_LINES and a triangle using GL_TRIANGLES. By using the w/a/s/d keys, the user can move the triangle up/left/down/right in the scene. I have also set some boundaries so that you cannot move the triangle completely out of the rectangle.