Need Help With Creating a Second Window!

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
jonasrf
Posts: 25
Joined: Fri Jan 13, 2006 6:18 am
Contact:

Need Help With Creating a Second Window!

Post by jonasrf »

:shock: I'm having a horrible time getting a second window to work!
I got the second device started and a second skin second driver a second env and even a second font for it. What it does is it draws both of them but when I exit the second window the first won't work. But when I exit the first window the second window still works!
Last edited by jonasrf on Thu Mar 30, 2006 6:53 pm, edited 1 time in total.
andrei25ni
Posts: 326
Joined: Wed Dec 14, 2005 10:08 pm

Post by andrei25ni »

could you post your code please ? that will help
jonasrf
Posts: 25
Joined: Fri Jan 13, 2006 6:18 am
Contact:

Post by jonasrf »

I wish I could post the code! its on another computer with out internet.

I just need to know if there is any special procedure to adding a second window. Any Special code. Has anyone ever done it before? Is it even possible for it to render 2 windows at once?

I have created a second eventreceiver(it works) I declared a second id(in the evenreciever) a second env a second skin a second font a second driver(i made sure that env2 use's only driver 2 not driver1 and env1 uses driver1 not 2) I made sure that if it was declared in env1 and driver1 that a one just like it was created in env2 with a 2 at the end. Can anyone tell me what I'm missing or if its even possible. Like I said before It renders 1st window all the way but it won't render 2nd window while first is still there(it shows just a clear frame till then) then if you exit the second window first then the second window will not render any longer.

I will see if I can show you my changes I post it a little later
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

have you checked Max Winkel's splitscreen tutorial?
http://irrlicht.sourceforge.net/tut_split.html
jonasrf
Posts: 25
Joined: Fri Jan 13, 2006 6:18 am
Contact:

Post by jonasrf »

Yes I've seen that and read through it but that doesn't create 2 different windows with 2 different skins and have diffrent buttons on both.

What I'm trying to do is make another window be created when I press a button.

I would use the IGUIWindow but it has to stay inside the main window, and for this program I need it to be free, to move around like a win32 window(but I need to use irrlicht so it will be compatible) so therefore I need 2 different devices. I've gotten the windows both created but I just want them both to be able to show at the same time.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

I'm looking at this and I see that it is _not_ safe to create and destroy devices at runtime.

The first problem is that the device stub CIrrDeviceStub constructor allocates a logger and assigns it to the printer logger. When a stub is destroyed, it drops its own logger. If the printer logger is still pointing to that stubs logger, you will get a crash.

The second problem is that after one of the devices is destroyed, calls to IDirect3DDevice9::Present() fail repeatedly. This is most likely the problem that you are seeing. I haven't looked into why it is happening, but from what I'm seeing this is not something that is being done by many people and it doesn't appear to be getting tested either.

Another problem is that it doesn't seem to work with OpenGL driver at all.

Travis
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Here is my test code...

Code: Select all

#include <irrlicht.h>
#include <stdlib.h>
#include <string.h>

using namespace irr;
using namespace gui;

#pragma comment(lib, "Irrlicht.lib")

IrrlichtDevice* Devices[2];

int main()
{
   // ask user for driver

   video::E_DRIVER_TYPE driverType = video::EDT_DIRECT3D8;

   // create device and exit if creation failed
#define countof(x) (sizeof(x) / sizeof(*x))

   u32 d;
   for (d = 0; d < countof(Devices); ++d)
   {
      Devices[d] = createDevice(driverType, core::dimension2d<s32>(640, 480),
         16, false, false, false);
      if (!Devices[d])
         return 1; // yes, we leak if 2nd device create fails

      wchar_t caption[40];
      swprintf(caption, 40, L"Device:%u", d);

      Devices[d]->setWindowCaption(caption);
      Devices[d]->setResizeAble(true);

      // add a camera scene node 
      Devices[d]->getSceneManager()->addCameraSceneNodeMaya();

      scene::ISceneNode* Node = Devices[d]->getSceneManager()->addTestSceneNode();
      Node->setMaterialTexture(0, Devices[d]->getVideoDriver()->getTexture("../../media/fireball.bmp"));

      scene::ISceneNodeAnimator* Animator =
			Devices[d]->getSceneManager()->createFlyCircleAnimator(core::vector3df(10.f, 10.f, 0.f), 10.f, d & 0x1 ? .001f : -.001f);
         Node->addAnimator(Animator);
      Animator->drop();
   }
   
   // render and run until both windows are closed
   u32 g = countof(Devices);
   while(g)
   {     
      for(d = 0; d < countof(Devices); ++d)
      {
         IrrlichtDevice* device = Devices[d];
         if (device)
         {
            if (device->run())
            {
               video::IVideoDriver* driver = device->getVideoDriver();
               scene::ISceneManager* scene = device->getSceneManager();
               gui::IGUIEnvironment* gui = device->getGUIEnvironment();

               if (driver->beginScene(true, true, video::SColor(255, 50, 50, 50)))
               {
                  scene->drawAll();
                  gui->drawAll();

                  driver->endScene();
               }
            }
            else 
            {
               device->drop();
               Devices[d] = 0;
               --g;
            }
         }
      }
   }

   return 0;
}
jonasrf
Posts: 25
Joined: Fri Jan 13, 2006 6:18 am
Contact:

Post by jonasrf »

ok I figured out an alternative answer to creating a second window.

I created a second program. Then I set it so that it checks to see if a value is yes if it is it will continue, then at the end it sets the value to no. the main program changes the value to yes then instantly runs it. This method works great! Because you can't start the second program up at all with out pressing a button in the first program.
rooly
Posts: 224
Joined: Tue Oct 25, 2005 4:32 pm
Location: Louisiana, USA, backwater country
Contact:

Post by rooly »

yup, that is what i was gonna sugest, of course, you could always use a network service, like zoidcom. that would make information sharing between the programs a heluva lot easier
When banks compete, you win.
When ISPs compete, you win.
When electronics retailers compete, you win.
When governments compete...you get drafted.
Post Reply