Use the following steps to enable pixel fog in your application:
To enable pixel fog
The following example shows what these steps might look like in code:
// For brevity, error values in this example are not checked
// after each call. A real-world application should check
// these values appropriately.
//
// For the purposes of this example, g_lpDevice is a valid
// pointer to an IDirect3DDevice3 interface.
void SetupPixelFog(DWORD dwColor, DWORD dwMode)
{
float fStart = 0.5f, // for linear mode
fEnd = 0.8f,
fDensity = 0.66; // for exponential modes
// Enable fog blending.
g_lpDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE);
// Set the fog color.
g_lpDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, dwColor);
// Set fog parameters.
if(D3DFOG_LINEAR == dwMode)
{
g_lpDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, dwMode);
g_lpDevice->SetRenderState(D3DRENDERSTATE_FOGTABLESTART, *(DWORD *)(&fStart));
g_lpDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEEND, *(DWORD *)(&fEnd));
}
else
{
g_lpDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, dwMode);
g_lpDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEDENSITY, *(DWORD *)(&fDensity));
}
}
Note Some fog parameters are required as floating-point values, even though the IDirect3DDevice3::SetRenderState method only accepts DWORD values in the second parameter. The preceding example provides the floating-point values to SetRenderState without data translation by casting the addresses of the floating-point variables as DWORD pointers, then dereferencing them.