CEGUI buttons on 2nd Ogre scene too?

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

User avatar
mmixLinus
Quite a regular
Quite a regular
Posts: 71
Joined: Fri May 20, 2011 08:46
Location: Lund, Sweden
Contact:

CEGUI buttons on 2nd Ogre scene too?

Postby mmixLinus » Fri Sep 02, 2011 18:28

Hi All,

Ok, I've been staring and hacking for two weeks now, to no avail :D [CEGUI 0.7.4 Ogre 1.7.2]
(EDIT: Cross posted to the Ogre forums!)

Short: My goal is to have some CEGUI buttons/window rendered on top of a Viewport in a second Ogre Scene (which in turn is rendered to a texture).

Long:
To do this incrementally, to make sure everything is working, I've started by creating a second SceneManager with a viewport and camera, which I Render-to-texture. This texture, I subsequently show by setting the texture name of a TextureUnitState of an already existing material, to my "RTTName"-string. To make sure I'm seeing the right things, I set up a SkyDome (animated texture) and made the camera rotate in the XZ-plane. All this works. I also get the standard Ogre App Overlay on that second Scene/Viewport (which surprised me a bit). You know, FPS stat box and large OGRE text. So I see a "window into a different world with a moving sky and a rotating camera, and an Ogre Overlay...".

Finally I wanted to see a CEGUI FrameWindow on top of that scene. Nope. That didn't work. Here's the code. Note, I am already showing CEGUI windows and buttons in my SceneManager1/Viewport1.

Code: Select all

void CMMNode::setupOverlayRTT()
{
   USES_CONVERSION;
   CEGUI::WindowManager&   wmgr      = CEGUI::WindowManager::getSingleton();
   CEGUI::Window         *myRTTRoot   = wmgr.createWindow("DefaultWindow", "rtt_root");
   CEGUI::String         sLocalName   = STRING_CUBE_TO_CEGUI(m_sOverlayName);

   CEGUI::Window *pRealRoot = CEGUI::System::getSingleton().setGUISheet(myRTTRoot);

   m_OverlaySceneMgr = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC, "RTTSceneMgr");
   {
      bool  bEnable = true;
      float fCurvature = 8.0f;
      float fTiling = 0.3f;
      float fDistance = 100.0f;
      m_OverlaySceneMgr->setSkyDome(bEnable, "Environment/SunilSky", fCurvature, fTiling, fDistance,
         true,
         Ogre::Quaternion::IDENTITY,
         24, 24);
   }

   m_pMyOverlay = static_cast<CEGUI::FrameWindow*>(wmgr.getWindow(sLocalName));      // for example "Overlay_Album"
   m_pMyOverlay->setProperty("AutoRenderingSurface", "True");
   m_pMyOverlay->show();
   m_pMyOverlay->isVisible();
   m_pMyOverlay->isActive();

   myRTTRoot->addChildWindow(m_pMyOverlay);
   myRTTRoot->setProperty("AutoRenderingSurface", "True");
   myRTTRoot->show();
   myRTTRoot->isVisible();
   myRTTRoot->isActive();

   m_OverlayCam = m_OverlaySceneMgr->createCamera("OverlayRTTCam");
   m_OverlayCam->setPosition(0, 0, 100);
   m_OverlayCam->lookAt(0, 0, 0);

   m_OverlayCam->setNearClipDistance(1.5f);
   m_OverlayCam->setFarClipDistance(3000.0f);
   m_OverlayCam->setAspectRatio(1.0f);

   const Ogre::String rttTexName = "R2TTex";
   const CEGUI::String rttImgName = "R2TImage";
   
   Ogre::TexturePtr cTex = Ogre::TextureManager::getSingleton().createManual(rttTexName,
      Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
      Ogre::TEX_TYPE_2D, 512, 512, 0,
      Ogre::PF_R8G8B8,
      Ogre::TU_RENDERTARGET);

   Ogre::RenderTexture *RTTRenderTarget = cTex->getBuffer()->getRenderTarget();
   RTTRenderTarget->addListener(this);
   CEGUI::OgreRenderer&   myRenderer = CEGUI::OgreRenderer::create(static_cast<Ogre::RenderTarget&>(*RTTRenderTarget));

   Ogre::Viewport *m_overlayViewport = RTTRenderTarget->addViewport(m_OverlayCam, 110);
   m_overlayViewport->setOverlaysEnabled(true);
   m_overlayViewport->setClearEveryFrame(false);
   m_overlayViewport->setBackgroundColour(Ogre::ColourValue::Red);

/* Not sure if I need this...
   CEGUI::Texture&      aRttTexture   = myRenderer.createTexture(cTex);
   CEGUI::Imageset&   imageSet   = CEGUI::ImagesetManager::getSingleton().create((CEGUI::utf8*)"R2TImageset", aRttTexture);
   imageSet.defineImage(rttImgName,
      CEGUI::Point(0.0f, 0.0f),
      CEGUI::Size(aRttTexture.getSize()),
      CEGUI::Point(0.0f,0.0f));

   Ogre::CompositorManager::getSingleton().addCompositor( m_overlayViewport, "Ogre/Scene" ) ;   // was Comp/GuiAlpha
    Ogre::CompositorManager::getSingleton().setCompositorEnabled( m_overlayViewport, "Ogre/Scene", true ) ;   // was Comp/GuiAlpha
*/
   CEGUI::System::getSingleton().setGUISheet(pRealRoot);
}


and once a frame I move the camera. At set up, I do a

Code: Select all

   pTUS->setTextureName(sImageName);
where sImageName is "R2TTex".

What about

Code: Select all

//   myRenderer->setDefaultRootRenderTarget(*RTTRenderTarget);
or

Code: Select all

//   myRenderer->setTargetSceneManager(mySceneManager);
?
setTargetSceneManager doesn't exist anymore I think. I have no interesting errors or exceptions in log files etc, so my CEGUI windows and objects exist.
I think I have managed to miss some sort of CEGUI->Ogre connection. Any ideas?

Image

Thanks!!! /Linus
Last edited by mmixLinus on Mon Oct 24, 2011 20:26, edited 2 times in total.
MMiX.Me 3D Music Player
Galaxy Navigator 3D - 2 million stars (ESA's Gaia satellite)
(YouTube|Facebook)

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: CEGUI buttons on 2nd Ogre scene too?

Postby Kulik » Sat Sep 03, 2011 23:41

We briefly discussed this on IRC:

Code: Select all

12:13 < Kulik> is this even possible? http://www.cegui.org.uk/phpBB2/viewtopic.php?f=2&t=5801
12:13 < Kulik> without resorting to RTT hacks
12:15 < CrazyEddie> Kulik: it depends if he wants different CEGUI on each Ogre VP or the same
12:15 < Kulik> well I guess he wants different GUISheet on each
12:16 < Kulik> what sense would it make to make them the same?
12:16  * CrazyEddie shrugs
12:17 < CrazyEddie> ok, then I think you have to control  your own rendering loop, call renderGUI manually, and swap gui sheets out in-between calls.  Or use RTT of some kind, as you said.
12:17 < CrazyEddie> in the first scenario, I mean you cann renderGUI >1 time
12:17 < CrazyEddie> call*
12:17 < CrazyEddie> fucking keyboard
12:17 < CrazyEddie> lol


There are 2 solutions:
- swapping GUI sheets between renders
- abusing RTT of some window

I will hopefully get back to this later but wanted to post this in here so it doesn't get lost/forgotten.

User avatar
mmixLinus
Quite a regular
Quite a regular
Posts: 71
Joined: Fri May 20, 2011 08:46
Location: Lund, Sweden
Contact:

Re: CEGUI buttons on 2nd Ogre scene too?

Postby mmixLinus » Sun Sep 04, 2011 17:13

*Ahem* :lol:

Oki, thanks guys! I, really appreciate your time and effort!

As far as I'm concerned, that's a [SOLVED] :) - haven't tried it, but I'll go for "swapping GUI sheets between renders"!

Good work, thanks!
/Linus

PS Different GUIs
MMiX.Me 3D Music Player
Galaxy Navigator 3D - 2 million stars (ESA's Gaia satellite)
(YouTube|Facebook)

User avatar
mmixLinus
Quite a regular
Quite a regular
Posts: 71
Joined: Fri May 20, 2011 08:46
Location: Lund, Sweden
Contact:

CEGUI buttons on 2nd Ogre scene too?

Postby mmixLinus » Mon Oct 24, 2011 20:25

Hi again,

(recap: I am trying to get CEGUI windows/objects rendered onto my objects in Ogre space)

So, I've been busy, but also had a little time to try it out. :wink:

My conclusion is that swapping GUI sheets is not enough (does not solve my issue). The problem being that System is using the same Renderer whatever GUI Sheet I set as root.

So, looking at a feasible solution (for me at least), what do you think of letting System have a vector of Renderers, and associate each renderer with the necessary unique attributes (d_activeSheet, ...). Then let renderGUI() loop all renderers (each with a root window). I am assuming each texture target will be an entry in this RendererList.
Then of course, setGUISheet could be overloaded to setGUISheet(Renderer* rttRenderer, Window* sheet) so the list can be edited.

Is there even a remote possibility this will work? And the things I haven't thought of are....?
Maybe this can be done without actually hacking System? Just "regular" things like System->setRenderer and System->setGUIsheet?

If something along these lines actually does work, I know what my next nightmare is: getting mouse coordinates mapped to this "warped texture in a different scene" :cry:

Thank you for your time. MUCH appreciated!
MMiX.Me 3D Music Player
Galaxy Navigator 3D - 2 million stars (ESA's Gaia satellite)
(YouTube|Facebook)

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: CEGUI buttons on 2nd Ogre scene too?

Postby Kulik » Mon Oct 24, 2011 22:01

The proper way to solve this once and for all is to have proper multiple RenderingRoots. That way you would set a root widget / GUI sheet for each of these rendering roots and each would render to whatever you choose, render texture, screen, ... depending on the renderer.

But this can't go into 0.7 as it's a huge change. If it is to go into 0.8 it has to happen fairly fast. From what I've heard RenderingRoots are there in some shape but the API needs to be polished and tightened.

If you are interested in pursuing this, join #cegui @ freenode to discuss this, CrazyEddie usually hangs in there during the weekends, I should be able to reply daily but that depends, it may take hours before I get to reply.

User avatar
mmixLinus
Quite a regular
Quite a regular
Posts: 71
Joined: Fri May 20, 2011 08:46
Location: Lund, Sweden
Contact:

Re: CEGUI buttons on 2nd Ogre scene too?

Postby mmixLinus » Fri Oct 28, 2011 10:47

Ok, it seems the basics needed will come in 0.8, or perhaps are there already. I will have to set aside some time to try out the development branch. Multiple RenderingRoots actually sounds like the solution, to me. Hope this is on the planned path : )

Thanks!
MMiX.Me 3D Music Player
Galaxy Navigator 3D - 2 million stars (ESA's Gaia satellite)
(YouTube|Facebook)

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: CEGUI buttons on 2nd Ogre scene too?

Postby CrazyEddie » Sat Oct 29, 2011 09:09

As of this writing, the default branch (0.8) code is 99% the same as 0.7 with regards to the rendering situation. However this is one final area that I would like to see movement on before (or while) we freeze and polish things a bit ready for a 0.8.0 release (finally!). What results may not be the final version of the multiple rendering roots, but it should certainly be directly supported in some way. Once that's done and working, I'll likely post an article of some kind about it - so keep your eyes peeled for that over the next few weeks :)

CE.


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 5 guests