AmandaLuther/Assignment1

Assignment 1

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

Control is passed back to the programmer using callback functions. During initialization, the programmer specifies what these callback functions are using function pointers. For example, the call to glutKeyboardFunc(keyboard) during initialization sets up the "keyboard" function as the callback for a keyboard event. Thus, if a key is pressed while the program is running, the keyboard function will be called, which allows the programmer to specify in this function what should occur when a given key is used.

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

The parameter to glutInitDisplayMode() specifies the display properties for the window. The most common window properties to specify are the type of color to use and whether or not to use double buffering. The values for the parameter are combined using the logical OR of options such as color type and buffering specifications. In my program, the parameter "GLUT_RGBA | GLUT_DOUBLE" specifies RGBA coloring and double buffering of color buffers.

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?

The call to glOrtho specifies a clipping window that goes from (0, 0) to (1, 1) in two dimensions. A viewport is rectangular area of the window on the screen, which specifies where in the actual window on screen we draw. If the window is to be resized, we might want to change this because it means that our drawing can be stretched when the window is. If instead we call gluOrtho2D(-w/size, w/size, -h/size, h/size), as I've modified the code, then the aspect ratio and size of the drawing will be fixed when the window is resized.

My program

My program draws Koch's snowflake in the middle of the window. By pressing the keys 0-9, you can alter how many iterations the snowflake has. Pressing the r, g, b, and k keys changes the color to red, green, blue, and black, respectively. Pressing the space key changes whether just an outline of the snowflake is drawn (using a line loop) or whether a filled snowflake is displayed (using triangles).

Recent