Fog doesn't work

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Sard
Posts: 8
Joined: Tue Dec 09, 2008 1:19 pm

Fog doesn't work

Post by Sard »

Been poking around, but I can't seem to get the fog to work.

Code: Select all

#include <irrlicht.h>
#include <iostream>


using namespace irr;

int main()
{
        // create device and exit if creation failed

IrrlichtDevice* device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(1024, 768), 
      32, false, false, false);

        if (device == 0)
                return 1; // could not create selected driver.
////////////////////////////////////////////////////////////////////////////////////                

        video::IVideoDriver* driver = device->getVideoDriver();
        scene::ISceneManager* smgr = device->getSceneManager();
            



        scene::IAnimatedMesh* TERRAIN = smgr->getMesh("data/terrain.obj");
        
        scene::ISceneNode* node = 0;
        
        if (TERRAIN)
                node = smgr->addOctTreeSceneNode(TERRAIN->getMesh(0), 0, 0, 0);
        if (node)
                node->setPosition(core::vector3df(0,0,0));
                

  
TERRAIN->setMaterialFlag(video::EMF_LIGHTING, true);
TERRAIN->setMaterialFlag(video::EMF_ZWRITE_ENABLE, true);
TERRAIN->setMaterialFlag(video::EMF_FOG_ENABLE, true);


[b]driver->setFog(video::SColor(0,138,125,81), false, 0.1f, 255.0f, 1.0f, false, true);[/b]


	smgr->addSkyBoxSceneNode(
		driver->getTexture("data/sboxnode/irrlicht2_up.jpg"),
		driver->getTexture("data/sboxnode/irrlicht2_dn.jpg"),
		driver->getTexture("data/sboxnode/irrlicht2_lf.jpg"),
		driver->getTexture("data/sboxnode/irrlicht2_rt.jpg"),
		driver->getTexture("data/sboxnode/irrlicht2_ft.jpg"),
		driver->getTexture("data/sboxnode/irrlicht2_bk.jpg"));

	scene::ILightSceneNode* light1 =
		smgr->addLightSceneNode(0, core::vector3df(-2000,2000,0),
		video::SColorf(1.0f, 1.0f, 1.0f, 0.0f), 800.0f);

smgr->addCameraSceneNodeFPS();
device->getCursorControl()->setVisible(false);
    
        int lastFPS = -1;

        while(device->run())
        {
                if (device->isWindowActive())
                {
                        driver->beginScene(true, true, video::SColor(255,255,255,255));
                        smgr->drawAll();
                        driver->endScene();

                        int fps = driver->getFPS();

                        if (lastFPS != fps)
                        {
                                core::stringw str = L"Irr_project [";
                                str += driver->getName();
                                str += "] FPS:";
                                str += fps;

                                device->setWindowCaption(str.c_str());
                                lastFPS = fps;
                        }
                }
                else
                        device->yield();
        }
        
        device->drop();
        return 0;
}
I've tried different values and pretty much everything I know, which ain't a lot since I'm a newbie. Any ideas?
sjb
Posts: 19
Joined: Tue Dec 23, 2008 10:35 pm
Location: Sweden

Post by sjb »

You must enable fog on the scenenodes that you want to be affected by fog.

node->setMaterialFlag(video::EMF_FOG_ENABLE, true);
Post Reply