Microsoft DirectX 8.0 (Visual Basic) |
The code example below shows how to implement fixed-function vertex tweening after a vertex type and declaration are set.
' Variables used for this example Dim handle As Long Dim TweenFactor As Float TweenFactor = 0.3
The first step is to use the Direct3DDevice8.CreateVertexShader method to create a vertex shader, as shown in the code example below.
Call d3dDevice.CreateVertexShader(decl, ByVal 0, handle, 0)
The first parameter accepted by CreateVertexShader is a vector shader declaration. This example uses the declaration declared in the topic Setting Vertex Declaration. The second parameter accepts a vertex shader function array. This example does not use a vertex shader function, so this parameter is set to ByVal 0. The third parameter accepts a vertex shader handle representing the returned vertex. The fourth parameter specifies the usage controls for the vertex shader. You can use the D3DUSAGE_SOFTWAREPROCESSING flag to indicate that the vertex shader should use software vertex processing. This example sets this parameter to zero to indicate that vertex processing should be done in hardware.
The next step is to set the current vertex shader by calling the Direct3DDevice8.SetVertexShader method as shown in the code example below.
Call d3dDevice.SetVertexShader(handle)
SetVertexShader accepts a handle to a vertex shader. The value for this parameter can be a handle returned by CreateVertexShader or an FVF code. This example uses the handle returned from CreateVertexShader called in the last step.
The next step is to set the current render state to enable vertex tweening, set the tween factor, and set the stream source. The code example below uses Direct3DDevice8.SetRenderState and Direct3DDevice8.SetStreamSource to accomplish this.
Call d3dDevice.SetRenderState(D3DRS_VERTEXBLEND, D3DVBF_TWEENING) Call d3dDevice.SetRenderState(D3DRS_TWEENFACTOR, TweenFactor) Call d3dDevice.SetStreamSource(0 ,vb, 12*Len(vb(0))
If you have more than one stream specified for the current vertex shader, you need to call SetStreamSource for each stream that will be used for the tweening effect. At this point, vertex tweening is enabled. A call to any rendering function automatically has vertex tweening applied to it.