how to use cegui0.7.1 in ogre1.7(solved)

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

haibo19981984
Just popping in
Just popping in
Posts: 10
Joined: Wed May 06, 2009 06:37

how to use cegui0.7.1 in ogre1.7(solved)

Postby haibo19981984 » Thu Mar 04, 2010 14:39

At first,I create a simple ogre's project which can show a ground in 3D space.
It runs triumphantly.
Then I try to add a cegui's mouse in the project.
After I spend some time to search the forums,I get some code which is half-baked.
However,I'm confused about loading cegui's resource.
For example,it always occurs error that "TaharezLook.scheme" can not be found.
So I think my code which loads cegui's resource is not correct.
But I don't know where is not correct.
By the way,I had built the ogre1.7 and cegui0.7.1 triumphantly and run the cegui's
sample triumphantly.
At the same time,copy all .dll and .lib in my project.

my project's frame:
E:\ogrework\samples1\testCegui // my project
E:\ogrework\datafiles // cegui's resource
E:\ogrework\samples1\Include\CEGUI // cegui's include
E:\ogrework\samples1\lib\debug // cegui's lib
E:\ogrework\bin\debug // cegui's and ogre's .dll
E:\ogrework\bin\media // ogre's resource

my project's include path:
"$(OGRE_HOME)\OgreMain\include";
"$(OGRE_HOME)\include";
"$(OGRE_HOME)\Dependencies\include";
..\Include\cegui

my project's lib path:
"$(OGRE_HOME)\lib\$(ConfigurationName)";
"$(OGRE_HOME)\Dependencies\lib\$(ConfigurationName)";
"..\lib\$(ConfigurationName)";

my project's lib:
OgreMain_d.lib
OIS_d.lib
CEGUIBase_d.lib
CEGUIOgreRenderer_d.lib

my project's code:

Code: Select all

#include "ExampleApplication.h"
#include "CEGUI.h"
#include "RendererModules/Ogre/CEGUIOgreRenderer.h"
class MyListener : public ExampleFrameListener
{
public:
   SceneManager* mSceneMgr;
public:
   MyListener(SceneManager *sceneMgr, RenderWindow* win, Camera* cam)
      : ExampleFrameListener(win, cam)
      , mSceneMgr(sceneMgr)
   {
   }
   bool frameStarted(const FrameEvent& evt)
   {
      if (!ExampleFrameListener::frameStarted(evt))
         return false;
      return true;
   }
};
class test : public ExampleApplication
{
public:
   test()
   {}
   ~test()
   {
      unloadCEGUIResoure();
   }
   void loadCEGUIResource()
   {
      // initialise the required dirs for the DefaultResourceProvider
      CEGUI::DefaultResourceProvider* rp = (CEGUI::DefaultResourceProvider*)
         (CEGUI::System::getSingleton().getResourceProvider());

      rp->setResourceGroupDirectory("schemes", "../datafiles/schemes/");
      rp->setResourceGroupDirectory("imagesets", "../datafiles/imagesets/");
      rp->setResourceGroupDirectory("fonts", "../datafiles/fonts/");
      rp->setResourceGroupDirectory("layouts", "../datafiles/layouts/");
      rp->setResourceGroupDirectory("looknfeels", "../datafiles/looknfeel/");
      rp->setResourceGroupDirectory("lua_scripts", "../datafiles/lua_scripts/");

      // set the default resource groups to be used
      CEGUI::Imageset::setDefaultResourceGroup("imagesets");
      CEGUI::Font::setDefaultResourceGroup("fonts");
      CEGUI::Scheme::setDefaultResourceGroup("schemes");
      CEGUI::WidgetLookManager::setDefaultResourceGroup("looknfeels");
      CEGUI::WindowManager::setDefaultResourceGroup("layouts");
      CEGUI::ScriptModule::setDefaultResourceGroup("lua_scripts");
   }
   void unloadCEGUIResource()
   {
   }
   void createScene(void)
   {
      mSceneMgr->setAmbientLight( ColourValue( 1.0, 1.0, 1.0) );
      // camera
      mCamera->setPosition(Vector3(0,200,200));
      mCamera->lookAt(Vector3(0,0,0));
      // ground
      Plane plane(Vector3::UNIT_Y, 0);
      MeshManager::getSingleton().createPlane("ground",
         ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
         400,400,20,20,true,1,5,5,Vector3::UNIT_Z);
      Entity *ent3 = mSceneMgr->createEntity("GroundEntity", "ground");
      SceneNode *node3 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node3", Vector3( 0, 0, 0 ));
      node3->attachObject(ent3);
      ent3->setMaterialName("Examples/Rockwall");
      // load CEGUI resource
      loadCEGUIResource();
      // CEGUI setup   
      CEGUI::OgreRenderer& mGUIRender = CEGUI::OgreRenderer::create();
      CEGUI::System::create(mGUIRender);
      CEGUI::Window* mEditorGuiSheet = CEGUI::WindowManager::getSingleton().createWindow("DefaultWindow","Sheet");
      // Mouse
      CEGUI::SchemeManager::getSingleton().create("TaharezLook.scheme");
      CEGUI::System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");
      // add window
      CEGUI::System::getSingleton().setGUISheet(mEditorGuiSheet);
   }
   void createFrameListener(void)
   {
      mFrameListener = new MyListener(mSceneMgr, mWindow, mCamera);
      mRoot->addFrameListener(mFrameListener);
   }
};

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char **argv)
#endif
{
   test app;
   try {
      app.go();
   } catch( Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
      MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!",
         MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
      fprintf(stderr, "An exception has occured: %s\n",
         e.getFullDescription().c_str());
#endif
   }
   return 0;
}

Last edited by haibo19981984 on Fri Mar 05, 2010 01:50, edited 2 times in total.

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

Re: how to use cegui0.7.1 in ogre1.7

Postby CrazyEddie » Thu Mar 04, 2010 15:02

You're currently using the non-Ogre specific resource loading and image codec systems. This may be what you intended, in which case that's fine, though since you have this issue, I'm guessing that it's not what you intended at all. So, I'll address that issue first, otherwise it will lead to more headaches down the road.

Basically, as you may know, Ogre has it's own resource management systems and it's own image codec system to process loaded image files. In order to have CEGUI use these, you need to pass instances of the appropriate objects to the System::create function. Because that's all too much of a pain, we have provided some simple helper functions to do that work for you. So to initialise the system for Ogre, you just need to make the following call:

Code: Select all

CEGUI::OgreRenderer& mGUIRender = CEGUI::OgreRenderer::bootstrapSystem();

Note that you do not need to call System::create when you use this approach, as that's all done for you.

Using this approach, the resource provider is no longer an instance of CEGUI::DefaultResourceProvider, so you should not use the code you posted, since it will crash the app. Instead, you should set your resource groups via the usual Ogre methods. You do still need to set the CEGUI default resource groups, though.

The approach you take could be like this:

Code: Select all

    Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../datafiles/schemes", "FileSystem", "schemes");
    Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../datafiles/imagesets", "FileSystem", "imagesets");
    Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../datafiles/fonts", "FileSystem", "fonts");
    Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../datafiles/layouts", "FileSystem", "layouts");
    Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../datafiles/looknfeel", "FileSystem", "looknfeels");
    Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../datafiles/lua_scripts", "FileSystem", "lua_scripts");


Aside from all of this, if the system can't find the file(s), then the files do not exist in the specified locations! Those relative paths you specified will be taken from the working directory at the given time. Usually this is the same directory location that contains the .exe file, though may not be - for instance, under the MSVC++ debugger, the working directory defaults to some other location.

CE.

haibo19981984
Just popping in
Just popping in
Posts: 10
Joined: Wed May 06, 2009 06:37

Re: how to use cegui0.7.1 in ogre1.7

Postby haibo19981984 » Fri Mar 05, 2010 01:34

Thanks for you reply,CrazyEddie.
My problem is solved.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 13 guests