g_pd3dDevice->SetRenderState( D3DRS_FOGENABLE, true );
g_pd3dDevice->SetRenderState( D3DRS_FOGCOLOR, 0x007F7F7F );
g_pd3dDevice->SetRenderState( D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR );
g_pd3dDevice->SetRenderState( D3DRS_FOGSTART, (DWORD)0.5 );
g_pd3dDevice->SetRenderState( D3DRS_FOGEND, (DWORD)0.8 );
Fog problem
When I'm trying to turn on some linear fog, everything thing gets the fog color I've set (in this case, the whole screen gets gray) and if I try with D3DFOG_EXP or D3DFOG_EXP2 nothing is affected.
Here's the code I'm using:
What could possibly be wrong? Any suggestions?
EDIT: I'm sure my card support these kind of fogs (though it's an old TNT2) since it works perfectly in the MFCFog sample from the old SDK.
The problem is that FOGSTART and FOGEND are both set to 0, because (DWORD)0.5 == 0 and (DWORD)0.8 == 0.
For the render states taking a floatting point value, you must use something like:
For the render states taking a floatting point value, you must use something like:
// Casts a float into a DWORDDWORD FloatToDWORD(float val){ return *((DWORD*)(&val));}// ...g_pd3dDevice->SetRenderState( D3DRS_FOGSTART, FloatToDWORD(0.5f) );g_pd3dDevice->SetRenderState( D3DRS_FOGEND, FloatToDWORD(0.8f) );
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement