Microsoft DirectX 8.1 (C++) |
Before using textures, a custom vertex format that includes texture coordinates must be used. Texture coordinates tell Microsoft® Direct3D® where to place a texture for each vector in a primitive. Texture coordinates range from 0.0 to 1.0, where (0.0, 0.0) represents the top-left side of the texture and (1.0, 1.0) represents the bottom-right side of the texture.
The following sample code shows how the Texture sample project sets up its custom vertex format to include texture coordinates.
struct CUSTOMVERTEX { D3DXVECTOR3 position; // The position. D3DCOLOR color; // The color. FLOAT tu, tv; // The texture coordinates. }; // The custom FVF, which describes the custom vertex structure. #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)
For more information on texture coordinates, see Texture Coordinates.
Now that a custom vertex type has been defined, the next step is to load a texture and create a cylinder, as described in Step 2: Initializing Screen Geometry.