draw2dRectangle not working

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
acra
Posts: 3
Joined: Sat Nov 22, 2014 1:55 pm

draw2dRectangle not working

Post by acra »

Code: Select all

while (device->run())
    {
        tempReceiver->endEventProcess();
        mDriver->beginScene(true, true, video::SColor(255, 255, 0, 0));     
        mGuiEnv->drawAll();
        
 
        if (tempReceiver->isGuiUsed(GUI_ID_QUIT_BUTTON))
            return -1;
        else if (tempReceiver->isGuiUsed(GUI_ID_NEW_GAME_BUTTON))
        {
            mGuiEnv->clear();
            return (Screens::GAME);
        }
        else if (tempReceiver->isGuiUsed(GUI_ID_NEW_WINDOW_BUTTON))
        {
            mDriver->draw2DRectangle(SColor(100, 0, 0, 0), rect<s32>(0, 0, 640, 480), 0);   // << NOT DRAWING
            IGUIWindow* window = mGuiEnv->addWindow(
                rect<s32>(100 , 100  , 300 , 200 ),
                true, // modal?
                L"Test window");
            
        }   
        mDriver->endScene();
        tempReceiver->startEventProcess();
    }
and if change code to

Code: Select all

while (device->run())
    {
        tempReceiver->endEventProcess();
        mDriver->beginScene(true, true, video::SColor(255, 255, 0, 0));     
        mGuiEnv->drawAll();
        
        mDriver->draw2DRectangle(SColor(100, 0, 0, 0), rect<s32>(0, 0, 640, 480), 0);   // <<  DRAWING
        if (tempReceiver->isGuiUsed(GUI_ID_QUIT_BUTTON))
            return -1;
        else if (tempReceiver->isGuiUsed(GUI_ID_NEW_GAME_BUTTON))
        {
            mGuiEnv->clear();
            return (Screens::GAME);
        }
        else if (tempReceiver->isGuiUsed(GUI_ID_NEW_WINDOW_BUTTON))
        {
        
            IGUIWindow* window = mGuiEnv->addWindow(
                rect<s32>(100 , 100  , 300 , 200 ),
                true, // modal?
                L"Test window");
            
        }   
        mDriver->endScene();
        tempReceiver->startEventProcess();
    }
it's okay but FOREVER.
What have I done wrong?
CuteAlien
Admin
Posts: 9693
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: draw2dRectangle not working

Post by CuteAlien »

The screen is redrawn every frame. If you draw something only 1 frame it's gone so fast that you might miss it (depends on your framerate). If you want it to be drawn for a certain time then you have to work with time. For example when your GUI_ID_NEW_WINDOW_BUTTON is used (whatever used means) then set a variable to the current time (let's call the variable for now buttonClickedTime). And in your main-loop for drawing you first get the current time. And then you check if currentTime-buttonClickedTime < amount_of_time_to_draw_this. Where amount_of_time_to_draw_this can be some constant (for example 1000ms to draw the rect for 1 second). And only draw if that condition is true.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply