Microsoft DirectX 8.0 (C++) |
Create an index buffer object by calling the IDirect3DDevice8::CreateIndexBuffer method, which accepts five parameters. The first parameter specifies the index buffer length, in bytes.
The second parameter is a set of usage controls. Among other things, its value determines whether the vertices being referred to by the indices are capable of containing clipping information. To improve performance, specify D3DUSAGE_DONOTCLIP when clipping is not required.
The third parameter is either the D3DFMT_INDEX16 or D3DFMT_INDEX32 member of the D3DFORMAT enumerated type that specifies the size of each index.
The fourth parameter is a member of the D3DPOOL enumerated type that tells the system where in memory to place the new index buffer.
The final parameter that CreateIndexBuffer accepts is the address of a variable that is filled with a pointer to the new IDirect3DIndexBuffer8 interface of the vertex buffer object, if the call succeeds.
The following C++ code example shows what creating a index buffer might look like in code.
/* * For the purposes of this example, the d3dDevice variable is the * address of an IDirect3DDevice8 interface exposed by a * Direct3DDevice object, g_IB is a variable of type * LPDIRECT3DINDEXBUFFER8. */ if( FAILED( d3dDevice->CreateIndexBuffer( 16384 *sizeof(WORD), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &g_IB ) ) ) return E_FAIL;