Lighting: Blank White Screen

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
KarneeKarnay
Posts: 8
Joined: Mon Dec 19, 2011 3:48 pm

Lighting: Blank White Screen

Post by KarneeKarnay »

Fairly new to using the engine, so recently I decided to just go nuts and see what I could do. One of the things I'm doing is experimenting with the lights available. I got Ambient lighting after a few failures, but I can't get the Spot Light to work. When I add it to the code, the screen becomes completely white. A copy of the spotlight code and my code below that. Any ideas?

Code: Select all

        ILightSceneNode* mySpotLight = smgr->addLightSceneNode();
        mySpotLight->setPosition(vector3df(0.0f, 10.0f, 0.0f));
        SLight spotLightData;
        spotLightData.Type = ELT_SPOT;
        spotLightData.DiffuseColor = SColor(255, 255, 0, 0);
        spotLightData.OuterCone = 100;
        spotLightData.InnerCone = 10;
        mySpotLight->setLightData(spotLightData);
        while(device->run())
        {
                mySpotLight->setRotation(vector3df(0.0f, 0.0f, 0.0f));
        }
 


My code:

Code: Select all

#include <irrlicht.h>
 
using namespace irr;
 
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
 
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
 
class MyEventReceiver : public IEventReceiver
{
public:
        
        virtual bool OnEvent(const SEvent& event)
        {
                        if (event.EventType == EET_KEY_INPUT_EVENT)
                                KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
                        
                        return false;
                }
 
        
        virtual bool IsKeyDown(EKEY_CODE keyCode) const
        {
                        return KeyIsDown[keyCode];
        }
        
        MyEventReceiver()
        {
                        for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
                                KeyIsDown[i] = false;
        }
 
private:     
        
        bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
 
 
 
 
int main()
{
        MyEventReceiver receiver;
 
        IrrlichtDevice *device =
                createDevice( EDT_OPENGL, dimension2d<u32>(640, 480), 16,
                        false, false, false, &receiver);
 
        if (!device)
                return 1;
 
        
 
        device->setWindowCaption(L"CI2511 Assignment Part 1");
        IVideoDriver* driver = device->getVideoDriver();
        ISceneManager* smgr = device->getSceneManager();
        IGUIEnvironment* guienv = device->getGUIEnvironment();
 
        ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
        camera->setPosition(vector3df(15.0,8.4,-59.6));  
        
        device->getCursorControl()->setVisible(false);
 
        ISceneNode* node1=smgr ->addCubeSceneNode();
        ISceneNode* node2=smgr ->addCubeSceneNode();
        ISceneNode* node3=smgr ->addSphereSceneNode();
        ISceneNode* node4=smgr ->addSphereSceneNode();
 
 
        if(node1)
        {
                node1->setMaterialFlag(EMF_LIGHTING, true);
                node1->setMaterialTexture(0, driver->getTexture("Bgtext.png"));
        }
 
        node1->setPosition(core::vector3df(0,0,0));
 
        if(node2)
        {
                node2->setMaterialFlag(EMF_LIGHTING, true);
                node2->setMaterialTexture(0, driver->getTexture("Bgtext.png"));
        }
 
        node2->setPosition(vector3df(20,20,0));
 
        if(node3)
        {
                node3->setMaterialFlag(EMF_LIGHTING, true);
                node3->setMaterialTexture(0, driver->getTexture("BgBtext.png"));
        }
 
        node3->setPosition(core::vector3df(0,15,0));
 
        if(node4)
        {
                node4->setMaterialFlag(EMF_LIGHTING, true);
                node4->setMaterialTexture(0, driver->getTexture("BgBtext.png"));
        }
 
        node4->setPosition(vector3df(20,35,0));
        
        
        IAnimatedMeshSceneNode* anms =
                smgr->addAnimatedMeshSceneNode(smgr->getMesh("ninja.b3d"));
        
        if (anms)
        {
                ISceneNodeAnimator* anim =
                        smgr->createFlyStraightAnimator(vector3df(100,0,60),
                        vector3df(-100,0,60), 3500, true);
                
                if (anim)
                {
                        anms->addAnimator(anim);
                        anim->drop();
                }
                
                anms->setMaterialFlag(EMF_LIGHTING, true);
                
                anms->setFrameLoop(0, 13);
                anms->setAnimationSpeed(15);
                
                
                anms->setScale(vector3df(2.f,2.f,2.f));
                anms->setRotation(vector3df(0,-90,0));
                anms->setMaterialTexture(0, driver->getTexture("sydney.bmp"));
        }
 
        IAnimatedMeshSceneNode* anms2 =
                smgr->addAnimatedMeshSceneNode(smgr->getMesh("faerie.md2"));
        
        if (anms2)
        {
                ISceneNodeAnimator* anim =
                        smgr->createFlyStraightAnimator(vector3df(0,0,130),
                        vector3df(200,100,130), 3500, true);
                
                if (anim)
                {
                        anms2->addAnimator(anim);
                        anim->drop();
                }
                
                anms2->setMaterialFlag(EMF_LIGHTING, true);
                
                anms2->setFrameLoop(0, 13);
                anms2->setAnimationSpeed(10);
                anms2->setMD2Animation(EMAT_JUMP);
                
                anms2->setScale(vector3df(2.f,2.f,2.f));
                anms2->setRotation(vector3df(0,0,0));
                anms2->setMaterialTexture(0, driver->getTexture("Faerie5.bmp"));
        }
 
        IAnimatedMeshSceneNode* anms3 =
                smgr->addAnimatedMeshSceneNode(smgr->getMesh("dwarf.x"));
        
        if (anms3)
        {
                ISceneNodeAnimator* anim =
                        smgr->createFlyStraightAnimator(vector3df(0,0,290),
                        vector3df(0,0,180), 3500, true);
                
                if (anim)
                {
                        anms3->addAnimator(anim);
                        anim->drop();
                }
                
                anms3->setMaterialFlag(EMF_LIGHTING, true);
                
                anms3->setFrameLoop(0, 13);
                anms3->setAnimationSpeed(8);
                anms3->setMD2Animation(EMAT_STAND);
                
                anms3->addShadowVolumeSceneNode();
                anms3->setScale(vector3df(2.f,2.f,2.f));
                anms3->setRotation(vector3df(0,0,0));
                anms3->setMaterialTexture(0, driver->getTexture("dwarf.jpg"));
        }
 
        smgr->setShadowColor(SColor(150, 0, 0, 0));
        smgr->setAmbientLight(SColor(100, 100, 100, 100));
 
        ILightSceneNode* mySpotLight = smgr->addLightSceneNode();
        mySpotLight->setPosition(vector3df(0.0f, 10.0f, 0.0f));
        SLight spotLightData;
        spotLightData.Type = ELT_SPOT;
        spotLightData.DiffuseColor = SColor(255, 255, 0, 0);
        spotLightData.OuterCone = 100;
        spotLightData.InnerCone = 10;
        mySpotLight->setLightData(spotLightData);
        while(device->run())
        {
                mySpotLight->setRotation(vector3df(0.0f, 0.0f, 0.0f));
        }
 
        //ILightSceneNode* light1 = smgr->addLightSceneNode( 0, vector3df(0,400,-200), SColorf(0.3f,0.3f,0.3f), 1.0f, 1 ); 
 
        wchar_t tmp[1000];
 
        int lastFPS = -1;
 
        u32 then = device->getTimer()->getTime();
        const f32 MOVEMENT_SPEED = 5.f;
 
        double i=0.5;
 
        while(device->run())
        {
                const u32 now = device->getTimer()->getTime();
                const f32 frameDeltaTime = (f32)(now - then) / 1000.f;
                then = now;
                                
                vector3df nodePosition = node3->getPosition();
 
        if(receiver.IsKeyDown(KEY_KEY_W))
                        nodePosition.Y += MOVEMENT_SPEED * frameDeltaTime;
                
                else if(receiver.IsKeyDown(KEY_KEY_S))
                        nodePosition.Y -= MOVEMENT_SPEED * frameDeltaTime;
                
                if(receiver.IsKeyDown(KEY_KEY_A))
                        nodePosition.X -= MOVEMENT_SPEED * frameDeltaTime;
                
                else if(receiver.IsKeyDown(KEY_KEY_D))
                        nodePosition.X += MOVEMENT_SPEED * frameDeltaTime;
 
                node3->setPosition(nodePosition);
 
                vector3df nodePosition2 = node4->getPosition();
 
        if(receiver.IsKeyDown(KEY_KEY_1))
                        nodePosition2.Y += MOVEMENT_SPEED * frameDeltaTime;
                
                else if(receiver.IsKeyDown(KEY_KEY_2))
                        nodePosition2.Y -= MOVEMENT_SPEED * frameDeltaTime;
                
                if(receiver.IsKeyDown(KEY_KEY_3))
                        nodePosition2.X -= MOVEMENT_SPEED * frameDeltaTime;
                
                else if(receiver.IsKeyDown(KEY_KEY_4))
                        nodePosition2.X += MOVEMENT_SPEED * frameDeltaTime;
 
                node4->setPosition(nodePosition2);
                
                driver->beginScene(true, true, SColor(255,100,101,140));
                
                smgr->drawAll();
                guienv->drawAll();
 
                /*int fps = driver->getFPS();
 
                if (lastFPS != fps)
                {
                        swprintf(tmp, 1000, L"(%3.1f,%3.1f,%3.1f)",  camera->getTarget().X,
                                camera->getTarget().Y, camera->getTarget().Z);
                        
                        device->setWindowCaption(tmp);
                        lastFPS = fps;
                }
                */
 
                node3->setRotation(vector3df(0,0,i));
                node4->setRotation(vector3df(0,0,i));
                i+= 0.2;
 
                driver->endScene();
        }
 
        device->drop();
 
        return 0;
}
 
 
 
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Lighting: Blank White Screen

Post by hybrid »

If you scale a node, you hav to enable EMF_NORMALIZE_NORMALS is lighing is also applied. also check the lighting material values (emissive, specular, etc.)
Bl00drav3n
Posts: 48
Joined: Sun Apr 22, 2012 11:55 pm
Location: Vienna
Contact:

Re: Lighting: Blank White Screen

Post by Bl00drav3n »

KarneeKarnay wrote:

Code: Select all

while(device->run())
{
    mySpotLight->setRotation(vector3df(0.0f, 0.0f, 0.0f));
}
 
Smells like an infinite loop without any drawing occuring.
KarneeKarnay
Posts: 8
Joined: Mon Dec 19, 2011 3:48 pm

Re: Lighting: Blank White Screen

Post by KarneeKarnay »

hybrid wrote:If you scale a node, you hav to enable EMF_NORMALIZE_NORMALS is lighing is also applied. also check the lighting material values (emissive, specular, etc.)
Would it be possible for you to indicate in my code where that needs to go? Still a noob to this.
Bl00drav3n wrote:
KarneeKarnay wrote:

Code: Select all

while(device->run())
{
    mySpotLight->setRotation(vector3df(0.0f, 0.0f, 0.0f));
}
 
Smells like an infinite loop without any drawing occuring.
I suspect the same thing as well, but I'm pretty sure I need a value in there and anything I try fails. Without this line the spotlight doesn't appear.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Lighting: Blank White Screen

Post by serengeor »

That just looks illogical. A loop (infinite) that is used to set a constant value.
Working on game: Marrbles (Currently stopped).
Bl00drav3n
Posts: 48
Joined: Sun Apr 22, 2012 11:55 pm
Location: Vienna
Contact:

Re: Lighting: Blank White Screen

Post by Bl00drav3n »

I suspect that the spotlight is not aligned to illuminate your scene. The light's position is set to (0,10,0) and I think it looks along the negative z-axis as default value. Try

Code: Select all

mySpotLight->setPosition(vector3df(0.0f, 10.0f, 0.0f));
mySpotLight->setRotation(vector3df(+/-90.f, 0.0f, 0.0f)); // not sure if + or -, i suspect the minus sign though
instead of the infinite loop.
Post Reply