Microsoft DirectX 8.1 (Visual Basic)

Rendering from a Vertex Buffer

Rendering vertex data from a vertex buffer requires a few steps. First, you need to set the stream source by calling the Direct3DDevice8.SetStreamSource method, as shown in the following code example.

Call m_D3Device.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 inform Direct3D which vertex shader to use by calling the Direct3DDevice8.SetVertexShader method. The following sample code sets an FVF code for the vertex shader. This informs Direct3D of the types of vertices it is dealing with.

Call m_D3DDevice.SetVertexShader(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 Direct3DDevice8.DrawPrimitive method.

Call m_D3DDevice.DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1)

The second parameter that DrawPrimitive accepts is the index of the first vector in the vertex buffer to load.