Core Techniques and Algorithms in Game Programming2003
DrawPrimitive can only work with nonindexed primitives. For indexed primitives, DrawIndexedPrimitive must be used. However, we need to first learn how to create an index buffer, so we can couple that with the actual geometry. The process starts with a call to: HRESULT CreateIndexBuffer(UINT Length,DWORD Usage,D3DFORMAT Format, D3DPOOL Pool,IDirect3DIndexBuffer8** ppIndexBuffer); This call creates the array of indices. The syntax is very similar to the CreateVertexBuffer call. The only difference is the third parameter. For the CreateVertexBuffer call, this parameter specifies the FVF to be used. This makes no sense in index buffers. But there is a parameter that is somehow similar: The Format parameter allows us to specify the format of the index buffer so memory footprint is reduced. Valid parameters are D3DFMT_INDEX16 for 16-bit indices and D3DFMT_INDEX32 for their 32-bit counterparts. Now, we need to provide Direct3D with both a vertex and index buffer. The index buffer will contain the topology information (face loops), whereas the vertex buffer will hold the geometrical information, such as vertices, colors, and mapping coordinates. Then, the DrawIndexedPrimitive is used to render the geometry. The syntax is HRESULT DrawIndexedPrimitive(D3DPRIMITIVETYPE Type, INT BaseVertexIndex, UINT MinIndex, UINT NumVertices, UINT StartIndex, UINT PrimitiveCount ); The first parameter defines the type of geometry to handle, from points to triangle strips and fans. The second and third parameters are used to specify the starting point in both the vertex and index buffers. Then, we use the remaining parameters to specify the number of vertices, the first index, and the number of indices to be processed, respectively. |