Page 1 of 1

[Solved] Ogre Dual monitor application

Posted: Wed Jul 06, 2016 16:17
by kiske1
Hello,

I'm trying to use CEGUI in my Ogre application, that works with 2 indipendent windows each of them on different monitor.

I came across these 2 threads:
http://cegui.org.uk/forum/viewtopic.php?f=10&t=6971
and
http://cegui.org/forum/viewtopic.php?f=10&t=6831&sid=292d88310f7b2d97b372d3125e8bfd5f

As far as I can understand, they're based on different approaches, while the first one basically creates 2 ogrerenderer, the second one only creates a new context for the new window. Please tell me if I understood it correctly and what is the best approach.

I've managed to get both approaches to work correctly, but only if the windows are created in the same monitor, and not moved from there. As soon as I move the window to another monitor I get an INVALID_CALL exception thrown by D3D upon "drawprimitive" in the Ogre D3D9 rendersystem. Any clue where to look at?

Thanks!

PS.
The project uses Ogre 1.9 with D3D9 Rendersystem and CEGUI 0.8.7

PS2.
This is crossposted on Ogre forums, here: http://www.ogre3d.org/forums/viewtopic.php?f=2&t=88638

Re: Dual monitor application

Posted: Thu Jul 07, 2016 20:02
by YaronCT
@kiske1: That's an interesting problem, I've never dealt with multiple monitors b4. I'll look into it, but it might take some time.

Re: Dual monitor application

Posted: Fri Jul 08, 2016 07:15
by kiske1
@YaronCT

I've just managed to find out what the problem was. Basically the problem was that when the ogre renderwindows are created a different d3ddevice is created for every monitor used. In the CEGUI::OgreRenderer, when beginRendering() (and endRendering) is called it always activates the renderTarget relative to the default (eg first) GUIContext, and this causes the default device to be always used. In the CEGUI source in fact there is a FIXME comment on this line.

What I've done to overcome the problem was to create a new beginRendering() (and endRendering() ) overload wich takes a GUIContext as a parameter, changing

Code: Select all

//FIXME: ???
    System::getSingleton().getDefaultGUIContext().getRenderTarget().activate();

to

Code: Select all

Context->getRenderTarget().activate();


After recompiling CEGUIOgreRenderer, in my app I disabled automated rendering and FrameControlExecution with that:

Code: Select all

   mRenderer->setFrameControlExecutionEnabled(false);
   mRenderer->setRenderingEnabled(false);   


and then attached an Ogre::RenderTargetListener to each of the windows, and in the postRenderTargetUpdate() I've made the actual draw call for each. Eg. for the first one:

Code: Select all

      
      mGUIManager->getRenderer()->beginRendering(mGUIManager->getContext1());
      mGUIManager->getContext1()->draw();
      mGUIManager->getRenderer()->endRendering(mGUIManager->getContext1());


and for the second one

Code: Select all

      
      mGUIManager->getRenderer()->beginRendering(mGUIManager->getContext2());
      mGUIManager->getContext2()->draw();
      mGUIManager->getRenderer()->endRendering(mGUIManager->getContext2());


I'm pretty sure that it isn't the best way, but it actually does the job... :D

Re: [Solved] Ogre Dual monitor application

Posted: Sat Jul 16, 2016 15:01
by YaronCT
@kiske1: Gotta love those "FIXME"-s..

I've submitted a fix to cegui branch "v0-8". Can u plz test it?