Microsoft DirectX 8.1 (Visual Basic) |
Microsoft® Direct3D® has a simplified programming model for using the fixed function vertex processing pipeline with a single input stream, providing functionality very similar to that of previous DirectX releases. In this case, the vertex shader consists of a flexible vertex format (FVF) code that is passed in place of a vertex shader handle when setting the current vertex shader. The handle space for vertex shaders is managed by the run-time library so that handles that are valid FVF codes are reserved for this usage.
Setting an FVF code as the current vertex shader causes the vertex processing to load from stream zero only, and to interpret the vertex elements as defined in the FVF code.
The following code example illustrates how to use an FVF code as a vertex shader in your C++ application.
First, define a structure for your custom vertex type and initialize the vertices. In this case, three vertices are initialized for rendering a triangle.
' This code example assumes that d3dDeviceis a valid reference ' to a Direct3DDevice8 object. Private Type CUSTOMVERTEX x As Single 'x in screen space y As Single 'y in screen space z As Single 'Normalized z rhw As Single 'Normalized z rhw color As Long 'Vertex color End Type Const D3DFVF_CUSTOMVERTEX = (D3DFVF_XYZRHW Or D3DFVF_DIFFUSE) Dim Vertices(2) As CUSTOMVERTEX Dim VertexSizeInBytes As Long VertexSizeInBytes = Len(Vertices(0)) With Vertices(0): .x = 150: .y = 50: .z = 0.5: .rhw = 1: .color = &HFFFF0000: End With With Vertices(1): .x = 250: .y = 250: .z = 0.5: .rhw = 1: .color = &HFF00FF00: End With With Vertices(2): .x = 50: .y = 250: .z = 0.5: .rhw = 1: .color = &HFF00FFFF: End With
Then, render the primitive using stream zero.
sizeOfVertex = Len(v) d3dDevice.SetStreamSource 0, g_VB, sizeOfVertex d3dDevice.SetVertexShader D3DFVF_CUSTOMVERTEX d3dDevice.DrawPrimitive D3DPT_TRIANGLELIST, 0, 1
For more information, see Vertex Shaders.