## ECSE-4750 Computer Graphics, Rensselaer Polytechnic Institute, Midterm Exam, Fall 2011, 13 Oct 2011 4-5:30

NAME: _____W. Randolph Franklin Solution__ EMAIL:__wrf@ecse.rpi.edu_______________________ RIN:______________

This solution set may be freely copied and distributed for nonprofit research and education, provided that: There is no charge, and credit is given to the author.

Answer every question.There are 3 pages with 20 questions, total 40 points.

For 2 questions, you may write free for your answer (and get 2 points each).

This exam is open book: you may use calculators and any paper books and notes that you brought with you. You may not use computers or communication devices, or share material with other students.

1. _____/2 Suppose that you have 1000 triangles that can be arranged into a triangle strip. How many vertices would you have to specify to OpenGL if you use the fact that they can be arranged into a triangle strip?
1002
2. _____/2 What is the event loop?
An infinite loop entered by the last executed line in your program, which waits for events such as user inputs and state changes. For any such input for which an event handler is defined, the event loop calls the event handler, which processes the event and then returns to the event loop.
3. _____/2 What OpenGL routine do you call to tell it that you wish to have a depth buffer? (I am not asking how to enable the depth buffer.)
glutInitDisplayMode
4. _____/2 Name two ways that putting all your vertices into an array and telling OpenGL about it might make a big graphics program faster.
1. fewer subroutine calls.
2. less memory.
3. the vertices might be cached in the GPU, reducing data on the graphics bus.
5. _____/2 One problem with putting all your vertices into an array is that each vertex might be a member of a variable containing other info, such as this:
Class Vert {
public:
float coords[3];
float color[4];
float normal[3];
}
Vert verts[10];

Therefore the coordinates of successive vertices are not adjacent. How can you tell OpenGL about that when using a vertex array?
By setting the stride (the 3rd argument) when calling glVertexPointer.
6. _____/2 What does glFlush do?
Flushes the graphics pipeline to force everything to be displayed now.
7. _____/2 What is it about how display lists are constructed that prevents you from creating an infinite loop, where list 3 might call list 4 and list 4 calls list 3?
A display list can call only another display list that was defined earlier.
8. _____/2 You can have the same callback routine for more than one menu. When that routine is called, how can it know which menu item in which menu was clicked on?
You can specify anything you want for the 2nd entry of glutAddMenuEntry, and it is passed to the menu callback. Thus, the menu callback knows which menu entry was clicked.
9. _____/2 What does this do: glMatrixMode(GL_MODELVIEW);
Future matrix modifications, such as glTranslate, will be applied to the modelview matrix, until glMatrixMode is called again.
10. ____/2 Since routine specified in glutDisplayFunc takes no arguments, how do you get data from other routines to it?
Use a global variable.
11. ____/2 What's the normal to the plane x+2y+3z=4? Your answer should be normalized.
{$$\left( \frac{1}{\sqrt{14}}, \frac{2}{\sqrt{14}}, \frac{3}{\sqrt{14}} \right)$$}
12. ____/2 When are glPushMatrix() and glPopMatrix() useful?
To isolate a transformation to one part of the object, and to allow nested transformations and objects.
13. ____/2 One property of a well designed font is that different characters may have different widths. E.g., m is wider than i. This could be a problem when writing a character string in OpenGL since you'd have to know the width of each character and advance the raster position the correct amount after drawing each character. However OpenGL makes things easy for you. How?
OpenGl advances the raster pointer by the width of each character as it is drawn.
14. ____/2 What would look different in the resulting image if you changed the 1.0 to -1.0 in the following line?
gluLookAt(camera.getZoomDistance() * sin(camera.getViewDirection()*PI/180.0), 0.0, camera.getZoomDistance() * cos(camera.getViewDirection()*PI/180.0), 0.0, 0.0, 0.0, 0.0, 1.0 , 0.0);
The image would appear upside down since the up vector was inverted.
15. ____/2 Consider this sequence of calls:
glColor3f(1.,1.,1.);
glColor3f(0.,1.,0.);\
glVertex3f(1.,1.,1.);
glVertex3f(2.,2.,2.);

1. What color is the vertex (1,1,1)?
green
2. What color is the vertex (2,2,2)?
green
16. ____/2 Give the 4x4 matrix for a 90 degree rotation about the X axis followed by a translation by (1,2,3).
{$$\left(\begin{array}{cccc} 1 & 0 & 0 & 1 \\ 0 & 0 & -1 & 2 \\ 0 & 1 & 0 & 3 \\ 0 & 0 & 0 & 1 \end{array}\right)$$}
17. ____/2 To deal with multiple functions for a similar purpose, C++ and OpenGL take different approaches: C++ uses overloading while OpenGL defined a number of functions which differ from each other in the last letter, for example, glVertex3f, glVertex2i, glVertex3dv all create a vertex but take different data types as input. What is an advantage of each approach?
Overloading makes the code cleaner if you consider that the suffixes don't add any information but just clutter things up. That's the point of abstraction - hiding irrelevant details. However some people find that the explicit data type in the suffix helps them to debug the code. They might not like the compiler to do too many things automatically since the compiler might get things wrong. Also, C++ compilers are not as interchangeable as C compilers. (Other answers are possible.)
18. ____/2 What's the 2 word name for the technique for storing the graphic objects in the GPU (if there's space) so that they does not have to be repeatedly sent down the network each time the window is redisplayed?
display list
19. ____/2 If you call glutCreateWindow a second time in the program, which one of the following happens?
1. a new window replaces the old one
2. a new window is created, and the old one still remains
3. nothing happens
4. an error message is printed and the program exits
5. the computer executes the HCF (halt and catch fire) machine instruction.

20. ____/2 Here's how picking might have been implemented: When you pick an object, the line number of the glBegin call to draw the closest object covering that pixel might be returned by the pick routine.
Why would this idea be inadequate?
That line may have been executed many times in a loop to generate different instances of primitive objects, and you might want to know which instance was picked.

end of exam