Game Development Reference
In-Depth Information
2.1.1 Vertex Formats
The previous definition of a vertex is correct mathematically, but it is
an incomplete definition when used in the context of Direct3D. This is
because a vertex in Direct3D can consist of additional properties
besides a spatial location. For instance, a vertex can have a color prop-
erty as well as a normal property (colors and normals are discussed in
Chapters 4 and 5, respectively). Direct3D gives us the flexibility to con-
struct our own vertex formats; in other words it allows us to define the
components of a vertex.
To create a custom vertex format, we first create a structure that
holds the vertex data that we choose. For instance, below we illustrate
two different kinds of vertex formats; one consists of position and color,
and the second consists of position, normal, and texture coordinates
(see Chapter 6, “Texturing”).
struct ColorVertex
{
float _x, _y, _z;
// position
DWORD _color;
};
struct NormalTexVertex
{
float _x, _y, _z; // position
float _nx, _ny, _nz; // normal vector
float _u, _v;
// texture coordinates
};
Once we have the vertex structure completed, we need to describe the
way that the vertices are formatted by using a combination of flexible
vertex format (FVF) flags. Using the previous two vertex structures,
we have the following vertex formats :
#define FVF_COLOR (D3DFVF_XYZ | D3DFVF_DIFFUSE)
Put into words, the above says that the vertex structure that corre-
sponds to this vertex format contains a position property and a diffuse
color property.
#define FVF_NORMAL_TEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1)
The above says that the vertex structure that corresponds to this ver-
tex format contains position, normal, and texture coordinate properties.
One restriction that must be taken into consideration is that the
order in which you specify the flexible vertex flags must be the same
order in which you specify the data in the vertex structure.
Look up D3DFVF in the documentation for a complete list of the
available vertex format flags.
Search WWH ::




Custom Search