Page 1 of 1

Image

Posted: Sat May 13, 2006 9:19 pm
by German_man
Jsut a quick question i didn;t see in the tutorials:

i made a nice little title screen in paint and was wodnering how i import it into Irrlicht and then how to display it?

Posted: Sat May 13, 2006 9:30 pm
by andrei25ni
Well, if you made it in Paint it must be an image. And displaying of images IS covered by tutorials. For example the Irrlicht logo.

Posted: Sat May 13, 2006 9:32 pm
by German_man
heh i guess your right, weird i didnt make the connection to what i wanted to do and that irrlicht logo tutorial >_<

Posted: Sat May 13, 2006 9:55 pm
by German_man
ok cool got it on there with

device->getGUIEnvironment()->addImage(
driver->getTexture("media/Title_Screen.jpg"),
core::position2d<s32>(0,0));

(its in the main loop if it makes any difference)

but my question now is what is the command to remove it, i got i tal set up to
remove the image when the enter key is pressed, but i don't know hte actually command to remove the image. Anyone know what that command is?

Posted: Sun May 14, 2006 2:12 am
by andrei25ni
Actually, I had this problem some time ago, but unfortunately I didn't found a solution. But there are some paralel answers around here on this forum, do a search.

Posted: Sun May 14, 2006 8:16 am
by drac_gd
try
IGUIImage* m_pMyImage;

m_pMyImage = device->getGUIEnvironment()->addImage(
driver->getTexture("media/Title_Screen.jpg"),
core::position2d<s32>(0,0));



then

m_pMyImage ->setVisible(false);

to make invisible or

m_pMyImage->remove();

to remove it

Just a suggestion.. you may want to get IrrWizird an make a project and see how it does things :)

Posted: Sun May 14, 2006 3:32 pm
by andrei25ni

Code: Select all

m_pMyImage ->setVisible(false);

to make invisible or

m_pMyImage->remove();

to remove it 
unfortunately that will not work.

Posted: Sun May 14, 2006 3:59 pm
by drac_gd
could you explain more about it not working.
It works in IrrWizard CMenuState and I did a small test to make sure.
If it doesnt work for you then maybe something else is wrong. Is your IGUIImage* pointer global or part of a class that is not destroyed so that it is valid after the addImage function is called?.

Posted: Sun May 14, 2006 9:52 pm
by German_man
i figured out a way around hte problem at least. I guess irrlicht has 2 ways of laoding 2d images.. the 1 i used from the tutorials was about how to put the irrlicht logo on it.

device->getGUIEnvironment()->addImage(
driver->getTexture("../../media/irrlichtlogoalpha2.tga"),
core::position2d<s32>(10,10));

i assume this way was created to place logo's, so there was no need to remove htem.

So i tried the other way, i used it like i was creating a 2d game:

loaded it b4 the main loop:

video::ITexture* titleScreen = driver->getTexture("media/Title_Screen.jpg");


then in the mainloop it looks like:

if (titlescreen == 1) {
driver->draw2DImage(titleScreen, core::position2d<s32>(0,0),
core::rect<s32>(0,0,1024,768), 0,
video::SColor(255,255,255,255), false);
}

and when i press enter it makes titlescreen equal to 0 and it no longers displays it.

I assume this is because the first method, for the logo just has it build into the GUI, where as the second method updates it every loop of the game. Hope that helps any1 out and htank you all for your sugestions =]

Posted: Mon May 15, 2006 12:07 am
by andrei25ni
So, you figured it out by yourself ! Congratulations ! I'll try your solution.

Posted: Sat Feb 27, 2010 4:07 pm
by digoxy
drac_gd<-Thank You.

Looked for hours for this little bit of information. It seems, I was drawing this in the main run "if" conditions, and this little jewel "visable" works wonderful.

digz..

Posted: Sat Feb 27, 2010 5:24 pm
by sudi
are you kidding???
IGUIEnvironment::addImage is meant for what you want but, you are not supposed to call that function every frame. just once to add the image. after that you can alter its state. example:

Code: Select all

#include <irrlicht.h>
using namespace irr;
class Receiver : public IEventReceiver
{
public:
    gui::IGUIElement* Element;
    bool OnEvent(const SEvent& event)
    {
        if (event.EventType == EET_KEY_INPUT_EVENT)
        {
            if (event.KeyInput.Key == KEY_KEY_S)
                Element->setVisible(true);
            else if (event.KeyInput.Key == KEY_KEY_H)
                Element->setVisible(false);
        }
    }
};
int main(int argc, char* argv[])
{
    /*
    CMyApp app(argc, argv);
    app.Init();
    app.registerProcess();
    app.Run();
    */
    IrrlichtDevice *device = createDevice(video::EDT_OPENGL, core::dimension2d<u32>(640,480));
    video::IVideoDriver* driver = device->getVideoDriver();
    gui::IGUIEnvironment* gui = device->getGUIEnvironment();

    Receiver reciever;

    reciever.Element = gui->addImage(driver->getTexture("media/irrlichtlogoalpha2.tga"), core::position2d<s32>(10,10));

    device->setEventReceiver(&reciever);

    while (device->run() && driver)
    {
        driver->beginScene(true, true, video::SColor(255,0,0,255));
        gui->drawAll();
        driver->endScene();
    }
    device->drop();
    return 0;
}
pressing s makes the element visible and pressing h hides it.
you could also call remove but then u should set the pointer to zero.