Graphics Reference
In-Depth Information
13.3.1
Implementation Details
There are a few more changes involved when extending our program to support
the third dimension.
1. Allocate the Z-buffer. Listing 13.3 shows part of the OnCreate() function
of the GrfxWindowD3D class (defined in GrfxWindowD3D.cpp ). The last
two lines in Listing 13.3 show that we must enable and allocate the Z-stencil
or Z-buffer. As will be discussed later, this buffer is used for resolving
visibility in 3D.
2. Enable the Z-buffer. At the beginning of rendering, we must make sure Z-
buffer testing in the render state is enabled. Listing 13.4 shows some of the
details of the CGrfxWindowD3D::OnPaint() function that were omitted in
Listing 13.2. Here we see that one of the first operations we perform after
BeginScene() is to set the ZENABLE to be true.
3. Clear the Z-buffer. Listing 13.5 shows the details of the parameters to the
Clear() function during the OnPaint() redraw (once again, this detail is
omitted from Listing 13.2). Here we see that when clearing buffers, the
Z-buffer must also be cleared.
4. Define the floor. Notice that when drawing the rectangles in Step 3 of
Listing 13.2, the positions are defined on the xz -plane (e.g.,
) with
the y -coordinate defined to be zero. Recall that in 2D space, we worked
with rectangles on the xy -plane. The convention in 3D space reserves y to
be the height, and xz to be the horizontal plane.
(
4
,
0
,
4
)
int CGrfxWindowD3D::OnCreate(...) {
.
Source file.
GrfxWindowD3D.cpp file in
the GrfxWindow folder of the
D3D _ Rectangles3D project.
// creation and initialization
D3DPRESENT _ PARAMETERS present _ params;
.
// Set Windowed to TRUE, since we want to do D3d in a window
present _ params.Windowed = TRUE;
.
present _ params.EnableAutoDepthStencil = TRUE;
present _ params.AutoDepthStencilFormat = D3DFMT _ D24S8;
.
Listing 13.3. Allocate the Z-buffer.
Search WWH ::




Custom Search