The D3DVIEWPORT2 structure defines the visible 3-D volume and the window dimensions that a 3-D volume projects onto. This structure is used by the methods of the IDirect3D2 and IDirect3DDevice2 interfaces, and in particular by the IDirect3DViewport3::GetViewport2 and IDirect3DViewport3::SetViewport2 methods. This structure was introduced in DirectX 5.0.
typedef struct _D3DVIEWPORT2 {
DWORD dwSize;
DWORD dwX;
DWORD dwY;
DWORD dwWidth;
DWORD dwHeight;
D3DVALUE dvClipX;
D3DVALUE dvClipY;
D3DVALUE dvClipWidth;
D3DVALUE dvClipHeight;
D3DVALUE dvMinZ;
D3DVALUE dvMaxZ;
} D3DVIEWPORT2, *LPD3DVIEWPORT2;
The relevant coordinates here are the nonhomogeneous coordinates that result from the perspective division that projects the vertices onto the w=1 plane.
The dwX, dwY, dwWidth and dwHeight members describe the position and dimensions of the viewport on the render target surface. Usually, applications render to the entire target surface; when rendering on a 640x480 surface, these members should be 0, 0, 640, and 480, respectively.
The dvClipX, dvClipY, dvClipWidth, dvClipHeight, dvMinZ, and dvMaxZ members define the non-normalized post-perspective 3-D view volume which is visible to the viewer. In most cases, dvClipX is set to -1.0 and dvClipY is set to the inverse of the viewport's aspect ratio on the target surface, which can be calculated by dividing the dwHeight member by dwWidth. Similarly, the dvClipWidth member is typically 2.0 and dvClipHeight is set to twice the aspect ratio set in dwClipY. The dvMinZ and dvMaxZ are usually set to 0.0 and 1.0.
Unlike the D3DVIEWPORT structure, D3DVIEWPORT2 specifies the relationship between the size of the viewport and the window. The coordinates and dimensions of the viewport are given relative to the top left of the device; values increase in the y-direction as you descend the screen.
When the viewport is changed, the driver builds a new transformation matrix.
Windows NT/2000: Requires Windows 2000.
Windows 95/98: Requires Windows 95 or later. Available as a redistributable for Windows 95.
Header: Declared in d3dtypes.h.
D3DVALUE, IDirect3DViewport3::GetViewport2, IDirect3DViewport3::SetViewport2, Clipping Volumes, Viewports and Clipping