Multiple windows (launcher + game)

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
kiel814
Posts: 37
Joined: Mon May 23, 2011 4:30 pm

Multiple windows (launcher + game)

Post by kiel814 »

Hi, I want to create a launcher window for a game I'm starting to develop.
The idea is to have a window show up when the program is launched, where you can set the screen size, choose windowed or fullscreen, etc, then you click a play button and the game is launched with the selected settings.

So I start as usual:

Code: Select all

    IrrlichtDevice* device = createDevice(EDT_OPENGL, dimension2d<u32>(512, 384));
    device->setWindowCaption(L"Launcher");
    IVideoDriver* driver = device->getVideoDriver();
    while(device->run() && !exit)
    {
        /* do stuff and set exit when "Play" is clicked */
    }
    device->drop();
Then I create the device again using the selected options:

Code: Select all

    device = createDevice(/* options blah */);
    device->setWindowCaption(L"Game");
    driver = device->getVideoDriver();
    while(device->run())
    {
        /* play the game and do more stuff */
    }
    device->drop();
The problem I'm having is that the launcher window stays open. And if I close it, the game window closes as well and the program ends.
I tried using closeDevice before the first device->drop(). But the second window is also closed.
I also tried using a different device and driver objects, but it made no difference.

Can anyone help?
Is it at all possible what I want to do?
An alternative would be to change resolution, driver type, etc, after the device is created, but I'm pretty sure that is not possible.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Multiple windows (launcher + game)

Post by CuteAlien »

Hm, check the Demo - I think it does just that.

edit: Bascially your program should just never quit before you quit it - not sure why it quits in your case when you close the first window, maybe step through with a debugger.
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
kiel814
Posts: 37
Joined: Mon May 23, 2011 4:30 pm

Re: Multiple windows (launcher + game)

Post by kiel814 »

I got it to work. I don't know exactly why (not that I care much), but it should be done like this. With the closeDevice inside the loop:

Code: Select all

    IrrlichtDevice* device = createDevice(EDT_OPENGL, dimension2d<u32>(512, 384));
    device->setWindowCaption(L"Launcher");
    IVideoDriver* driver = device->getVideoDriver();
    while(device->run())
    {
        /* do stuff */
        if(play_clicked)
        {
            device->closeDevice();
        }
    }
    device->drop();
 
    device = createDevice(/* options blah */);
    device->setWindowCaption(L"Game");
    driver = device->getVideoDriver();
    while(device->run())
    {
        /* play the game and do more stuff */
    }
    device->drop();
Thanks for the tip!!!
Post Reply