Platform SDK: DirectX

Texture Coordinate Formats

Texture coordinates in Direct3D can include 1, 2, 3, or 4 floating point elements to address textures with varying levels of dimension. A 1-D texture (a texture surface with dimensions of 1-by-n texels) would be addressed by one texture coordinate. The most common case, 2-D textures, are addressed with two texture coordinates commonly called u and v. Direct3D supports a single type of 3-D texture, called a cubic-environment map. Cubic environment maps aren't truly 3-D, but they are addressed with a 3-element vector. For details, see Cubic Environment Mapping.

[C++]

As described in About Vertex Formats, applications encode texture coordinates within the vertex format. The vertex format can include multiple sets of texture coordinates. Use the D3DFVF_TEX0 through D3DFVF_TEX8 flexible vertex format flags to describe a vertex format that includes no texture coordinates, or as many as eight sets.

Each texture coordinate set can have between 1 and 4 elements. The D3DFVF_TEXTUREFORMAT1 through D3DFVF_TEXTUREFORMAT4 flags describe the number of elements are in a given texture coordinate in a given set, but these flags aren't used by themselves. Rather, the D3DFVF_TEXCOORDSIZEn set of macros use these flags to create bit patterns that describe the number of elements used by a particular set of texture coordinates in the vertex format. These macros accept a single parameter that identifies the index of the coordinate set whose number of elements is being defined. The following example illustrates how these macros are used.

// This vertex format contains two sets of texture coordinates. The first 
// set (index 0) has 2 elements, and the second set has 1 element.
//
// The description for this vertex format would be: 
//     dwFVF = D3DFVF_XYZ  | D3DFVF_NORMAL | 
//             D3DFVF_DIFFUSE | D3DFVF_TEX2| 
//             D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEXCOORDSIZE1(1); 
//
typedef struct CVF {
    D3DVECTOR position;
    D3DVECTOR normal;
    D3DCOLOR  diffuse;
    float     u, v;   // 1st set, 2-D
    float     t;      // 2nd set, 1-D
} CustomVertexFormat;
[Visual Basic]

As described in About Vertex Formats, applications encode texture coordinates within the vertex format. The vertex format can include multiple sets of texture coordinates. Use the D3DFVF_TEX0 through D3DFVF_TEX8 flexible vertex format flags to describe a vertex format that includes no texture coordinates, or as many as eight sets.

Each texture coordinate set can have between 1 and 4 elements. Use the D3DFVF_TEXCOORDSIZEn set of helper functions in the Math.bas source file that ships with this SDK to generate bit patterns that describe the number of elements used by a particular set of texture coordinates in the vertex format. These macros accept a single parameter that identifies the index of the coordinate set whose number of elements is being defined. The following example illustrates how these macros are used.

Private Sub Form_Load()
' This vertex format contains two sets of texture coordinates. The first
' set (index 0) has 2 elements, and the second set has 1 element.
'
' The description for this vertex format would be:
'     lFVF = D3DFVF_XYZ Or D3DFVF_NORMAL Or _
'            D3DFVF_DIFFUSE Or D3DFVF_TEX2 Or _
'            D3DFVF_TEXCOORDSIZE2(0) Or D3DFVF_TEXCOORDSIZE1(1)
'
Type CustomVertexFormat
    position As D3DVECTOR
    normal As D3DVECTOR
    diffuse  As D3DVECTOR
    ' 1st set, 2-D
    u As Single
    v As Single
    ' 2nd set, 1-D
    t As Single
End Type

Note  With the exception of cubic-environment maps, rasterizers cannot address textures by using any more than two elements. Applications can supply up to three elements for a texture coordinate, but only if the texture is a cube map, or the D3DTTFF_PROJECTED texture transform flag is used. The D3DTTFF_PROJECTED flag causes the rasterizer to divide the first two elements by the third (or nth) element. For more information, see Texture Coordinate Transformations.