Microsoft DirectX 8.0 (Visual Basic) |
This topic shows the steps necessary to initialize and use vertices that have a position, diffuse color, specular color, and texture coordinates.
The first step is to define the custom vertex type and FVF as shown in the code example below.
Private Type LVertex x As Single y As Single z As Single diffuse As Long specular As Long tu As Single tv As Single End Type Const VertexFVF = (D3DFVF_XYZ Or D3DFVF_DIFFUSE Or _ D3DFVF_SPECULAR Or D3DFVF_TEX1)
The next step is to create a vertex with enough room for four vertices buffer by using the Direct3DDevice8.CreateVertexBuffer method as shown in the code example below.
Set BigSquareVB = m_D3DDevice.CreateVertexBuffer( _ 4*len(LVertex), VertexFVF, _ D3DUSAGE_WRITEONLY, _ D3DPOOL_DEFAULT)
The next step is to manipulate the values for each vertex as shown in the code example below.
Dim v(4) As LVertex Call BigSquareVB.Lock(0, 0, v(), 0) v(0).x = 0.0: v(0).y = 10.0: v(0).z = 10.0 v(0).diffuse = &HFFFF0000; v(0).specular = &HFF00FF00; v(0).tu = 0.0: v(0).tv = 0.0 v(1).x = 0.0: v(1).y = 0.0: v(1).z = 10.0 v(1).diffuse = &HFF00FF00; v(1).specular = &HFF00FFFF; v(1).tu = 0.0: v(1).tv = 0.0 v(2).x = 10.0: v(2).y = 10.0: v(2).z = 10.0 v(2).diffuse = &HFFFF00FF; v(2).specular = &HFF000000; v(2).tu = 0.0: v(2).tv = 0.0 v(3).x = 0.0: v(3).y = 10.0: v(3).z = 10.0 v(3).diffuse = &HFFFFFF00; v(3).specular = &HFFFF0000; v(3).tu = 0.0: v(3).tv = 0.0 BigSquareVB.Unlock
The vertex buffer has been initialized and is ready to render. The following code example shows how to use the legacy FVF to draw a square.
Call m_D3DDevice.SetVertexShader(VertexFVF) Call m_D3DDevice.SetStreamSource(0, BigSquareVB, 4*len(LVertex)) Call m_D3DDevice.DrawPrimitive(D3DPT_TRIANGLESTRIP, 0 ,2)
Passing an FVF to the Direct3DDevice8.SetVertexShader method tells Direct3D that a legacy FVF is being used and that stream 0 is the only valid stream.