CHAPTER 7: Well-Rendered Miscellany (^225)
glPopMatrix();
spinY+=.25;
transY += 0.075;
}
And here’s the breakdown:
In line 1, GL_STENCIL_BUFFER_BIT is added to glClear().
Line 2 calls the new method renderToStencil(), which is back in
Listing 7-9. This will actually create the stenciled region, poking the
hole that we’ll draw through next.
Enable the stencil test in line 3.
Here in lines 4 and 5 the reflection is drawn. First translate it down a
little, subtracting 1.5, to ensure that it is below the real cube. And then
it’s a simple matter of ‘‘scaling’’ the y-axis to -1.0 to flip it upside-
down. You will need to change the front face to clockwise at this point;
otherwise, you’ll see the back faces only.
We want to make the lower image translucent instead of the full
intensity, as we’d expect. In line 6f, blend is enabled and uses the
most common blending function of GL_ONE and
GL_ONE_MINUS_SRC_COLOR covered in Chapter 6.
In lines 7ff we see that the inverted object is drawn exactly the same
way as the original. When done, the blending is switched off in line 8
so that it doesn’t affect the rendering of the primary cube. At the same
time, stencil is switched off while depth test is switched back on.
Since scale was touched to invert the image, in line 9 scale is reset to
the default. The translation has been modified with a couple of other
small values. This shifts it up a little bit just to get extra clearance for
the inverted cube.
And now the test. Figure 7-8 is what you should see.
singke
(singke)
#1