Two IIrrlicht in External Windows in One App Do Not Work

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!

Two IIrrlicht in External Windows in One App Do Not Work

Postby kkrizka » Wed Nov 05, 2008 6:53 am

Hi,

I am embedding an Irrlicht window inside a Qt widget for some 3D rendering. This works quite well if I only do this with one Irrlicht window. However, if I create two separate Irrlicht windows and put them in the same application under Linux while using OpenGL for rendering, only one of the Irrlicht windows actually renders something while the other remains empty. Also, if I use only 1 Irrlicht window and add a QGLWidget (basically a Qt widget with OpenGL acceleration) to the same application, the same thing happens to the Irrlicht window. However if I try two QGLWidgets, both of them work normally. Thus I suspect the problem lies somewhere with Irrlicht.

Does anyone have any suggestions on what could be wrong?

The complete code I am using to test this can be found here: http://www.box.net/shared/77cy2rlcv9

When I run it, I get the following output in the terminal:
Code: Select all
kkrizka@sein:~/Projects/amelia/testbed/qtrr$ ./qtrr
Irrlicht Engine version 1.4.2
Linux 2.6.27-7-generic #1 SMP Thu Oct 30 04:18:38 UTC 2008 i686
Creating X window...
Visual chosen: : 33
Using renderer: OpenGL 1.4
Mesa DRI Intel(R) 965GM 20061102 x86/MMX/SSE2: Tungsten Graphics, Inc
OpenGL driver version is 1.2 or better.
GLSL version: 1.3
Found joystick 0, 2 axes, 0 buttons, 'ThinkPad HDAPS joystick emulation'
Found joystick 1, 2 axes, 0 buttons, 'ThinkPad HDAPS accelerometer data'
Irrlicht Engine version 1.4.2
Linux 2.6.27-7-generic #1 SMP Thu Oct 30 04:18:38 UTC 2008 i686
Creating X window...
Visual chosen: : 33
Using renderer: OpenGL 1.4
Mesa DRI Intel(R) 965GM 20061102 x86/MMX/SSE2: Tungsten Graphics, Inc
OpenGL driver version is 1.2 or better.
GLSL version: 1.3
Found joystick 0, 2 axes, 0 buttons, 'ThinkPad HDAPS joystick emulation'
Found joystick 1, 2 axes, 0 buttons, 'ThinkPad HDAPS accelerometer data'


Here is what is displayed:
Image

Below is a snipplet of my QIrrWidget class, which basically is a Qt widget that contains and Irrlicht window. In my testcode, I inherit this class by another class called ABase, where I implement the load() function to create a white cube scene node. In my main() function, I create a base parent QWidget and to it add two instances of the fore mentioned ABase class.

Code: Select all
QIrrWidget::QIrrWidget( QWidget *parent )
  : QWidget(parent),Device(0)
{
    // Wait for the init() call
    Device = 0;

    // Default to Open GL
#ifdef Q_WS_WIN
    _driverType = irr::video::EDT_DIRECT3D9;
#else
    _driverType = irr::video::EDT_OPENGL;
#endif

  setAttribute( Qt::WA_OpaquePaintEvent );
  //Tell Qt we will use something else for painting
  setAttribute(Qt::WA_PaintOnScreen);
  setAttribute(Qt::WA_NoBackground);
  setAttribute(Qt::WA_NoSystemBackground);
 
  setMouseTracking(true);
 
  setFocusPolicy(Qt::StrongFocus);
  setAutoFillBackground(false);
}

QIrrWidget::~QIrrWidget()
{
  if ( Device != 0 )
    {
      Device->closeDevice();
      Device->drop();
      Device=0;
    }
}


irr::IrrlichtDevice* QIrrWidget::GetDevice()
{
    return Device;
}

video::IVideoDriver* QIrrWidget::GetDriver()
{
    return Device->getVideoDriver();
}

ISceneManager* QIrrWidget::GetSceneManager()
{
    return Device->getSceneManager();
}

irr::video::E_DRIVER_TYPE QIrrWidget::driverType()
{
  return _driverType;
}

void QIrrWidget::execute() { }

bool QIrrWidget::OnEvent(const SEvent &event)
{
  return false;
}

void QIrrWidget::load() { }

void QIrrWidget::Init()
{
  // Don't initialize more than once!
  if ( Device != 0 ) return;

  irr::SIrrlichtCreationParameters params;
 
  params.DriverType = driverType();
  params.WindowId = (void*)winId();
  params.WindowSize.Width = width();
  params.WindowSize.Height = height();
  params.AntiAlias = true;
  params.IgnoreInput = true;
 
  Device = irr::createDeviceEx( params );
 
  timerId=startTimer(20);
 
  load();
}

void QIrrWidget::timerEvent(QTimerEvent* event)
{
  update();
}
 
void QIrrWidget::paintEvent( QPaintEvent* event )
{
  if(!Device)

    {
      Init();
    }
 
  if (Device)
    {
      Device->getTimer()->tick();
     
      execute();
     
      irr::video::SColor color (0,0,0,0);
      Device->getVideoDriver()->beginScene( isEnabled(), true, color);
      Device->getSceneManager()->drawAll();
      Device->getVideoDriver()->endScene();
    }
 
  QWidget::paintEvent(event);
}

QPaintEngine * QIrrWidget::paintEngine () const
{
  return 0;
}
Cheers,
Karol Krizka

http://www.krizka.net
kkrizka
 
Posts: 70
Joined: Sun Sep 30, 2007 3:10 am

Postby deeves » Tue Nov 25, 2008 9:48 am

I had the same idea and was having the same problem. You need to send the handle of the window you want to draw to when calling 'endScene()', ie. Device->getVideoDriver()->endScene( (irr::s32)winId() );

But, according to 'ivideodriver.h' this will only work for "D3D8, D3D9, Software1 and Software2, and only for Windows", so it won't work cross-platform.
deeves
 
Posts: 1
Joined: Tue Nov 25, 2008 9:34 am

Postby kkrizka » Sun Dec 07, 2008 5:55 am

Ah, that could fix it. I believe I saw a commit a while back about this being added to OpenGL too for the 1.5 release. The documentation is based on 1.4...
Cheers,
Karol Krizka

http://www.krizka.net
kkrizka
 
Posts: 70
Joined: Sun Sep 30, 2007 3:10 am

Postby hybrid » Sun Dec 07, 2008 4:31 pm

No, it wasn't finished for Irrlicht 1.5, but we might add this for 1.5.1 as long as the changes are backward compatible (the major change was made for 1.5, i.e. moving the window pointer parameter to beginScene).
hybrid
Admin
 
Posts: 13943
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany

Postby TCM » Thu Sep 30, 2010 8:51 pm

Was this added in 1.7.1 ?

I seem to have the same problem when having two instances of irrLicht in the same software. It does seem to be a driver problem because if i use OpenGL for one instance and DirectX for the other instance it works perfectly. If i use OpenGL for both, when the second irrLicht window comes-up, the old one freezes. The new window works perfectly though.

Any way to tell irrLicht "do not render this window" and "go and render this, i need you here" ?
TCM
 
Posts: 53
Joined: Mon May 24, 2010 9:29 pm

Postby hybrid » Thu Sep 30, 2010 9:01 pm

As always, two instances are generally not supported by Irrlicht. For rendering into two windows, you should give one to Irrlicht's creation parameter, and render into the second window by passing the window structure into the beginScene parameter. This should also work on OpenGL in Irrlicht 1.7. I don't recall whether you have to make the glContext current before passing it to Irrlicht (and back when done rendering to the second window then). Just try it out and tell us :)
hybrid
Admin
 
Posts: 13943
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany

Postby TCM » Fri Oct 01, 2010 9:55 am

I'll try....

Still, there MUST be a way.... Irrlicht runs perfectly when having two different applications using irrLicht open. For example two irrLicht demos running at the same time. Of course both using OpenGL. So they are both using the same DLL. I would make no sense not to be able to use two instances or irrLicht in the same software. I guess some pointers get overwritten or something like that because always the last window to come up works and the older freezes. Or maybe some things are static in the library.


I have to render in a preview window before adding objects to main irrLicht instance. I could use DirectX for the preview window, but then i will not be able to display OpenGL shaders.

When using two instances, are the drivers also instantiated ?
TCM
 
Posts: 53
Joined: Mon May 24, 2010 9:29 pm

Postby hybrid » Fri Oct 01, 2010 11:01 am

Well, at least the OpenGL drivers also provide a per-process handling of ressources. So it can be pretty easy to have the same things happen in two processes. But once it comes down to the same app, even in two separate threads, things are much more complex. The whole driver design simply assumes, that the render context etc. are kept active all the time.
hybrid
Admin
 
Posts: 13943
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany

Re: Two IIrrlicht in External Windows in One App Do Not Work

Postby christianclavet » Fri Feb 10, 2012 1:01 am

Sorry, to revive this old thread...
I was able to have this working (on windows) using the software driver for a windows and the main as opengl. From some comments, figured out a way to maintain the app "alive" when the "software" (used as a secondary windows) was closed was to change the driver to the NULL driver (so as hybrid seem to say, keep the device pointer "active" when it's opened. Seem to work fine on Windows.

I just tried this on Ubutu, the other (secondary window) will open but there is no rendering in it (like the window is opened, but the rendering context is not for a reason). I'm using official 1.7.2

I decided to use a software renderer for the secondary window so it's will not try to use a second GL context. I wonder if anybody have succeeded to open more than one window with Irrlicht. I want to use this for have editor windows that could be used over multiple displays. As it's look now, I won't be able to have this in Linux.
User avatar
christianclavet
 
Posts: 1383
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA

Re: Two IIrrlicht in External Windows in One App Do Not Work

Postby CuteAlien » Fri Feb 10, 2012 9:38 am

@|christianclavet: Do you also use wxWidgets or something like that or pure Irrlicht? And just to get what exactly you are trying - you want one Window with OpenGL and one with Software rendering? I thought this would work on Linux, but I only used that for GUI so far, not with 3d.
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5359
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Two IIrrlicht in External Windows in One App Do Not Work

Postby christianclavet » Fri Feb 10, 2012 1:43 pm

Hi, I use this on pure Irrlicht and yes, I want to open a Opengl windows (as main), the second as software rendering a GUI (The code still render an empty scene, "smgr->renderAll()")
The window is opened but nothing is rendered in it.

The idea, is to have a version of IRB that will have nice requesters and don't need wxWidget at all and also that I could use Irrlicht for "editor" use by opening external windows so the user can use theses windows on a multi-monitor system and won't be stuck on only one screen. At least the method seem to work so far on Windows.

EDIT1 (2/9/12): Tried to open 2 OPENGL windows (Windows Vista), it still work. But the minute, I call "closeDevice()", it crash (From the debugger it crash in my driver opengGL driver (nvoglv32.dll)). But before closing it, the rendering of the gui and the gui events where all ok. So I think Irrlicht improved a lot in that direction since the first versions.

I will have to test this further by creating windows myself and attaching irrlicht to it, perhaps it will improve from there. I would like also to experiment with the windows styles.

I did not know about this, but this can limit severely development for multi-window apps. If I'm not able to do something, (still it work on Windows with a software driver for the other window), I will force linux to render all in the same window using "irrlicht" windows GUI.

Edit2 (2/11/12): Humm. I might be forced for stability to not use that at all. I've used the debug version of the Irrlicht DLL and now the APP is not closing, it's only closing with the release dll. At least, I've experimented with that and know now what it can currently do. It could perhaps be used someday for multi-windows application but at the current state of implementation, I would wait. I started studying the Irrlicht source in for the device/driver creation and might propose some patches in the future.

What could be good to have is the ability for supporting multi-windows apps creation (as for the moment, I can clearly see Irrlicht is getting there but not totally) would be a "device/driver" manager, that would deal with all the frame context/drivers linking (would also deal with the viewports, as it could also assign a viewport to an external window), would be able to switch or change a scene manager pointers and assign it to a device/driver (I think that currently can already do this, but not sure). Have more control on the window creation styles (borderless, transparent, modal, etc), create and manage the "children" windows, etc.
User avatar
christianclavet
 
Posts: 1383
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA


Return to Advanced Help

Who is online

Users browsing this forum: No registered users and 1 guest