Use the D3DXCreateEffectFromFile
function.
The parameter list is a bit daunting, but most of the parameters are optional and can support null values. Do note, however, the comment for the flags
parameter:
If pSrcFile contains a text effect, flags can be a combination of
D3DXSHADER Flags and D3DXFX flags; otherwise, pSrcFile contains a
binary effect and the only flags honored are D3DXFX flags. The
Direct3D 10 HLSL compiler is now the default. See Effect-Compiler Tool
for details.
Typical usage would be:
LPD3DXEFFECT effect = nullptr;
LPD3DXBUFFER errors = nullptr;
HRESULT result = D3DXCreateEffectFromFile(
direct3DDevice,
"Path/To/Your/Effect.fx",
nullptr,
nullptr,
0,
nullptr,
&effect,
&errors
)
If the HRESULT
isn't successful, compilation errors can be recovered from the errors
buffer (it's just a string; you can case the void *
returned from GetBufferPointer
).