CS 381  >  Test 1 Solutions

CS 381, Fall 2003
Test 1 Solutions

Problem 1 [1 pt]

In “glColor3d”, what does the “3d” mean?

Answer

3d” means that the function takes 3 parameters of type GLdouble (not double!).

Problem 2 [5 pts total]

States.

2a [3 pts]

What is an OpenGL “state”?

Answer

OpenGL keeps track of a large number of drawing attributes that an application can set and query using OpenGL commands. These are called OpenGL states; they function much like global variables whose value is maintained by OpenGL. Changing a state produces no output; rather, it affects drawing that occurs after the state change is made.

2b [2 pts]

Give two examples of OpenGL states.

Answer

Here are some OpenGL states you definitely should know about: Here are some others we have run across briefly: Any two of the above (along with lots of others) would be correct.

OpenGL does not handle input. Thus, such things as mouse-button state and mouse position are not OpenGL states. Double buffering is also not an OpenGL state; double buffering is a procedure that is followed: draw in the back buffer, then swap front and back.

Problem 3 [3 pts total]

2 1/2-D.

3a [2 pts]

In the context of CG, what does “2 1/2-dimensional” mean?

Answer

An interface is 2 1/2-dimensional if objects can have front-back a relationship, but there is no actual depth (z-coordinate).

3b [1 pt]

What is the quintessential example of a 2 1/2-dimensional interface?

Answer

The quintessential 2 1/2-D interface is one involving overlapping windows.

Problem 4 [3 pts]

Briefly explain how to draw a curve in OpenGL.

Answer

OpenGL has no curve primitives. We approximate a curve in OpenGL by using a polyline with closely spaced vertices. Closer vertices make a smoother curve, but also slower rendering.


Problem 5 [3 pts]

What is an “event”? Give an example of a kind of event.

Answer

An event is something that happens external to a program that needs processing by the program. Examples are input events (keypress, mouse button press or release, mouse movement) or windowing-related events (redisplay needed, window resize, window status change).

Problem 6 [4 pts total]

Writing Code. In each part, write some C++ code that uses OpenGL to perform the required operation. I am not asking for a program, or even a function. A few lines of code (or maybe only one line?) should suffice.

6a [2 pts]

Draw a square with vertices (0,0), (1,0), (1,1), (0,1).

Answer

glBegin(GL_QUADS);
   glVertex2d(0., 0.);
   glVertex2d(1., 0.);
   glVertex2d(1., 1.);
   glVertex2d(0., 1.);
glEnd();
The above draws a filled square. So would GL_TRIANGLE_FAN or GL_POLYGON. You could also use GL_TRIANGLE_STRIP or GL_QUAD_STRIP, but the vertices would need to be given in a different order. To draw an outlined square, use GL_LINE_LOOP.

6b [2 pts]

Send any buffered OpenGL commands to the graphics server/hardware and wait for them to be completed.

Answer

glFinish();
The command glFlush sends commands to the server, but does not wait for them to be completed. The GLUT function glutSwapBuffers calls glFlush (not glFinish!) before swapping.


Problem 7 [8 pts total]

Primitives.

7a [3 pts]

In general (i.e., not necessarily in OpenGL), what is a “graphics primitive”?

Answer

Graphics libraries draw objects by making them out of simple graphical pieces. The simplest pieces, out of which all complex objects are constructed, are called graphics primitives. These may include points, lines, filled regions, curves, various types of surfaces, raster images, and text.

OpenGL primitives include points, lines, filled polygons, bitmaps, and general raster images.

7b [3 pts]

List all of the glBegin-style OpenGL primitives.

Answer

  1. GL_POINTS
  2. GL_LINES
  3. GL_LINE_STRIP
  4. GL_LINE_LOOP
  5. GL_TRIANGLES
  6. GL_TRIANGLE_STRIP
  7. GL_TRIANGLE_FAN
  8. GL_QUADS
  9. GL_QUAD_STRIP
  10. GL_POLYGON

7c [1 pt]

Some numbered points are shown below. Draw the output if these points were given, in the numbered order, to the primitive GL_LINES.

Additional instructions given at time of test: In your answer, distinguish between filled/unfilled by shading the interior of filled polygons.

Answer

GL_LINES Image

7d [1 pt]

Same question as in part c, except that the primitive is now GL_TRIANGLES.

Additional instructions given at time of test: In your answer, distinguish between filled/unfilled by shading the interior of filled polygons.

Answer

GL_TRIANGLES Image


Problem 8 [3 pts]

By default, OpenGL lirps colors along line segments. Suppose that a certain line segment has color (0, 1, 1) at one endpoint, where x = 0, and color (1, 0, 0.5) at the other endpoint, where x = 1. If the default OpenGL behavior occurs, determine the color at the point on the line segment at which x = 0.3. Note: Full credit will be given for a correct answer, but it is very difficult to give partial credit unless work is shown.

Answer

We are given values at 0 and 1, so we can do the simple form of lirping (we do not need to compute “t”).

We handle the three components (R, G, B) by lirping each one separately:

Thus, (R, G, B) = (0.3, 0.7, 0.85).

Problem 9 [5 pts total]

Kinds of Graphical Text Fonts.

9a [2 pts]

List the two main kinds of text fonts that are used in CG. Hint: I am not talking about particular formats here.

Answer

  1. Bitmap/raster fonts
  2. Outline/stroke fonts

9b [3 pts]

Give one advantage of each kind over the other.

Answer

Here are a couple of advantages for each. You only needed to give one from each of the lists below.

Bitmap/raster fonts are better than outline/stroke fonts because:

Outline/stroke fonts are better than bitmap/raster fonts because:


Problem 10 [3 pts]

Briefly describe the “synthetic camera model”.

Answer

The synthetic camera model describes how to generate a 2-D image of a 3-D scene, similarly to the way most cameras work. A special point in the 3-D scene is chosen: the center of projection. The image to be generated is considered to lie in a plane somewhere in the scene. To map a given point in the scene to the image, draw a straight line through this point and the center of projection. If this line hits the image, then where it hits is where the given point appears in the image.

Problem 11 [6 pts total]

Picking Methods.

11a [3 pts]

Briefly describe the extent-testing method of picking. Hint: The “obvious” method.

Answer

In extent testing, we determine which object was selected by a pointing device (e.g., a mouse) by iterating through the objects in the scene, generally in front-to-back order. For each object, we test whether the mouse position lies in its extent. The first object for which the test succeeds (if any) is the object picked.

11b [3 pts]

Briefly describe one of the other picking methods we have discussed.

Answer

We discussed two methods. You only needed to describe one. They are:
Buffer Reading
Draw each object in the scene in a different, solid color. Read the color of the pixel at the mouse position to determine which object was picked. If possible, do all this off-screen to avoid annoying the user.
Selection Mode
Set the clipping region to a small (single pixel?) region around the mouse position. Give each object in the scene a “name”, and send this name through the pipeline with the primitives making up the object. Get a list of the names of objects that were rendered (i.e., were not discarded by the clipping operation). These are the objects at the mouse position; the closest one is the one picked.


Problem 12 [2 pts]

What is one way that a (presumed) client-server relationship influenced the design of OpenGL?

Answer

OpenGL presumes a client-server relationship between the application and the rendering hardware/software. OpenGL was designed to allow the application to manage the client-server information flow in an efficient manner. In particular: You only needed to mention one of the above.

Problem 13 [4 pts total]

Conceptual Errors. Below are some C++/OpenGL code fragments. Each contains a serious conceptual error. In each part, explain what the error is.

13a [2 pts]

Assume that my_list is an int that holds a valid OpenGL call-list name.
glNewList(my_list, GL_COMPILE);
   for (int i=1; i<=10; ++i)
      cout << "i = " << i << endl;
glEndList();  // 1-10 in a display list

Answer

Display lists only hold OpenGL commands, not arbitrary C++ code. The above code creates an empty display list, as well as doing some printing while the display list is being created.

13b [2 pts]

Assume we are in the display function.
// Draw a blue point at (0, 0)
glBegin(GL_POINTS);
   glVertex2d(0., 0.);  // The point
glEnd();
glColor3d(0., 0., 1.);  // Make the color blue
glFlush();              // And go draw it!

Answer

OpenGL states only affect drawing that occurs after the state is set. Thus, in order to make the point blue, the glColor* command must be executed before the glVertex* command.


CS 381, Fall 2003: Test 1 Solutions / Last update: 6 Oct 2003 / Glenn G. Chappell / ffggc@uaf.edu