Click for blendRectangles1.cpp Program Windows Project
E
xper
iment
13.1. Run blendRectangles1.cpp, which draws two translu-cent rectangles with their alpha values equal to 0.5, the red one being closer to the viewer than the blue one. The code order in which the rectangles are drawn can be toggled by pressing space. Figure 13.2 shows screenshots ofeither order.
E
ndClick for blendRectangles2.cpp Program Windows Project
E
xper
iment
13.2. Run blendRectangles2.cpp, which draws three rectangles at different distances from the eye. The closest one at depth 0.5 is vertical and a translucent red (α = 0.5), the next one at depth 0.7 is angled and opaque green (α = 1), while the farthest at depth 0.9 is horizontal anda translucent blue (α = 0.5). Figure 13.3(a) is a screenshot of the output. 91
Chapter 13 Special Visual Techniques
(a) (b) (c)
Figure 13.1: Screenshots of blendRectangles2.cpp: (a) Original (b) With rectangles re-ordered to blue, green, red in the code (c) New ordering seen from the −z-direction.
The scene is clearly not authentic as no translucency is evident in either of the two areas where the green and blue rectangles are behind the red.
The fault is not OpenGL’s as it is rendering as it’s supposed to with depth
testing, as we see next.
E
ndClick for blendRectangles2.cpp modified Program Windows Project
E
xper
iment
13.3. Rearrange the rectangles and insert two glDepth-Mask() calls in the drawing routine of blendRectangles2.cpp as follows:// Draw opaque objects, only one.
drawGreenRectangle();
glDepthMask(GL FALSE); // Make depth buffer read-only.
// Draw translucent objects.
drawBlueRectangle();
drawRedRectangle();
glDepthMask(GL TRUE); // Make depth buffer writable.
Try both gluLookAt(. . ., 0.0, 0.0, -1.0, . . .) and gluLookAt(. . ., 0.0, 0.0, 1.0, . . .) to see the rectangles from the front and back.
Interchange the drawing order of the two translucent rectangles as well.
The scene is authentic in every instance.
E
ndClick for sphereInGlassBox.cpp Program Windows Project
E
xper
iment
13.4. Run sphereInGlassBox.cpp, which makes the sides of the box of sphereInBox2.cpp glass-like by rendering them translucently.92
Only the unaveraged normals option of sphereInBox2.cpp is implemented.
Press the up and down arrow keys to open or close the box and ‘x/X’, ‘y/Y’
and ‘z/Z’ to turn it.
The opaque sphere is drawn first and then the translucent box sides, after making the depth buffer read-only. A screenshot is Figure 13.5(a).
E
ndClick for fieldAndSkyTexturesBlended.cpp Program Windows Project
E
xper
iment
13.5. Run fieldAndSkyTexturesBlended.cpp, which is based on fieldAndSkyLit.cpp. Press the arrow keys to move the sun.As the sun rises the night sky morphs into a day sky (yes, we saw this very same morph as an application of multitexturing, using the interpolation combiner, in Section 12.6). Figure 13.5(b) shows late evening.
E
ndClick for ballAndTorusReflected.cpp Program Windows Project
E
xper
iment
13.6. Run ballAndTorusReflected.cpp, which builds on ballAndTorusShadowed.cpp. Press space to start the ball traveling around the torus and the up and down arrow keys to change its speed.The reflected ball and torus are obtained by drawing them scaled by a factor of −1 in the y-direction, which creates their reflections in the xz-plane, and then blending the floor into the reflection. Figure 13.5(c) shows a
screenshot.
E
ndClick for fieldAndSkyFogged.cpp Program Windows Project
E
xper
iment
13.7. Run fieldAndSkyFogged.cpp, which is based on our favorite workhorse program fieldAndSky.cpp, adding to it a movable black ball and controllable fog. Figure 13.6 is a screenshot.Press the up/down arrow keys to move the ball. When the program starts there is no fog. We’ll describe the fog controls after we discuss their
implementation in the following.
E
ndClick for billboard.cpp Program Windows Project
E
xper
iment
13.8. Run billboard.cpp, where an image of two trees is textured onto a rectangle. Press the up and down arrow keys to move the viewpoint and the space bar to turn billboarding on and off. See Figure 13.9for screenshots.
E
nd 93Chapter 13 Special Visual Techniques
Click for antiAliasing+multisampling.cpp Program Windows Project
E
xper
iment
13.9. Run antiAliasing+multisampling.cpp. Ignore the multisampling controls, as well as the blue-yellow rectangle, for now. Focus on the red line segment and the green point, which are both either antialiased or not, ‘a’ or ‘A’ toggling between the two modes. The width of the line is changed by pressing ‘l/L’, while the size of the point with ‘p/P’. The scene can be turned by the ‘x’-‘Z’ keys and translated by pressing the arrow and page up/down keys. A wire cube is drawn as frame of reference to view the motion.Figure 13.11 shows screenshots of antialiasing both off and on. The effect of antialiasing is especially marked when the line is just shy of horizontal or
vertical.
E
ndClick for antiAliasing+multisampling.cpp Program Windows Project
E
xper
iment
13.10. Fire up again antiAliasing+multisampling.cpp.Multisampling is toggled on/off, independently of antialiasing, by pressing
‘m’ or ‘M’.
Multisampling antialiases polygons particularly effectively and its effect in our program is best observed on the boundary of the blue-yellow rectangle, as well as the edge between its two colored halves, particularly, when they are nearly horizontal or vertical.
When multisampling is enabled, lines and points are antialiased regardless if GL POINT SMOOTH or GL LINE SMOOTH have been enabled, which you can
see as well.
E
ndClick for pointSprite.cpp Program Windows Project
E
xper
iment
13.11. Fire up pointSprite.cpp. The space bar toggles animation on and off. The particle system of six sprites of fluctuating size, imprinted with the same star texture, spinning in a circle is simple-minded, though, hopefully, indicative of the possibilities. Figure 13.13 is a screenshot.E
ndClick for sphereMapping.cpp Program Windows Project
E
xper
iment
13.12. Run sphereMapping.cpp, which shows the scene of a shuttle launch with a reflective rocket cone initially stationary in the sky in front of the rocket. Press the up and down arrow keys to move the cone. As the cone flies down, the reflection on its surface of the launch image changes.Figure 13.15 is a screenshot as it’s about to crash to the ground.
E
nd94
Click for ballAndTorusStenciled.cpp Program Windows Project
E
xper
iment
13.13. Run ballAndTorusStenciled.cpp, based on ball-AndTorusReflected.cpp. The difference is that in the earlier program the entire checkered floor was reflective, while in the current one the red floor is non-reflective except for a mirror-like disc lying on it. Pressing the arrow keys moves the disc and pressing the space key starts and stops the ball moving. As you can see in the screenshot of Figure 13.24, the ball and torus are reflected only in the disc and nowhere else.E
ndClick for imageManipulation.cpp Program Windows Project
E
xper
iment
13.14. Run imageManipulation.cpp. An image of the numeral 1 appears at the bottom left of the OpenGL window. Clicking the mouse left button anywhere on the window will move the image to that location, while you can, as well, drag the image with the left button pressed.Figure 13.25 is a screenshot of the initial configuration.
E
ndClick for imagaManipulationPBO.cpp Program Windows Project
E
xper
iment
13.15. Fire up imageManipulationPBO.cpp, which modifies imageManipulation.cpp to store the pixel data in a PBO. Otherwise, the functionality of both programs is identical, the image of the numeral beingmoved by mouse clicks and drags.
E
ndClick for bumpMapping.cpp Program Windows Project
E
xper
iment
13.16. Run bumpMapping.cpp, where a plane is bump mapped to make it appear corrugated. Press space to toggle between bump mapping turned on and off. Figure 13.29 shows screenshots.E
nd95