[solved] How do I set up CEGUI on Ogre 2.1? Default GUI context isn't a rendering window?

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

Dugi
Just popping in
Just popping in
Posts: 14
Joined: Fri Apr 17, 2015 20:41

[solved] How do I set up CEGUI on Ogre 2.1? Default GUI context isn't a rendering window?

Postby Dugi » Wed Jul 13, 2016 15:45

Hello.

I've been using CEGUI with Ogre 1.9 for some time, then I decided to upgrade to Ogre 2.1 and the API to set up CEGUI changed. I have found somewhere how to to get it working, it allowed me to compile the program but I could not test it right afterwards. When I finally could test it, I realised that CEGUI is completely invisible. Now I can't find the tutorial how to get it running. I have searched the Internet, but I found almost nothing.

The best thing I could find was this liked from this thread. This also gave out a bit of information.

I can't find any proper information how to set it up, so I would be really happy if someone assisted me in fixing the issue because it seems I can't do it alone.

Here is the code that sets up Ogre and CEGUI:

Code: Select all

   root_ = std::unique_ptr<Ogre::Root>(new Ogre::Root());
   root_->loadPlugin(prefs.renderSystem);
   root_->loadPlugin("Plugin_ParticleFX");

   const Ogre::RenderSystemList& renderSystems = root_->getAvailableRenderers();
   if (renderSystems.empty()) throw(std::runtime_error("Cannot find the desired render system"));
   root_->setRenderSystem(renderSystems[0]);
   root_->initialise(false, "Render Window", "");

   // SDL2 is initialised here and Ogre is configured to use its window, but it appears to work and it was copied from an Ogre sample anyway

   Ogre::NameValuePairList params;
   params["FSAA"] = std::to_string(prefs.FSAA);
   params["vsync"] = prefs.vsync ? "true" : "false";
   renderWindow_ = root_->createRenderWindow("Render Window", prefs.displayWidth, prefs.displayHeight, prefs.fullscreen, &params);

   sceneManager_ = root_->createSceneManager(Ogre::ST_GENERIC, 3, Ogre::INSTANCING_CULLING_THREADED, "GameSceneMgr");
   sceneManager_->setForward3D(true, 4, 4, 5, 96, 3, 200);
   sceneManager_->setShadowFarDistance(prefs.shadowFarDistance);

   camera_ = sceneManager_->createCamera("GameCamera");
   compositorManager_ = root_->getCompositorManager2();
   const Ogre::IdString workspaceName("Main Workspace");
   if (!compositorManager_->hasWorkspaceDefinition(workspaceName)) {
      compositorManager_->createBasicWorkspaceDef(workspaceName, Ogre::ColourValue(0.5f, 0.5f, 0.5f), Ogre::IdString());
   }
   compositorManager_->addWorkspace(sceneManager_, renderWindow_, camera_, workspaceName, true);

   guiRenderer_ = &CEGUI::OgreRenderer::bootstrapSystem(*renderWindow_);

   std::cout << "CEGUI verification " << CEGUI::System::getSingleton().getDefaultGUIContext().isRenderingWindow()
           << " " << guiRenderer_->isRenderingEnabled() << std::endl;

At this point, I am informed that the default GUI context isn't a rendering window.

Afterwards, I set up CEGUI to actually show an intro scren, I don't think there is an error there but I am posting it for completeness' sake:

Code: Select all

// This part is probably irrelevant
   guiRenderer_ = renderer;

   Ogre::ResourceGroupManager& resManager = Ogre::ResourceGroupManager::getSingleton();
   resManager.addResourceLocation("media/cegui/imagesets", "FileSystem", "Imagesets");
   resManager.addResourceLocation("media/cegui/fonts", "FileSystem", "Fonts");
   resManager.addResourceLocation("media/cegui/layouts", "FileSystem", "Layouts");
   resManager.addResourceLocation("media/cegui/looknfeel", "FileSystem", "LookNFeel");
   resManager.addResourceLocation("media/cegui/schemes", "FileSystem", "Schemes");

   Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

   CEGUI::ImageManager::setImagesetDefaultResourceGroup("Imagesets");
   CEGUI::Font::setDefaultResourceGroup("Fonts");
   CEGUI::Scheme::setDefaultResourceGroup("Schemes");
   CEGUI::SchemeManager::getSingleton().createFromFile("Generic.scheme");
   CEGUI::WidgetLookManager::setDefaultResourceGroup("LookNFeel");
   CEGUI::WindowManager::setDefaultResourceGroup("Layouts");

   CEGUI::WindowManager &wmgr = CEGUI::WindowManager::getSingleton();
   sheet_ = wmgr.createWindow("DefaultWindow", "CEGUIDemo/Sheet");
   CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(sheet_);
   CEGUI::System::getSingleton().getDefaultGUIContext().getRootWindow()->setProperty(CEGUI::String("AutoRenderingSurface"), CEGUI::String("false"));

   std::cout << "CEGUI verification " << CEGUI::System::getSingleton().getDefaultGUIContext().isRenderingWindow()
           << " " << guiRenderer_->isRenderingEnabled() << std::endl;
           // Still not a rendering window

   CEGUI::ImageManager::getSingleton().loadImageset("title.imageset", "Imagesets");
   // THIS PART SHOULD BE RELEVANT
   loadingScreen_ = wmgr.createWindow("Generic/Image","loadingScreen");
   loadingScreen_->setSize(CEGUI::USize(cegui_reldim(1.0f), cegui_reldim(1.0f)));
   loadingScreen_->setProperty("Image", "title/title");
   loadingScreen_->setMousePassThroughEnabled(false);
   loadingScreen_->setRiseOnClickEnabled(false);
   loadingScreen_->setProperty(CEGUI::String("AutoRenderingSurface"), CEGUI::String("false")); // I've found somewhere that this might be necessary, doesn't seem to help, though
   sheet_->addChild(loadingScreen_);


With every frame, I run:

Code: Select all

   root_->renderOneFrame();

   CEGUI::System::getSingleton().injectTimePulse(period);
   CEGUI::System& guiSystem = CEGUI::System::getSingleton();
   guiSystem.injectTimePulse(period);

   CEGUI::Renderer* guiRenderer(guiSystem.getRenderer());

   guiRenderer->beginRendering();

   guiSystem.getDefaultGUIContext().injectTimePulse(period / 1000);
   guiSystem.getDefaultGUIContext().draw();

   guiRenderer->endRendering();

   CEGUI::WindowManager::getSingleton().cleanDeadPool();


Ogre itself is running properly and I see what it renders. No CEGUI window shows up ever, no error messages appear neither.
Last edited by Dugi on Fri Jul 15, 2016 09:15, edited 1 time in total.

YaronCT
CEGUI Team
Posts: 448
Joined: Fri Jun 19, 2015 12:18
Location: Kiryat-Bialik, Israel

Re: How do I set up CEGUI on Ogre 2.1? Default GUI context isn't a rendering window?

Postby YaronCT » Wed Jul 13, 2016 19:12

@Dugi: which cegui version do u use?

Dugi
Just popping in
Just popping in
Posts: 14
Joined: Fri Apr 17, 2015 20:41

Re: How do I set up CEGUI on Ogre 2.1? Default GUI context isn't a rendering window?

Postby Dugi » Wed Jul 13, 2016 19:51

0.8.7, I didn't want to cause confusion so I tried a version I downloaded today from mercurial.

YaronCT
CEGUI Team
Posts: 448
Joined: Fri Jun 19, 2015 12:18
Location: Kiryat-Bialik, Israel

Re: How do I set up CEGUI on Ogre 2.1? Default GUI context isn't a rendering window?

Postby YaronCT » Thu Jul 14, 2016 10:19

@Dugi: I think you haven't done "#define CEGUI_USE_OGRE_COMPOSITOR2"?

YaronCT
CEGUI Team
Posts: 448
Joined: Fri Jun 19, 2015 12:18
Location: Kiryat-Bialik, Israel

Re: How do I set up CEGUI on Ogre 2.1? Default GUI context isn't a rendering window?

Postby YaronCT » Thu Jul 14, 2016 10:22

@Dugi: sorry, my mistake, ignore it.

Ogre 2.0/2.1 currently doesn't work in the cegui sample framework, I work to fix it.

lucebac
Just can't stay away
Just can't stay away
Posts: 193
Joined: Sat May 24, 2014 21:55

Re: How do I set up CEGUI on Ogre 2.1? Default GUI context isn't a rendering window?

Postby lucebac » Thu Jul 14, 2016 10:34

Do we actually support Ogre 2.0/2.1 in v0-8? Default does, but I'm not sure if someone backported the changes to v0-8.

YaronCT
CEGUI Team
Posts: 448
Joined: Fri Jun 19, 2015 12:18
Location: Kiryat-Bialik, Israel

Re: How do I set up CEGUI on Ogre 2.1? Default GUI context isn't a rendering window?

Postby YaronCT » Thu Jul 14, 2016 10:37

@lucebac: Good question. If @Ident were here perhaps he would know.

It does build though. And the sample framework doesn't work on any branch.

Dugi
Just popping in
Just popping in
Posts: 14
Joined: Fri Apr 17, 2015 20:41

Re: How do I set up CEGUI on Ogre 2.1? Default GUI context isn't a rendering window?

Postby Dugi » Thu Jul 14, 2016 11:06

As far as I know, CEGUI should work with Ogre 2.1, this guy has done the hard work. According to some topics, some people could get it working, but there is no example code so far.

The samples can't compile, probably they were not updated to reflect the changes in the API of CEGUI's OgreRender. No example code there neither.

YaronCT wrote:@Dugi: I think you haven't done "#define CEGUI_USE_OGRE_COMPOSITOR2"?
So is this true or not? Where should I define it? If I define it before including the headers (to activate the #ifdefs in them), nothing happens.

YaronCT
CEGUI Team
Posts: 448
Joined: Fri Jun 19, 2015 12:18
Location: Kiryat-Bialik, Israel

Re: How do I set up CEGUI on Ogre 2.1? Default GUI context isn't a rendering window?

Postby YaronCT » Fri Jul 15, 2016 01:20

@Dugi: Try to do all rendering (including cegui) from inside "frameRenderingQueued".

Dugi
Just popping in
Just popping in
Posts: 14
Joined: Fri Apr 17, 2015 20:41

Re: How do I set up CEGUI on Ogre 2.1? Default GUI context isn't a rendering window?

Postby Dugi » Fri Jul 15, 2016 06:46

Wow :shock: It works! Thanks!

It becomes visible when the update is inside frameRenderingQueued. I will add information how to set it up soon.
Last edited by Dugi on Fri Jul 15, 2016 09:14, edited 1 time in total.

YaronCT
CEGUI Team
Posts: 448
Joined: Fri Jun 19, 2015 12:18
Location: Kiryat-Bialik, Israel

Re: How do I set up CEGUI on Ogre 2.1? Default GUI context isn't a rendering window?

Postby YaronCT » Fri Jul 15, 2016 08:46

@Dugi: :D

It seems like rendering to an off-screen buffer (like a texture) still have problems. I work on it. If u only render to screen and still have problems u can't solve, plz report.

Dugi
Just popping in
Just popping in
Posts: 14
Joined: Fri Apr 17, 2015 20:41

Re: [solved] How do I set up CEGUI on Ogre 2.1? Default GUI context isn't a rendering window?

Postby Dugi » Fri Jul 15, 2016 09:16

No, my problem was just that I was trying to load an imageset with dimensions 1920x1080 as a loading screen instead of a square. It's all right now. I am bit trying to do any render to texture at the moment.

To facilitate the work to others who have the same problems, here is what I did to start CEGUI in Ogre:

Code: Select all

   root_ = std::unique_ptr<Ogre::Root>(new Ogre::Root()); // Ogre::Root* in header
   root_->loadPlugin(prefs.renderSystem);
   root_->loadPlugin("Plugin_ParticleFX");

   const Ogre::RenderSystemList& renderSystems = root_->getAvailableRenderers();
   if (renderSystems.empty()) throw(std::runtime_error("Cannot find the desired render system"));
   root_->setRenderSystem(renderSystems[0]);
   root_->initialise(false, "YourGame", "");

   Ogre::NameValuePairList params;
   params["FSAA"] = std::to_string(prefs.FSAA); // prefs is a just a provider of settings, values like 0 will do here
   params["vsync"] = prefs.vsync ? "true" : "false";
   
   // PLACE THE SDL2 INITIALISATION CODE HERE IF YOU WANT

   renderWindow_ = root_->createRenderWindow("YourGame", prefs.displayWidth, prefs.displayHeight, prefs.fullscreen, &params) // Ogre::RenderWindow* in header

   sceneManager_ = root_->createSceneManager(Ogre::ST_GENERIC, 3, Ogre::INSTANCING_CULLING_THREADED, "GameSceneMgr"); // Ogre::SceneManager* in header
   sceneManager_->setForward3D(true, 4, 4, 5, 96, 3, 200); // Not necessary for CEGUI, but point lights don't work without it
   sceneManager_->setShadowFarDistance(prefs.shadowFarDistance);

   camera_ = sceneManager_->createCamera("GameCamera"); // Ogre::Camera* in header
   compositorManager_ = root_->getCompositorManager2(); // Ogre::CompositorManager2* in header
   const Ogre::IdString workspaceName("Main Workspace");
   if (!compositorManager_->hasWorkspaceDefinition(workspaceName)) {
      compositorManager_->createBasicWorkspaceDef(workspaceName, Ogre::ColourValue(0.5f, 0.5f, 0.5f), Ogre::IdString());
   }
   compositorManager_->addWorkspace(sceneManager_, renderWindow_, camera_, workspaceName, true);

   guiRenderer_ = &CEGUI::OgreRenderer::bootstrapSystem(*renderWindow_); // CEGUI::OgreRenderer* in header
   
   Ogre::ResourceGroupManager& resManager = Ogre::ResourceGroupManager::getSingleton();
   resManager.addResourceLocation("media/cegui/imagesets", "FileSystem", "Imagesets");
   resManager.addResourceLocation("media/cegui/fonts", "FileSystem", "Fonts");
   resManager.addResourceLocation("media/cegui/layouts", "FileSystem", "Layouts");
   resManager.addResourceLocation("media/cegui/looknfeel", "FileSystem", "LookNFeel");
   resManager.addResourceLocation("media/cegui/schemes", "FileSystem", "Schemes");

   Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

   CEGUI::ImageManager::setImagesetDefaultResourceGroup("Imagesets");
   CEGUI::Font::setDefaultResourceGroup("Fonts");
   CEGUI::Scheme::setDefaultResourceGroup("Schemes");
   CEGUI::SchemeManager::getSingleton().createFromFile("Generic.scheme");
   CEGUI::WidgetLookManager::setDefaultResourceGroup("LookNFeel");
   CEGUI::WindowManager::setDefaultResourceGroup("Layouts");

   CEGUI::WindowManager &wmgr = CEGUI::WindowManager::getSingleton();
   sheet_ = wmgr.createWindow("DefaultWindow", "CEGUIDemo/Sheet"); // CEGUI::Window* in header
   CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(sheet_);

   root_.addFrameListener(&(GameUI::getInstance())); // Must be some class that is a child of Ogre::FrameListener

Virtual function that the child of Ogre::FrameListener must contain:

Code: Select all

bool GameUI::frameRenderingQueued(const Ogre::FrameEvent &evt) {
   CEGUI::System::getSingleton().injectTimePulse(evt.timeSinceLastFrame);
   CEGUI::System& guiSystem = CEGUI::System::getSingleton();
   guiSystem.injectTimePulse(evt.timeSinceLastEvent);

   CEGUI::Renderer* guiRenderer(guiSystem.getRenderer());

   guiRenderer->beginRendering();

   guiSystem.getDefaultGUIContext().injectTimePulse(evt.timeSinceLastEvent);
   guiSystem.getDefaultGUIContext().draw();

   guiRenderer->endRendering();

   CEGUI::WindowManager::getSingleton().cleanDeadPool();
   return true;
}

For completeness, to have Ogre work with SDL2, this should me placed in the location marked in the first code sample:

Code: Select all

   if(SDL_Init( SDL_INIT_EVERYTHING ) != 0){
      throw(std::runtime_error("Cannot initialise SDL2"));
   }
      sdlWindow_ = SDL_CreateWindow("Warheart", SDL_WINDOWPOS_UNDEFINED_DISPLAY(0), SDL_WINDOWPOS_UNDEFINED_DISPLAY(0), prefs.displayWidth, prefs.displayHeight, SDL_WINDOW_SHOWN | (prefs.fullscreen ? SDL_WINDOW_FULLSCREEN : 0) | SDL_WINDOW_RESIZABLE); // SDL_Window* in header
      
   // The rest of code gets the window's native handle and inserts it into the parameters for Ogre's createRenderWindow so that it would render in SDL2's window instead of a new window (pasted from an Ogre sample)
   
   SDL_SysWMinfo wmInfo; //Get the native whnd, necessary to make Ogre use the SDL2 window
   SDL_VERSION( &wmInfo.version );
   if(SDL_GetWindowWMInfo(sdlWindow_, &wmInfo) == SDL_FALSE)
      throw(std::runtime_error("Could not get WM Info of the SDL2 window"));
   Ogre::String winHandle;
   switch( wmInfo.subsystem )
   {
#ifdef WIN32
      case SDL_SYSWM_WINDOWS:
         // Windows code
         winHandle = Ogre::StringConverter::toString((uintptr_t)wmInfo.info.win.window);
         break;
#elif __MACOSX__
      case SDL_SYSWM_COCOA:
         //required to make OGRE play nice with our window
         params.insert(std::make_pair("macAPI", "cocoa"));
         params.insert(std::make_pair("macAPICocoaUseNSView", "true"));
         winHandle = Ogre::StringConverter::toString(WindowContentViewHandle(wmInfo));
         break;
#else
      case SDL_SYSWM_X11:
         winHandle = Ogre::StringConverter::toString((uintptr_t)wmInfo.info.x11.window);
         break;
#endif
      default:
         throw(std::runtime_error("Received an unusual WM Info"));
         break;
   }
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
   params.insert( std::make_pair("externalWindowHandle",  winHandle) );
#else
   params.insert( std::make_pair("parentWindowHandle",  winHandle) );
#endif

YaronCT
CEGUI Team
Posts: 448
Joined: Fri Jun 19, 2015 12:18
Location: Kiryat-Bialik, Israel

Re: [solved] How do I set up CEGUI on Ogre 2.1? Default GUI context isn't a rendering window?

Postby YaronCT » Fri Jul 15, 2016 16:54

Several remarks:

* You shouldn't do "#define CEGUI_USE_OGRE_COMPOSITOR2". It's automatically done when necessary.

* "CEGUI::System::getSingleton().getDefaultGUIContext().isRenderingWindow()" returns "false" because a rendering window isn't what you'd perhaps epexct - it's a "RenderingSurface" that can be "drawn back" onto another "RenderingSurface" and is primarily intended to be used as a kind of cache for rendered imagery. Perhaps its name is indeed confusing and perhaps we'll change it. However, "dynamic_cast<CEGUI::OgreWindowTarget*>(&CEGUI::System::getSingleton().getDefaultGUIContext().getRenderTarget()) != 0" should b true, which is prolly what u were looking to check.

* "guiRenderer_->isRenderingEnabled()" returns "false" because enabling rendering in the cegui Ogre renderer means the cegui Ogre renderer registers itself as a frame listener and overrides "Ogre::FrameListener::frameRenderingQueued", in which it calls "CEGUI::System::getSingleton().renderAllGUIContexts()". Perhaps its name is indeed confusing and perhaps we'll change it. Anyway I'd recommend u in general to avoid doing "CEGUI::OgreRenderer::setRenderingEnabled(true)" - do the rendering yourself (like u do).

* I think in general in Ogre all rendering should be done in an override of "Ogre::FrameListener::frameRenderingQueued". I don't think it's specific to Ogre 2 or to cegui.

Dugi
Just popping in
Just popping in
Posts: 14
Joined: Fri Apr 17, 2015 20:41

Re: [solved] How do I set up CEGUI on Ogre 2.1? Default GUI context isn't a rendering window?

Postby Dugi » Fri Jul 15, 2016 20:03

YaronCT wrote:You shouldn't do "#define CEGUI_USE_OGRE_COMPOSITOR2". It's automatically done when necessary.
I have tried to remove it and when I did it, nothing was changed. Good to know that it's good to be removed.
YaronCT wrote: "CEGUI::System::getSingleton().getDefaultGUIContext().isRenderingWindow()" returns "false" because a rendering window isn't what you'd perhaps epexct...
Aha. This explains a lot. The misconception totally misdirected me from the actual problem.
YaronCT wrote: "guiRenderer_->isRenderingEnabled()" returns "false" because enabling rendering in the cegui Ogre renderer means the cegui Ogre renderer registers itself as a frame listener...
It returned true. I don't enable rendering in guiRenderer_, though. I am not sure what is going on.
YaronCT wrote:I think in general in Ogre all rendering should be done in an override of "Ogre::FrameListener::frameRenderingQueued". I don't think it's specific to Ogre 2 or to cegui.
Thanks for this information. I wasn't using any FrameListeners, I found them quite nontransparent, my code calls Ogre code, Ogre code then calls my code that again calls Ogre...

Thank you for your valuable remarks.

YaronCT
CEGUI Team
Posts: 448
Joined: Fri Jun 19, 2015 12:18
Location: Kiryat-Bialik, Israel

Re: [solved] How do I set up CEGUI on Ogre 2.1? Default GUI context isn't a rendering window?

Postby YaronCT » Sat Jul 16, 2016 12:14

Dugi wrote:my code calls Ogre code, Ogre code then calls my code that again calls Ogre...


Can u plz b more specific about function names?


Return to “Help”

Who is online

Users browsing this forum: Bing [Bot] and 5 guests