CS 381  >  Week 1 Review Problems

CS 381, Fall 2003
Week 1 Review Problems

Below are some problems related to the material covered in class recently. Answers are in the Answers section, below. Do not turn these in. We may certainly discuss any of these problems in class, if you want.

You can expect Test 1 (on Friday, October 3) to contain problems similar to some of these.

Problems

Note: On the test you will be expected to do problems like these without books or notes.
  1. Briefly describe the “synthetic camera model”.
     
  2. What is “rendering”?
     
  3. a. What does “API” stand for? b. What is an API? c. How does the specification of an API help in making software modular and portable?
     
  4. There is no C++-specific API for OpenGL. How, then, can we write C++ programs that use OpenGL?
     
  5. What is the difference between OpenGL itself (GL) and the GL Utilities (GLU)?
     
  6. OpenGL is said to be “function-call-intensive”. a. What does this mean? b. What is one advantage of the function-call-intensive approach to API design? c. What is one disadvantage of the function-call-intensive approach?
     
  7. Suppose there were an OpenGL Utilities constant whose name was the words “We like pizza”. a. What exactly would its name have to be, in order to adhere to the OpenGL naming conventions? b. What would the name need to be if it were a function instead of a constant? c. What would the name be if it were a type?
     
  8. In “glVertex3d”, what does the “3d” mean?
     
  9. List the ten glBegin-style OpenGL primitives.
     
  10. Any polygon can be sliced into triangles; thus, to draw a filled polygon, we need only know how to draw triangles. Why, then, does OpenGL have primitives for quadrilaterals and general polygons?
     
  11. Unlike some graphics systems (for example, Apple QuickDraw, Adobe PostScript) OpenGL has no curve primitives. Suppose we want to draw a curve using OpenGL. How do we do it?
     
  12. The OpenGL standard only guarantees that a polygon will be drawn correctly if it meets certain requirements. What requirements must be met?
     
  13. Most OpenGL options are handled in terms of “states”. a. What is an OpenGL state? b. Give some examples of OpenGL states.
     
  14. Some numbered points are shown below. Draw the output if these points were given, in the numbered order, to the primitives a. GL_LINES, b. GL_LINE_LOOP, c. GL_TRIANGLES.
    Points given to the primitives
     
  15. Write some C++ code that uses OpenGL to draw a green (filled) triangle with vertices (1,1), (2,3), and (0,5). (Don’t worry about declaring functions, clearing the window, setting the projection, flushing, etc.)
     
  16. In OpenGL terminology, what is the name of the buffer where the final rendered frame is stored? (Hint: It is not the “frame buffer”.)
     
  17. A certain quantity has value 2.4 when t = 0, and value 3.8 when t = 1. Using linear interpolation, approximate the value when t = 0.73.
     
  18. Suppose we are dealing with a function f. We know that f(0) = 4.1 and f(1) = 2.3. Using linear interpolation, approximate f(0.45).
     
  19. Suppose we are dealing with a function g. We know that g(2.7) = 5.5 and g(3.5) = 7.5. Using linear interpolation, approximate g(3) as closely as possible.
     
  20. A straight line passes through the points (0.9, 3.0), (2.5, 4.2), and (2.0, k). What is k?
     
  21. A certain object is to have color (0.9, 0.1, 0.1) [this is R, G, B] at position x = 0.0 and color (0.5, 0.9, 0.9) at position x = 1.0. If each component [R, G, B] of the color is linearly interpolated between these positions, then what is the color at x = 0.5?
     

Answers

  1. The synthetic camera model describes the way we generate an image of a 3-D scene. A point is chosen in 3-D space: the center of projection. The image to be generated lies in a plane. To determine where in the image an object in the scene is appears, draw a line from the object, through the center of projection, to the image. Where this line hits the image (if it does) is where the object appears.
  2. Rendering is the creation of the image to be displayed, by storing pixel colors in a frame buffer.
    1. API stands for Application Programmer’s Interface
    2. An API specifies the interface for a software library. It indicates what functions, variables, and types the library makes available, and how these behave.
    3. An API tells a programmer how to use a library without knowing the internal details. This promotes software modularity, since the implementation of the library can then be changed, as long as it conforms to the API, without breaking programs that use it. A good API specification also increases portability, since libraries on different systems can be written to conform to the same API, allowing the same application program to run on differing hardware or under a different OS.
  3. We use the C-language OpenGL API.
  4. GL refers to the core CG functionality, designed for efficient implementation in hardware. GLU is a set of utilities, always implemented in software, that runs on top of GL. GLU calls are implemented using GL calls.
    1. An API is function-call-intensive if using it generally means making many function calls. In the specific case of 3-D graphics libraries, it is often necessary to pass a great deal of information to the library. One can specify this information by in big chunks or in little chunks. OpenGL takes the latter approach. Since the chunks are small, there have to be many chunks; thus, many function calls.
    2. An advantage of the function-call-intensive approach (as opposed, say, to throwing all data into a big struct) is that new functionality can be added to the API without breaking old programs. Another is that the API becomes easier to learn: features that are not used can be ignored.
    3. A major disadvantage of the function-call-intensive approach is that, if a large amount of information needs to be passed to the library, then a great number of function calls are required, thus slowing down the program.
    1. GLU_WE_LIKE_PIZZA
    2. gluWeLikePizza
    3. GLUweLikePizza
  5. 3d” means that the function takes three parameters of type GLdouble. (It does not mean “three-dimensional”!)
  6. Here are the ten glBegin-style OpenGL primitives listed in their three major categories.
  7. OpenGL has primitives for quadrilaterals and general polygons because there are ways of drawing these (both in hardware and in software) that are more efficient than making them out of triangles. If the only filled-polygon primitives were ones that drew triangles, then an OpenGL implementation could not take advantage of these more efficient methods.
  8. We usually draw a curve in OpenGL by approximating it with a polyline consisting of many short line segments. (We could also use individual points, but this is not the usual method.)
  9. The polygon must be planar, simple, and convex. A polygon that does not meet these requirements may be drawn correctly on some systems and incorrectly on others.
    1. A state is an OpenGL parameter that can be set to a value; it then retains that value until it is changed. This value affects any drawing that subsequently occurs. Thus, a state is like a global variable used by OpenGL.
    2. Some OpenGL states that we have discussed: drawing color, clear color, current projection matrix. There are many others.
    1. GL_LINES
      Output of GL_LINES
    2. GL_LINE_LOOP
      Output of GL_LINE_LOOP
    3. GL_TRIANGLES
      Output of GL_TRIANGLES
  10. glColor3d(0.1, 0.9, 0.1);  // green
    glBegin(GL_TRIANGLES);
        glVertex2d(1., 1.);
        glVertex2d(2., 3.);
        glVertex2d(0., 5.);
    glEnd();
    Instead of GL_TRIANGLES, we could have used any of the primitives GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, or GL_POLYGON. Also, any slight variation on the color (0.1, 0.9, 0.1) would be fine.
  11. OpenGL stores the final rendered image is stored in a color buffer.
  12. (1 – 0.73) × 2.4 + 0.73 × 3.8 = 3.422.
  13. (1 – 0.45) × 4.1 + 0.45 × 2.3 = 3.29.
  14. We first find “t”: Now we use this to obtain our answer:
  15. We first find “t”: Now we use this to obtain our answer:
  16. We lirp the three components separately. Thus, the color is (0.7, 0.5, 0.5).


CS 381, Fall 2003: Week 1 Review Problems / Last update: 23 Sep 2002 / Glenn G. Chappell / ffggc@uaf.edu