Game Development Reference
In-Depth Information
Example vertex declaration description
: Suppose the vertex format we
want to describe consists of a position vector and three normal vectors.
The vertex declaration would be specified as:
D3DVERTEXELEMENT9 decl[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_
POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_
NORMAL, 0},
{0, 24, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_
NORMAL, 1},
{0, 36, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_
NORMAL, 2},
D3DDECL_END()
};
The
D3DDECL_END
macro is used to initialize the last vertex element
in the
D3DVERTEXELEMENT9
array. Also, observe the usage index
labels for the normal vectors.
17.1.2
Creating a Vertex Declaration
Once you have described a vertex declaration as a
D3DVERTEXELE-
MENT9
array, we can obtain a pointer to an
IDirect3DVertex-
Declaration9
interface using the method:
HRESULT IDirect3DDevice9::CreateVertexDeclaration(
CONST D3DVERTEXELEMENT9* pVertexElements,
IDirect3DVertexDeclaration9** ppDecl
);
pVertexElements
—Array of
D3DVERTEXELEMENT9
structures
describing the vertex declaration we want created
ppDecl
—Used to return a pointer to the created
IDirect3D-
VertexDeclaration9
interface
Example call, where
decl
is a
D3DVERTEXELEMENT9
array:
IDirect3DVertexDeclaration9* _decl = 0;
hr = _device->CreateVertexDeclaration(decl, &_decl);
17.1.3
Enabling a Vertex Declaration
Recall that flexible vertex formats are a convenience feature and inter-
nally get converted to vertex declarations. Thus, when using vertex
declarations directly, we no longer call:
Device->SetFVF( fvf );
We instead call:
Device->SetVertexDeclaration( _decl );
Search WWH ::
Custom Search