Microsoft DirectX 8.0 (C++)

Fixed-Function Tweening

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
DWORD handle;
float TweenFactor = 0.3f;

The first step is to use the IDirect3DDevice8::CreateVertexShader method to create a vertex shader, as shown in the code example below.

m_d3dDevice->CreateVertexShader( decl, NULL, &handle, 0 );

The first parameter accepted by CreateVertexShader is a pointer to a vector shader declaration. This example uses the declaration declared in the topic Setting Vertex Declaration. The second parameter accepts a pointer to a vertex shader function array. This example does not use a vertex shader function, so this parameter is set to NULL. The third parameter accepts a pointer to 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 IDirect3DDevice8::SetVertexShader method as shown in the code example below.

m_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 IDirect3DDevice8::SetRenderState and IDirect3DDevice8::SetStreamSource to accomplish this.

m_d3dDevice->SetRenderState( D3DRS_VERTEXBLEND, D3DVBF_TWEENING );
m_d3dDevice->SetRenderState( D3DRS_TWEENFACTOR, *(DWORD*) &TweenFactor );
m_d3dDevice->SetStreamSource( 0 ,vb, 12*sizeof(float));

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.