CS148 Assignment 1

Greg Goldgof

Due: January 18, 2007

Assignment One Answers

Read up on OpenGL and GLUT and answer the following questions. Be sure you can answer all these questions before moving on.

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

Control is passed to the programmer via function pointers. The glut functions

  • glutDisplayFunc( display ); glutReshapeFunc( reshape ); glutKeyboardFunc( keyboard ); glutTimerFunc(16.0f, tick, 0);

and others take function pointers as parameters during initialization. These functions are provided by the programmer, so that he/she can control what is displayed, how reshaping works, how the program responds to keyboard input, how it updates, et cetera.

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

The first parameter GLUT_RGBA specifies that we want out window to have color.

The second parameter GLUT_DOUBLE specifies that we want to use double buffering rather than single buffering, which is the default.

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() changes the coordinate reference frame. If you comment out the line from the starter code than (0, 0) becomes the center (by default) rather than the bottom left-hand corner.

glViewPort() controls scaling. Commenting out the line from the starter code makes it so that shapes created do not resize with the window. The paramaters (0, 0, w, h) keep the shapes proportional to the window size (width and height).

Program Operation

Notes on program: Press “space” to get the squares to change direction. Press ‘f’ to toggle double-time (fast). Press ‘t’ to make the triangle appear or disappear. Press ‘c’ for a color change. Press ‘p’ for psychedelic mode. Press “escape” to exit.

To change the starting positions of the polygons and therefore the relationship between their rotations use the following keys. Press ‘r’ to reset back to original positions.

‘w’ = up

‘s’ = down

‘d’ = right

‘a’ = left