Page 1 of 1

Ogre Overlay on top of CEGUI

Posted: Mon Jul 04, 2011 14:07
by blablub
Hi,

I have CEGUI 0.7.5 and are bootstrapping it to the OgreRenderer.

But all the CEGUI elements are on top of my Ogre overlays. I want it the other way round (-> Ogre Overlay on top of CEGUI).

I found a solution with setRenderTargetQueue(), but this function doesn't seem to exist in 0.7.5.

How can I change this behavior?

Re: Ogre Overlay on top of CEGUI

Posted: Mon Jul 04, 2011 16:06
by Kulik
I don't have the exact details of how to do this but I recall someone asking for this, so this is already in the forum somewhere.

General idea is that you have to disable the automatic CEGUI rendering and render when you want.

Re: Ogre Overlay on top of CEGUI

Posted: Tue Jul 05, 2011 21:55
by Jabberwocky
Yeah, you need to call:

Code: Select all

CEGUI::OgreRenderer::setFrameControlExecutionEnabled( false );

to tell CEGUI not to render, so you can explicitly tell it when to render, after the overlays in your case.

My code looks something like this (chopped out a bunch of stuff for simplicity, not-tested):

Code: Select all

class UISystem: public Ogre::RenderQueueListener
{
public:
   void Init( Ogre::SceneManager* pSceneMgr );
   // We can specify a RenderQueue to render the UI on (actually before or after).
   void SetRenderQueue( Ogre::RenderQueueGroupID i_nRenderQueue, bool i_bPostQueue );
   void renderQueueStarted(Ogre::uint8 id, const Ogre::String& invocation, bool& skipThisQueue);
   void renderQueueEnded(Ogre::uint8 id, const Ogre::String& invocation, bool& repeatThisQueue);

private:
   // When we draw the UI.
   Ogre::RenderQueueGroupID m_nRenderQueue;
   // Whether to draw CEGUI immediately before or after m_nRenderQueue
   bool m_bPostQueue;
};


Code: Select all

void UISystem::Init( Ogre::SceneManager* i_pSceneMgr )
{
   // -- a bunch of other CEGUI initialization code omitted here for brevity ---

   // tell CEGUI that we want to handle the calls to CEGUI::System::renderGUI()
   GetCEGUIOgreRenderer()->setFrameControlExecutionEnabled( false );

   // Register a RenderQueueListener so we have a hook to call CEGUI::System::renderGUI()
   // Be careful not to call this function more than once, or you will render your GUi multiple times per tick
   i_pSceneMgr->addRenderQueueListener( this );
}

void UISystem::SetRenderQueue( Ogre::RenderQueueGroupID i_nRenderQueue, bool i_bPostQueue )
{
   m_nRenderQueue = i_nRenderQueue;
   m_bPostQueue = i_bPostQueue;
}

void UISystem::renderQueueStarted(Ogre::uint8 id, const Ogre::String& invocation, bool& skipThisQueue)
{
   // make sure you check the invocation string, or you can end up rendering the GUI multiple times
   // per frame due to shadow cameras.
   if ( !m_bPostQueue && m_nRenderQueue == id && invocation == "" )
   {
      CEGUI::System::getSingleton().renderGUI();
   }
}

void UISystem::renderQueueEnded(Ogre::uint8 id, const Ogre::String& invocation, bool& repeatThisQueue)
{
   if ( m_bPostQueue && m_nRenderQueue == id && invocation == "" )
   {
      CEGUI::System::getSingleton().renderGUI();
   }
}


If you want CEGUI to render after overlays, try:

Code: Select all

UISystem->SetRenderQueue( RENDER_QUEUE_OVERLAY, true );