Jump to content
  • Advertisement
Sign in to follow this  
peter86

Fog problem

This topic is 5035 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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 DWORD
DWORD FloatToDWORD(float val)
{
return *((DWORD*)(&val));
}

// ...

g_pd3dDevice->SetRenderState( D3DRS_FOGSTART, FloatToDWORD(0.5f) );
g_pd3dDevice->SetRenderState( D3DRS_FOGEND, FloatToDWORD(0.8f) );


Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!