www.xbdev.net
xbdev - software development
Thursday March 28, 2024
home | contact | Support | DirectX.. Its doing all the hard work for us...
>>

FOG

by bkenwright@xbdev.net



 

So how do we go about adding fog to our DirectX game or application?  Well you can accomplish it with a relatively few lines of code, as shown:

 

Code Snippet

// IDirect3DDevice8* pd3dDevice

 

void Fog()

{

      DWORD dwColour = 0xff666666;

      float start = 20.5f;

      float end  = 50.8f;

 

      float density = 0.66f;  // 0.0 to 1.0

 

 

      pd3dDevice->SetRenderState(D3DRS_FOGENABLE, TRUE);

      pd3dDevice->SetRenderState(D3DRS_FOGCOLOR, dwColour);

 

      if(true)

      {

            pd3dDevice->SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);

            pd3dDevice->SetRenderState(D3DRS_FOGSTART, *(DWORD*)(&start));

            pd3dDevice->SetRenderState(D3DRS_FOGEND,   *(DWORD*)(&end));

      }

      else

      {

            pd3dDevice->SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_EXP);

            pd3dDevice->SetRenderState(D3DRS_FOGDENSITY, *(DWORD*)(&density));

      }

 

}

 

Where there are two main types of fog - linear and exponential.  As above I've shown how you switch fog on, and with the little if(..)else(..) statement you can choose whether you what type of fog you want.

 

    D3DFOG_NONE       0

    D3DFOG_EXP          1

    D3DFOG_EXP2        2

    D3DFOG_LINEAR   3

 

 

 

 

 

 

 

 

 

 

 

 

 

 
Advert (Support Website)

 
 Visitor:
Copyright (c) 2002-2024 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.