Microsoft DirectX 8.0 (C++) |
Use the following steps to enable pixel fog in your application.
To enable pixel fog in a C++ application
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_pDevice is a valid // pointer to an IDirect3DDevice8 interface. void SetupPixelFog(DWORD Color, DWORD Mode) { float Start = 0.5f, // For linear mode End = 0.8f, Density = 0.66; // For exponential modes // Enable fog blending. g_pDevice->SetRenderState(D3DRS_FOGENABLE, TRUE); // Set the fog color. g_pDevice->SetRenderState(D3DRS_FOGCOLOR, Color); // Set fog parameters. if(D3DFOG_LINEAR == Mode) { g_pDevice->SetRenderState(D3DRS_FOGTABLEMODE, Mode); g_pDevice->SetRenderState(D3DRS_FOGSTART, *(DWORD *)(&Start)); g_pDevice->SetRenderState(D3DRS_FOGEND, *(DWORD *)(&End)); } else { g_pDevice->SetRenderState(D3DRS_FOGTABLEMODE, Mode); g_pDevice->SetRenderState(D3DRS_FOGDENSITY, *(DWORD *)(&Density)); } }
Note Some fog parameters are required as floating-point values, even though the IDirect3DDevice8::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, and then dereferencing them.