Microsoft DirectX 8.1 (Visual Basic) |
Rendering index data from an index buffer requires a few steps. First, you must set the stream source by calling the Direct3DDevice8.SetStreamSource method.
Call m_D3DDevice.SetStreamSource( 0, VB, len(CUSTOMVERTEX) )
The first parameter of SetStreamSource tells Direct3D the source of the device data stream. The second parameter is the vertex buffer to bind to the data stream. The third parameter is the size of the component, in bytes. In the sample code above, the size of a CUSTOMVERTEX is used for the size of the component.
The next step is to call the Direct3DDevice8.SetIndices method to set the source of the index data.
Call m_D3DDevice.SetIndices( IB, 0 )
The first parameter that SetIndices accepts is the address of the index buffer to set. The second parameter is the starting point in the vertex stream.
After setting the stream and index sources, use the Direct3DDevice8.DrawIndexedPrimitive method to render vertices that use indices from the index buffer.
Call m_D3DDevice.DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, dwVertices, _ 0, dwIndices / 3)
The second parameter that DrawPrimitive accepts is the minimum vertex index for vertices used during this call. The third parameter is the number of indices to use during this call starting from BaseVertexIndex + MinIndex. The fourth parameter is the location in the index buffer to start reading indices. The final parameter that DrawPrimitive accepts is the number of primitives to render. This parameter is a function of the primitive count and the primitive type. The code sample above uses triangles, so the number of primitives to render is the number of indices divided by three.