Image

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
German_man
Posts: 16
Joined: Sat May 06, 2006 4:36 am

Image

Post 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?
andrei25ni
Posts: 326
Joined: Wed Dec 14, 2005 10:08 pm

Post 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.
German_man
Posts: 16
Joined: Sat May 06, 2006 4:36 am

Post 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 >_<
German_man
Posts: 16
Joined: Sat May 06, 2006 4:36 am

Post 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?
andrei25ni
Posts: 326
Joined: Wed Dec 14, 2005 10:08 pm

Post 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.
drac_gd
Posts: 132
Joined: Sun Apr 09, 2006 8:43 pm

Post 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 :)
andrei25ni
Posts: 326
Joined: Wed Dec 14, 2005 10:08 pm

Post by andrei25ni »

Code: Select all

m_pMyImage ->setVisible(false);

to make invisible or

m_pMyImage->remove();

to remove it 
unfortunately that will not work.
drac_gd
Posts: 132
Joined: Sun Apr 09, 2006 8:43 pm

Post 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?.
German_man
Posts: 16
Joined: Sat May 06, 2006 4:36 am

Post 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 =]
andrei25ni
Posts: 326
Joined: Wed Dec 14, 2005 10:08 pm

Post by andrei25ni »

So, you figured it out by yourself ! Congratulations ! I'll try your solution.
digoxy
Posts: 51
Joined: Wed Feb 17, 2010 3:55 pm
Location: Currently Germany.

Post 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..
Grandma-- / Grandpa --
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post 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.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Post Reply