Skip to main content
gamedev.net
🔒 Locked

Fog problem

Started by peter86 1 reply 1k views
Original Post
peter86
peter86
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:

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 );




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.
Aldenar
Aldenar
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:

// 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) );

peter86
peter86
Thanks, I've fixed it now. I had to set the range a little wider to be able to see anything too :-)

[Edited by - peter86 on January 4, 2005 5:14:47 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.