Platform SDK: DirectX

Step 2: Render a Textured Primitive

[C++]

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

[Visual Basic]

The only difference between rendering a textured primitive and a non-textured primitive is that you have to set the texture during the rendering of a textured primitive.

The following code excerpt from the Texture application draws the front and back faces of a cube, using the texture surface g_ddsTexture1:

    g_d3dDevice.SetTexture 0, g_ddsTexture1
    Call g_d3dDevice.DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_VERTEX, g_vCube(0), _
         4, D3DDP_DEFAULT)
    Call g_d3dDevice.DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_VERTEX, g_vCube(4), _
         4, D3DDP_DEFAULT)

You should employ the same procedures for the top and bottom faces of the cube, and the left and right faces of the cube, setting g_ddsTexture2 and g_ddsTexture3, respectively. See the Texture application code in the SDK for information on how to do this.

The Direct3DDevice7.SetTexture method assigns a texture to a given stage for a device. Since this tutorial does not use multiple texture blending, the first parameter of SetTexture is 0, specifying a value of 0 for the stage identifier. The second parameter identifies the DirectDrawSurface7 object being set as the texture.

For more information on textured rendering, see Rendering with Texture Surfaces.

For more information on multiple texture blending, see Multiple Texture Blending.