DirectX SDK |
The presence of the D3DFVF_XYZ (or any of the D3DFVF_XYZBn flags) and D3DFVF_NORMAL flags in the vertex description that you pass to rendering methods identifies the untransformed and unlit vertex type. By using untransformed and unlit vertices, your application effectively requests that Direct3D perform all transformation and lighting operations using its internal algorithms. (If you want, you can disable the Direct3D lighting engine for the primitives being rendered by setting the D3DRENDERSTATE_LIGHTING render state to FALSE.)
Many applications use this vertex type, as it frees them from implementing their own transformation and lighting engines. However, because the system is making calculations for you, it requires that you provide a certain amount of information with each vertex:
Other than these requirements, you have the flexibility to use, or disregard, the other vertex components. For example, if you want to include a diffuse or specular color with your untransformed vertices, you can. (This wasn't possible before DirectX 6.0). Including individual colors for each vertex makes it possible to achieve shading effects that are much more subtle and flexible than lighting calculations that use only the material color. Keep in mind that you must enable per-vertex color through the D3DRENDERSTATE_COLORVERTEX render state. Untransformed, unlit vertices can also include up to eight sets of texture coordinates.
Applications can still use the legacy D3DVERTEX structure for vertices. In fact, the d3dtypes.h header file defines a shortcut macro to identify this vertex format:
#define D3DFVF_VERTEX ( D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 )
If the D3DVERTEX structure doesn't suit your application's needs, feel free to define your own. Remember which vertex components your application needs, and make sure they appear in the required order by declaring a properly ordered structure. The following code declares a valid vertex format structure that includes a position, a vertex normal, a diffuse color, and two sets of texture coordinates:
// // The vertex format description for this vertex // would be: (D3DFVF_XYZ | D3DFVF_NORMAL | // D3DFVF_DIFFUSE | D3DFVF_TEX2) // typedef struct _UNLITVERTEX { float x, y, z;// position float nx, ny, nz; // normal DWORD dwDiffuseRGBA; // diffuse color float tu1, // texture coordinates tv1; float tu2, tv2; } UNLITVERTEX, *LPUNLITVERTEX;
The vertex description for the preceding structure would be a combination of the D3DFVF_XYZ, D3DFVF_NORMAL, D3DFVF_DIFFUSE, and D3DFVF_TEX2 flexible vertex format flags. The rendering methods, such as IDirect3DDevice7::DrawPrimitive, accept the address of a vertex array as a void pointer, so remember to cast your vertex array pointer to the LPVOID data type when you call the rendering methods.
For more information, see About Vertex Formats.
Other than these requirements, you have the flexibility to use, or disregard, the other vertex components. For example, if you want to include a diffuse or specular color with your untransformed vertices, you can. (This wasn't possible before DirectX 6.0). Including individual colors for each vertex makes it possible to achieve shading effects that are much more subtle and flexible than lighting calculations that use only the material color. Keep in mind that you must enable per-vertex color through the D3DRENDERSTATE_COLORVERTEX render state. Untransformed, unlit vertices can also include up to eight sets of texture coordinates. Visual Basic applications can use the D3DVERTEX type for vertices.
If the D3DVERTEX type doesn't suit your application's needs, feel free to define your own. Remember which vertex components your application needs, and make sure they appear in the required order by declaring a properly ordered structure. The following code declares a valid vertex format structure that includes a position, a vertex normal, a diffuse color, and two sets of texture coordinates:
' ' The vertex format description for this vertex ' would be: (D3DFVF_XYZ Or D3DFVF_NORMAL Or ' D3DFVF_DIFFUSE Or D3DFVF_TEX2) ' Type UNLITVERTEX x As Single ' Position y As Single z As Single nx As Single ' Normal ny As Single nz As Single DiffuseRGBA As Long ' diffuse color tu1 As Single ' texture coordinates tv1 As Single tu2 As Single ' texture coordinates tv2 As Single End Type
The vertex description for the preceding structure would be a combination of the D3DFVF_XYZ, D3DFVF_NORMAL, D3DFVF_DIFFUSE, and D3DFVF_TEX2 flexible vertex format flags. The rendering methods, such as Direct3DDevice7.DrawPrimitive, accept the first element of a vertex array as type Any, to accommodate all types of vertex formats.
For more information, see About Vertex Formats.