DirectX SDK

Step 2.4: Prepare the Viewport

[C++]

This section pertains only to application development in Visual Basic. See Direct3D Immediate Mode C/C++ Tutorials.

[Visual Basic]

After you create a rendering device, you can create a viewport object and assign it to the rendering device. In short, the viewport determines how the geometry in a 3-D scene is clipped and then represented in the 2-D space of a display screen. For a conceptual overview about viewports, see Viewports and Clipping.

Setting up a viewport is a straight-forward process that starts with preparing the viewport parameters in a D3DVIEWPORT7 type. The Triangle tutorial application sets the viewport parameters to the dimensions of the render target surface, with a standard range of minimum and maximum depth values into which the scene will be rendered, 0.0 and 1.0, respectively:

Dim VPDesc As D3DVIEWPORT7
 
    VPDesc.lWidth = g_rcDest.Right - g_rcDest.Left
    VPDesc.lHeight = g_rcDest.Bottom - g_rcDest.Top
    VPDesc.minz = 0#
    VPDesc.maxz = 1#

Once the viewport parameter type is ready, the tutorial application sets the viewport parameters for the rendering device:

    g_d3dDevice.SetViewport VPDesc

Now, cache the viewport parameters in a RECT type; you will use this information later during clearing operations.

With g_d3drcViewport(0)
        .X1 = 0: .Y1 = 0
        .X2 = VPDesc.lWidth
        .Y2 = VPDesc.lHeight
    End With

Now that the basic DirectX objects have been created, you can start preparing the subordinate objects required to render the scene, which is the topic of Step 3: Initialize the Scene.