CS 381  >  Test 1 Information & Week 3 Review Problems

CS 381, Fall 2003
Test 1 Information & Week 3 Review Problems

Test 1 Information

Test 1 will be given in class on Friday, October 3. It will take up the entire class meeting. The test will be worth 50 points and will cover all the course material from the beginning of the course up to Test 1 (weeks 0 through 4).

Referring to books, notes, or other students during the test will not be permitted.

The assignments, being oriented primarily toward programming, should not be considered a complete preparation for the test. Readings and review problems have been posted each week, as have lecture slides. You can expect the test to contain problems similar to the various review problems. Here are links to the other review-problem sets:

Week 3 review problems are given below. 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.

Problems

  1. a. What is a “display list”? b. What other term means the same thing?
     
  2. a. What is a display-list “name”? b. Why is it better to have display lists referred to by name than to store the data ourselves into the structure? (Wouldn’t it be nice to be able to get at the data structure?)
     
  3. Your are writing an OpenGL/GLUT program with the following code in the display function (draw_pt_flag is a global bool):
    if (draw_pt_flag)
    {
       glBegin(GL_POINTS);  // draw a point
          glVertex2d(0.1, 0.1);
       glEnd();
    }
    Your friend Egbert suggests that you could improve performance by putting these commands in a display list. He suggests adding the following code to your initialization (pt_list would be a global int):
    pt_list = glGenLists(1);
    if (pt_list == 0)
    {
       cerr << "Could not make list" << endl;
       exit(1);
    }
    
    glNewList(pt_list, GL_COMPILE);
       if (draw_pt_flag)
       {
          glBegin(GL_POINTS);  // draw a point
             glVertex2d(0.1, 0.1);
          glEnd();
       }
    glEndList();
    and replacing the original code in your display function with
    glCallList(pt_list);
    “Egbert,” you reply, “that would not improve performance very much. But aside from that, you have made a serious error!” What was Egbert’s error?
     
  4. a. When OpenGL draws a raster image, what determines where in the viewport the image goes? b. What OpenGL command sets the place where raster images go? c. Why do we care about this? Hint: Have we been drawing raster images?
     
  5. Function glutBitmapCharacter renders characters by calling glBitmap. This (I claim) is useful information. Give one way in which knowing this helps us.
     
  6. a. List the two main kinds of text fonts that are used in CG. Hint: I am not talking about particular formats here. b. Give an advantage of each kind over the other. c. Which kind is becoming more common, and what factors in the computing industry are making this happen?
     
  7. a. What is the GLUT reshape callback? b. Why is the reshape callback relevant to mouse handling?
     
  8. a. What is an OpenGL “viewport”? b. Where in a GLUT program do we typically set up the viewport?
     
  9. Briefly describe the following GLUT callbacks: a. mouse. b. motion.
     
  10. Commonly, when writing a GLUT motion function, you need to know which mouse button(s) is/are pressed. But this information is not passed to the motion function. What is an easy way to determine it?
     
  11. Suppose you have set up a projection with
    gluOrtho2D(0.0, 5.0, 0.0, 7.0);
    Your window width and height, in pixels, have been stored in the variables winw and winh, respectively. You get a mouse position from GLUT and store it in variables mousex and mousey. a. Write C++ expressions to properly compute x and y coordinates of the mouse position, in a form acceptable to glVertex* or glRasterPos*. b. What type-related arithmetic difficulty tends to rear its ugly head in situations like this one?
     
  12. a. How can the addition of pop-up menus improve the user interface of a program? b. How can the addition of pop-up menus make the user interface of a program worse?
     
  13. List two features that are commonly present in pop-up menus in modern GUI’s, but are not available in GLUT pop-up menus.
     
  14. a. When you “create” a GLUT menu, what exactly are you creating? b. What effect does calling glutCreateMenu have on the display?
     
  15. How do you draw a GLUT menu?
     
  16. An item in a menu reads
    Zapper Mode: Set
    a. What is wrong with this menu item? b. How can it be improved? c. Having thought the situation over, the software designer changes the item to read
    Toggle Zapper Mode
    . What is wrong with this one?
     

Answers

    1. A display list is a way of storing OpenGL commands for later, possibly repeated, playback.
    2. Display lists are also called call lists.
    1. A display-list name is a number, assigned by OpenGL, to identify the list.
    2. Here are several reasons why referring to display lists by name only is a Good Thing:
      • It allows us to avoid managing the memory used to store the list.
      • It means that display lists can be stored where the graphics hardware can get at the data easily, rather than where the application can get at it easily (easy for server vs. easy for client).
      • It means we do not have to know the format of a display list.
      • It means that display lists can be formatted in a system-dependent way, in order to optimize performance on a particular system.
  1. Egbert’s error was to expect the if statement to continue to work in the display list. Display lists hold only OpenGL commands, not C++ statements. So what the display list does will depend only on the value of draw_pt_flag at the time the list was compiled. Its value when the list is executed in the display function is irrelevant.
    1. OpenGL draws a raster image with the left side of its baseline at the current raster position.
    2. The raster position is set with the command glRasterPos*.
    3. This is relevant, since GLUT bitmap text is drawn using OpenGL raster-image commands (in particular, with glBitmap).
  2. The knowledge that glutBitmapCharacter uses glBitmap is helpful, because we have documentation on glBitmap, so we know some things about how GLUT bitmap characters work. For example, we know that the characters are rendered using an OpenGL command (glBitmap) and, therefore, we can make calls to glutBitmapCharacter during the compilation of a display list, and be confident that the character-rendering commands will appear in the list.
    1. The two kinds of graphical text fonts are bitmap fonts and stroke/outline fonts.
    2. Bitmap fonts are faster than stroke/outline fonts. They also tend to be better looking at their designed size. Stroke/outline fonts are much better for rotating and resizing than bitmap fonts.
    3. Stroke/outline fonts are becoming more common. The first reason for this is faster and faster computers, which make the speed advantage of bitmap fonts less and less important. The second reason is increasing resolution, particularly on printers, which make the looks advantage of bitmap fonts less important: the fact that something is one pixel off is less significant when the pixels are smaller.
    1. The GLUT reshape callback is a GLUT callback function that is called when a window’s size is set or changed.
    2. The reshape callback is relevant to mouse handling, since it lets us get the window size in pixels. This lets us find the position of the mouse in the window, since mouse positions are always given in pixels.
    1. Viewport is the term used to refer to the place where OpenGL output actually appears. When we resize the viewport (with glVierport, the various OpenGL buffers (color, depth, etc.) are resized accordingly.
    2. In a GLUT program, we generally set the size of the viewport in the reshape function, because the size of the viewport is usually related to the size of the window.
    1. The mouse function is called when a mouse button (with no menu attached to it) it pressed or released. Parameters are which button, the button state (up or down), and the mouse position at which the button was pressed (x and y).
    2. The motion function is called when the mouse moves while any button is pressed. Parameters are the new mouse position (x and y).
  3. If the motion function needs to know which mouse buttons are pressed, then that information should be saved in the mouse function, which does receive it. You are guaranteed that the mouse function will always be called before the motion function, so if you set appropriate globals in the mouse function, then the information will always be available when the motion function is called.
    1. The x- and y-coordinates are given, respectively, by the following.
      double(mousex)/winw*5.0
      (1 - double(mousey)/winh)*7.0
      Any expression that gives the same results as those above is fine; but watch out for the issue mentioned in the next part!
    2. Types can get you into trouble here, since numbers in pixels (mouse positions, window sizes) are typically stored in integer variables, while glVertex* and its ilk need floating-point values. If you are not careful, your computation will be performed with integer arithmetic, which will probably result in an incorrect value. Converting each mouse position coordinate to type double, as I have above, is a good way to deal with this problem.
    1. Menus can improve a user interface by:
      • Making functionality available in a way that users are already familiar with, and so do not have to learn/memorize.
      • Making functionality available available in a way that uses little or no screen space.
    2. Menus can worsen a user interface by:
      • Making functionality available in a way that takes time and interrupts a user’s train of thought.
      • Becoming an easy “dumping ground” for large numbers of commands, leading to a poorly organized interface.
  4. Here are a number of possible answers:
    1. When you create a GLUT menu, you are actually telling GLUT to create a data structure to hold menu information.
    2. Calling the function glutCreateMenu has no effect on the display.
  5. Trick question, sort of. You do not draw GLUT menus; GLUT does. They way you get GLUT to draw a menu is to create it, add items to it, and attach it to a mouse button in a window. GLUT then draws the menu when the appropriate mouse button is pressed in the appropriate window.
    1. The problem with this menu item is that it is not clear whether the text refers to the current state or to the action performed by selecting the menu item. In the former case, zapper mode is currently set; selecting the item probably unsets it. In the latter case, zapper mode is not currently set; selecting the item will set it.
    2. The item can be improved by clarifying which of the two types of information it is giving. To give state information, “Zapper Mode” with a checkmark (or not) might be good. To indicate what the item does, you might restate it as “Turn On Zapper Mode” or “Turn Off Zapper Mode”.
    3. Now at least the item tells what it does. However, it does not indicate whether zapper mode is currently set or not. Thus, the user may not know whether the mode is being turned on or off.


CS 381, Fall 2003: Test 1 Information & Week 3 Review Problems / Last update: 1 Oct 2002 / Glenn G. Chappell / ffggc@uaf.edu