EXERCISES FOR WEEK 2
week2-1

Use the demo program horiz_stripes3.cpp as a guide to write a display function that draws vertical stripes instead of horizontal stripes.

 

week2-2

Now put the horizontal stripes and vertical stripes together in the same program, using multiple windows. Have one window display horizontal stripes and a second window display vertical stripes.

week2-3

Add a third window to the program you wrote in exercise 2 so that it displays a "checkerboard".

 

week2-4

Suppose you have called glOrtho(0.0, 10.0, 0.0, 6.0, -1.0 1.0) and you are using the default viewport (entire screen window). The screen window width is 600 pixels (0 to 599) and its height is 400 pixels (0 to 399).

  • To what pixel value does the center of the frame (real window) (5.0, 3.0) map?
  • To what pixel value does the point (4.0, 2.0) map?
week2-5

Suppose you have called glOrtho(-10.0, 10.0, -6.0, 6.0, -1.0, 1.0) and you are using the default viewport (entire screen window). The screen window width is 600 pixels (0 to 599) and its height is 400 pixels (0 to 399).

  • To what pixel value does the center of the frame (real window) (0.0, 0.0) map?
  • To what pixel value does the real point (4.0, -2.0) map?
week2-6

What is the aspect ratio of the real window frame defined in the previoius exercise?   If you are still using the default viewport,

  • suggest appropriate screen window dimensions to use that would preserve the aspect ratio of the scene.
  • what screen window height would you use if you need to set the screen window width to be 500 pixels?
  • what screen window width would you use if you need to set the screen window height to be 500 pixels?
week2-7

If you want to preserve the aspect ratio of the real window frame defined in exercise 5, but must use a square screen window (800 by 800 pixels), what values would you use for left, bottom, width, height in the call to

glViewport(left, bottom, width, height);

so that the viewport is centered both vertically and horizontally in the screen window and uses as much of the window as possible?

 

week2-8

Re-do exercise 7 using the real window frame defined by:

glOrtho(-6.0, 6.0, -10.0, 10.0, -1.0, 1.0)

 

week2-9 Suppose your real world window frame is given by Frame.Left, Frame.Right, Frame.Bottom, and Frame.Top and the values for width and height of the screen window are given by ScreenWindow.Width and ScreenWindow.Height.   If the default viewport is used (the frame is mapped to the entire window), what is the real value (in terms of the real frame setting) for the pixel values (x,y) returned by the mouse click.  In other words, to what point in your real window on your graph paper does the mouse click correspond?
 
week2-10
Test your answer to previous exercise with this case:

The lower left corner of your real frame is (-5.0, -10.0) and the upper right corner of your real frame is (10.0, 15.0).  The screen window width is 400 pixels and the screen window height is 500 pixels.  The x and y values returned by the mouse click are (200, 300).  What is the corresponding (x,y) point in the real window?

week2-11

Regarding exercise 2-10, what will be the coordinates of the viewport within the screen window if we choose a viewport that preserves the aspect ratio of the real frame and is centered within the screen window?

Test your answer to exercise 3 by choosing this viewport with the window and mouse info given in the test case in exercise 2.