|Microsoft DirectX 9.0|
Rendering vertex data from a vertex buffer requires a few steps. First, you need to set the stream source by calling the IDirect3DDevice9::SetStreamSource method, as shown in the following example.
d3dDevice->SetStreamSource( 0, g_pVB, sizeof(CUSTOMVERTEX) );
The first parameter of IDirect3DDevice9::SetStreamSource tells Microsoft?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 inform Direct3D which vertex shader to use by calling the IDirect3DDevice9::SetVertexShader method. The following sample code sets an flexible vertex format (FVF) code for the vertex shader. This informs Direct3D of the types of vertices it is dealing with.
d3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
After setting the stream source and vertex shader, any draw methods will use the vertex buffer. The code example below shows how to render vertices from a vertex buffer with the IDirect3DDevice9::DrawPrimitive method.
d3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 );
The second parameter that IDirect3DDevice9::DrawPrimitive accepts is the index of the first vector in the vertex buffer to load.