Microsoft DirectX 9.0

Vertex Legacy Type

This topic shows the steps necessary to initialize and use vertices that have a position, a normal, and texture coordinates.

The first step is to define the custom vertex type and FVF as shown in the code example below.

struct Vertex
    FLOAT x, y, z;
    FLOAT nx, ny, nz;
    FLOAT tu, tv;


The next step is to create a vertex buffer with enough room for four vertices by using the IDirect3DDevice9::CreateVertexBuffer method as shown in the code example below.

                 4*sizeof(Vertex), VertexFVF, 
                 D3DPOOL_DEFAULT, &pBigSquareVB);

The next step is to manipulate the values for each vertex as shown in the code example below.

Vertex * v;
pBigSquareVB->Lock( 0, 0, (BYTE**)&v, 0 );

v[0].x  = 0.0f;  v[0].y  = 10.0;  v[0].z  = 10.0f;
v[0].nx = 0.0f;  v[0].ny = 1.0f;  v[0].nz = 0.0f;
v[0].tu = 0.0f;  v[0].tv = 0.0f;

v[1].x  = 0.0f;  v[1].y  = 0.0f;  v[1].z  = 10.0f;
v[1].nx = 0.0f;  v[1].ny = 1.0f;  v[1].nz = 0.0f;
v[1].tu = 0.0f;  v[1].tv = 0.0f;

v[2].x  = 10.0f; v[2].y  = 10.0f; v[2].z  = 10.0f;
v[2].nx = 0.0f;  v[2].ny = 1.0f;  v[2].nz = 0.0f;
v[2].tu = 0.0f;  v[2].tv = 0.0f;

v[3].x  = 0.0f; v[3].y  = 10.0f;  v[3].z = 10.0f;
v[3].nx = 0.0f; v[3].ny = 1.0f;   v[3].nz = 0.0f;
v[3].tu = 0.0f; v[3].tv = 0.0f;


The vertex buffer has been initialized and is ready to render. The following code example shows how to use the legacy flexible vertex format (FVF) to draw a square.

g_d3dDevice->SetFVF( VertexFVF );
g_d3dDevice->SetStreamSource( 0, pBigSquareVB, 4*sizeof(Vertex) );
g_d3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0 ,2);

Passing an FVF to IDirect3DDevice9::SetFVF specifies a legacy FVF with stream 0.

© 2002 Microsoft Corporation. All rights reserved.