Game Development Reference
In-Depth Information
2.3.8 Viewport Transform
The viewport transform is responsible for transforming coordinates on
the projection window to a rectangle on the screen, which we call the
viewport . For games, the viewport is usually the entire screen rectan-
gle. However, it can be a subset of the screen or client area if we are
running in windowed mode. The viewport rectangle is described rela-
tive to the window it resided in and is specified in window coordinates.
Figure 2.16 shows a viewport.
Figure 2.16: The
viewport rectangle
In Direct3D a viewport is represented by the D3DVIEWPORT9 struc-
ture. It is defined as:
typedef struct _D3DVIEWPORT9 {
DWORD X;
DWORD Y;
DWORD Width;
DWORD Height;
DWORD MinZ;
DWORD MaxZ;
} D3DVIEWPORT9;
The first four data members define the viewport rectangle relative to
the window in which it resides. The MinZ member specifies the mini-
mum depth buffer value, and MaxZ specifies the maximum depth buffer
value. Direct3D uses a depth buffer range of zero to one, so MinZ and
MaxZ should be set to those values respectively unless a special effect
is desired.
Once we have filled out the D3DVIEWPORT9 structure, we set the
viewport with Direct3D like so:
D3DVIEWPORT9 vp{ 0, 0, 640, 480, 0, 1 };
Device->SetViewport(&vp);
Search WWH ::




Custom Search