How can I make an external function that would be called from within 'while loop' and draw loaded textures on screen. It seems that I cannot call draw2dImage function outside that loop. Even when using BeginScene and EndScene.
My device variable is global - so should't it work in every function?
Drawing function outside main function
-
Guest
I just started programming with irrlicht but I think I have an idea whats your problem about.
You can call these special draw routines in other places than in the while (device). But if its not in the device its drawn once for a very very short time even if you set begin and end scene.
If you have a class and in this class you e.g. want to draw a button you have to do this in this class. but there you have to say what the parent of the button is.
m_pDevice->getGUIEnvironment()->addButton (irr::core::rect<irr::s32>(100,30,180,53), m_pWindow, BTNNAME_LOAD, L"Laden");
m_pWindow is the parent in this case. Now if you have a draw routine in this class it draws the parent and its child (Window and Button). But that is not enough. Now you have to write in the while (device) a call of the draw routine of this class.
while (s_pDevice->run())
{
Video->beginScene(true, true, irr::video::SColor(0, 100, 100, 100));
pMyScreen->Draw(); //this is the object pointer of your class
smgr->drawAll();
GuiEnv->drawAll();
Video->endScene();
}
Now the button shows up in the application. The same should be able with the image.
You can call these special draw routines in other places than in the while (device). But if its not in the device its drawn once for a very very short time even if you set begin and end scene.
If you have a class and in this class you e.g. want to draw a button you have to do this in this class. but there you have to say what the parent of the button is.
m_pDevice->getGUIEnvironment()->addButton (irr::core::rect<irr::s32>(100,30,180,53), m_pWindow, BTNNAME_LOAD, L"Laden");
m_pWindow is the parent in this case. Now if you have a draw routine in this class it draws the parent and its child (Window and Button). But that is not enough. Now you have to write in the while (device) a call of the draw routine of this class.
while (s_pDevice->run())
{
Video->beginScene(true, true, irr::video::SColor(0, 100, 100, 100));
pMyScreen->Draw(); //this is the object pointer of your class
smgr->drawAll();
GuiEnv->drawAll();
Video->endScene();
}
Now the button shows up in the application. The same should be able with the image.
Why do you need to do this? You create an instance of the button when you use the code that the Guest says there, it is registered in the node list and lined up to be drawn if node->setVisible(true), it is true by default so unless you change it the image or button will be drawn. By putting this function in the while loop you are wasting cycles constantly updating the same information into the node.
Code: Select all
irr::gui::IGUIButton* button = guiEnv->addButton() // Create button
button->setVisible(true); // Don't need to do this, just an example. It defaults to true
while (device->run())
{
driver->beginScene(true, true, irr::video::SColor(0, 100, 100, 100));
smgr->drawAll();
guiEnv->drawAll();
driver->endScene();
}
device->drop();