D3DVIEWPORT2

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;
 

Members

dwSize
Size of this structure, in bytes. This member must be initialized before the structure is used.
dwX and dwY
Pixel coordinates of the top-left corner of the viewport on the render target surface. Unless you want to render to a subset of the surface, these members can be set to zero.
dwWidth and dwHeight
Dimensions of the viewport on the render target surface, in pixels. Unless you are rendering only to a subset of the surface, these members should be set to the dimensions of the render target surface.
dvClipX and dvClipY
Coordinates of the top-left corner of the clipping volume.

The relevant coordinates here are the nonhomogeneous coordinates that result from the perspective division that projects the vertices onto the w=1 plane.

dvClipWidth and dvClipHeight
Dimensions of the clipping volume projected onto the w=1 plane. Unless you want to render to a subset of the surface, these members can be set to the width and height of the destination surface.
dvMinZ and dvMaxZ
Values of the D3DVALUE type describing the maximum and minimum nonhomogeneous z-coordinates resulting from the perspective divide and projected onto the w=1 plane.

Remarks

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.

QuickInfo

  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.

See Also

D3DVALUE, IDirect3DViewport3::GetViewport2, IDirect3DViewport3::SetViewport2, Clipping Volumes, Viewports and Clipping