Game Development Reference
In-Depth Information
3.3 Drawing Preparations
Once we have created a vertex buffer and, optionally, an index buffer,
we are almost ready to render its contents, but there are three steps
that must be taken first.
1.
Set the stream source. Setting the stream source hooks up a vertex
buffer to a stream that essentially feeds geometry into the render-
ing pipeline.
The following method is used to set a stream source:
HRESULT IDirect3DDevice9::SetStreamSource(
UINT StreamNumber,
IDirect3DVertexBuffer9* pStreamData,
UINT OffsetInBytes,
UINT Stride
);
StreamNumber —Identifies the stream source to which we are
hooking the vertex buffer. In this topic we do not use multiple
streams; thus we always use stream zero.
pStreamData —A pointer to the vertex buffer that we want to
hook up to the stream
OffsetInBytes —An offset from the start of the stream,
measured in bytes, that specifies the start of the vertex data to
be fed into the rendering pipeline. To set this parameter to
something besides zero, check if your device supports it by
checking the D3DDEVCAPS2_STREAMOFFSET flag in the
D3DCAPS9 structure.
Stride —Size in bytes of each element in the vertex buffer
that we are attaching to the stream
For example, suppose vb is a vertex buffer that has been filled with
vertices of type Vertex :
_device->SetStreamSource( 0, vb, 0, sizeof( Vertex ) );
2.
Set the vertex format. This is where we specify the vertex format
of the vertices that we use in subsequent drawing calls.
_device->SetFVF( D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1 );
3.
Set the index buffer. If we are using an index buffer, we must set
the index buffer that is used in subsequent drawing operations.
Only one index buffer can be used at a time; therefore if you need
to draw an object with a different index buffer, you must switch to
the other. The following code sets an index buffer:
_device->SetIndices( _ib ); // pass copy of index buffer pointer
Search WWH ::




Custom Search