Microsoft DirectX 8.0 (C++)

Creating an Effect

The first step to creating an effect is to compile the effect. The following functions can be used to compile an effect.

The code example below uses the D3DXCompileEffectFromFileA function to load and compile the effect described in the file Water.sha.

LPD3DXBUFFER pCompiledEffect;
D3DXCompileEffectFromFile( "Water.sha", &pCompiledEffect, NULL );

The first parameter that D3DXCompileEffectFromFileA accepts is a pointer to an ANSI string that specifies the file from which to create the effect. The second parameter accepts the address of a pointer to an ID3DXBuffer interface. This buffer will contain the compiled effect. The final parameter that D3DXCompileEffectFromFileA accepts is the address of a pointer to an ID3DXBuffer interface. This buffer will contain returned ASCII error message. This example ignores the errors and sets this parameter to NULL.

After compiling an effect, use the D3DXCreateEffect function to obtain a pointer to an ID3DXEffect interface as shown in the code sample below.

ID3DXEffect * pEffect;
D3DXCreateEffect( g_d3dDevice, pCompiledEffect->GetBufferPointer(),
                  pCompiledEffect->GetBufferSize(), 0, &pEffect);
pCompiledEffect->Release();

If this function succeeds, then pEffect contains a valid pointer to ID3DXEffect interface. When finished with the ID3DXBuffer that stored the compiled effect, be sure to call the IUnknown::Release method to avoid a memory leak.