Page 1 of 1

Problem when making 'Hello World' @_@

Posted: Wed Jan 30, 2008 19:07
by NewAce
Dear all,

I am still a noob here and still try to use CEGUI. But, I have a problem to make just a text 'Hello World' with a window. The text doesn't appear after I compile it with VS 2005 SP1.

Because i am still noob, i am still using samples in Ogre 1.4.0(using the code in basic tutorial 6) and makes changes to procedure createScene.

Here is the code

Code: Select all

 void createScene(void)
    {
       
        // Set ambient light
       mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
       // Set up GUI system
       mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mSceneMgr);
       mGUISystem = new CEGUI::System(mGUIRenderer);
       CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Informative);
        CEGUI::SchemeManager::getSingleton().loadScheme((CEGUI::utf8*)"TaharezLookSkin.scheme");
 CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();
      CEGUI::Window * mWndw = wmgr.createWindow("DefaultWindow","root");      
      CEGUI::Window* fWnd = (CEGUI::Window*)wmgr.createWindow("TaharezLook/FrameWindow", (CEGUI::utf8*)"testWindow");
      fWnd->setProperty("UnifiedXPosition", "0.1f" );
      fWnd->setProperty("UnifiedYPosition", "0.2f" );
      fWnd->setProperty("UnifiedWidth", "0.5f" );
      fWnd->setProperty("UnifiedHeight", "0.5f" );
      fWnd->setProperty("Visible", "true" );
         
      fWnd->setProperty("Text", "Hello World");
      mWndw->addChildWindow(fWnd);
      
      mGUISystem->setGUISheet(mWndw);

      

    }


Why the text 'Hello World' doesn't appear?

Posted: Wed Jan 30, 2008 19:33
by Rackle
Looks like you are not creating a font. Looking through the cegui.log file should change this suspicion into a certainty.

WidgetGalore is useful to rapidly figure out how to use the various widgets. However it's also a working program. There is a small initialization section followed by numerous sections, one per widget. Here's that initialization:

Code: Select all

// Retrieve the window manager
WindowManager& winMgr = WindowManager::getSingleton();

// Load the TaharezLook scheme and set up the default mouse cursor and font
SchemeManager::getSingleton().loadScheme("TaharezLook.scheme");
System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");
FontManager::getSingleton().createFont("Commonwealth-10.font");

// Set the GUI Sheet
Window* sheet = winMgr.createWindow("DefaultWindow", "root_wnd");
System::getSingleton().setGUISheet(sheet);

// Load a layout
Window* guiLayout = winMgr.loadWindowLayout("WidgetGalore.layout");
sheet->addChildWindow(guiLayout);



I've modified your code into the following

Code: Select all

void createScene(void)
    {
        // Set ambient light
       mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));

       // Set up GUI system
       mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mSceneMgr);
       mGUISystem = new CEGUI::System(mGUIRenderer);
       CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Informative);

       // Retrieve the window manager
       CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();

       // Load the TaharezLook scheme and set up the default mouse cursor and font
       CEGUI::SchemeManager::getSingleton().loadScheme("TaharezLook.scheme"); // or "TaharezLookSkin.scheme"
       CEGUI::System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");
       CEGUI::FontManager::getSingleton().createFont("Commonwealth-10.font");

       // Set the GUI Sheet
       CEGUI::Window* sheet = winMgr.createWindow("DefaultWindow", "root_wnd");
       CEGUI::System::getSingleton().setGUISheet(sheet);

       // Load or program a layout
       CEGUI::Window * mWndw = winMgr.createWindow("DefaultWindow","root");       
       CEGUI::Window* fWnd = (CEGUI::Window*)wmgr.createWindow("TaharezLook/FrameWindow", "testWindow");
       fWnd->setProperty("UnifiedXPosition", "0.1f" );
       fWnd->setProperty("UnifiedYPosition", "0.2f" );
       fWnd->setProperty("UnifiedWidth", "0.5f" );
       fWnd->setProperty("UnifiedHeight", "0.5f" );
       fWnd->setProperty("Visible", "true" );
       fWnd->setProperty("Text", "Hello World");
       sheet->addChildWindow(fWnd);
    }

Posted: Thu Jan 31, 2008 12:20
by NewAce
Compile error.

here is the error message.

Code: Select all

Error   1   error C2027: use of undefined type 'CEGUI::FontManager'
Error   2   error C2228: left of '.createFont' must have class/struct/union   
Error   3   error C3861: 'getSingleton': identifier not found   


Posted: Thu Jan 31, 2008 13:15
by CrazyEddie

Code: Select all

#include <CEGUIFontManager.h>

:?:

Posted: Fri Feb 01, 2008 14:37
by NewAce
After I compile it, I found only blind screen. Urghhhhh..... (what happen to me).

Fyi, I make modification because I cannot create Commonwealth-10.font. I don't have Commonwealth-10.font in my resource.

However, if I change the code to

Code: Select all

 CEGUI::FontManager::getSingleton().createFont("BlueHighway-12.font");
      


the exception is occured because the font is already in the resource.

If I use the font that not included in the resource, the excepption is also occured because the font is not found.

Urghhh...
So, I change the code to

Code: Select all

if(!CEGUI::FontManager::getSingleton().isFontPresent("BlueHighway-12"))
         CEGUI::FontManager::getSingleton().createFont("BlueHighway-12.font");


No exception is occured. But I found only blind screen.

Posted: Fri Feb 01, 2008 20:43
by scriptkid
Okay, then your .scheme file probably includes multiple fonts. The first font which is loaded by Cegui becomes the default font, and in your case it's probably not the blue highway one. Please do the following:

call

Code: Select all

System::getSingleton().setDefaultFont("BlueHighway-12");


That should render your 'hello world'.

HTH.

Posted: Sat Feb 02, 2008 06:18
by NewAce
Not Work. :(. I am so bad..

To make my explanation more clear, I will post my class here. I am using sample in Ogre SDK 1.4.x

Code: Select all

#include <OgreNoMemoryMacros.h>
#include <CEGUI/CEGUIImageset.h>
#include <CEGUI/CEGUISystem.h>
#include <CEGUI/CEGUILogger.h>
#include <CEGUI/CEGUISchemeManager.h>
#include <CEGUI/CEGUIWindowManager.h>
#include <CEGUI/CEGUIWindow.h>
#include <CEGUIFontManager.h>
#include "OgreCEGUIRenderer.h"
#include "OgreCEGUIResourceProvider.h"
//regular mem handler
#include <OgreMemoryMacros.h>
#include <CEGUI/elements/CEGUIPushButton.h>
#include "ExampleApplication.h"

class GuiFrameListener : public ExampleFrameListener
{
private:
  CEGUI::Renderer* mGUIRenderer;
public:
  GuiFrameListener(RenderWindow* win, Camera* cam, CEGUI::Renderer* renderer)
    : ExampleFrameListener(win, cam, false, false),
      mGUIRenderer(renderer)
  {
  }
};

class TutorialApplication : public ExampleApplication
{
private:
   CEGUI::OgreCEGUIRenderer* mGUIRenderer;
   CEGUI::System* mGUISystem;
   CEGUI::Window* mEditorGuiSheet;
public:
   TutorialApplication()
      : mGUIRenderer(0),
        mGUISystem(0),
        mEditorGuiSheet(0)
    {
    }

    ~TutorialApplication()
    {
       if(mEditorGuiSheet)
       {
           CEGUI::WindowManager::getSingleton().destroyWindow(mEditorGuiSheet);
       }
       if(mGUISystem)
       {
           delete mGUISystem;
           mGUISystem = 0;
       }
       if(mGUIRenderer)
       {
           delete mGUIRenderer;
           mGUIRenderer = 0;
       }
    }
protected:
    void createScene(void)
    {
       
      // Set ambient light
       mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
      // Set up GUI system
       mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mSceneMgr);
       mGUISystem = new CEGUI::System(mGUIRenderer);
       CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Informative);
      

      // Retrieve the window manager
       CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();

       // Load the TaharezLook scheme and set up the default mouse cursor and font
       CEGUI::SchemeManager::getSingleton().loadScheme("TaharezLookSkin.scheme");
       CEGUI::System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");
      if(!CEGUI::FontManager::getSingleton().isFontPresent("BlueHighway-12")){
         CEGUI::FontManager::getSingleton().createFont("BlueHighway-12.font");
      }
      CEGUI::System::getSingleton().setDefaultFont("BlueHighway-12");
       // Set the GUI Sheet
       CEGUI::Window* sheet = winMgr.createWindow("DefaultWindow", "root_wnd");
       CEGUI::System::getSingleton().setGUISheet(sheet);

       // Load or program a layout
       CEGUI::Window * mWndw = winMgr.createWindow("DefaultWindow","root");       
       CEGUI::Window* fWnd = (CEGUI::Window*)winMgr.createWindow("TaharezLook/FrameWindow", "testWindow");
       fWnd->setProperty("UnifiedXPosition", "0.1f" );
       fWnd->setProperty("UnifiedYPosition", "0.2f" );
       fWnd->setProperty("UnifiedWidth", "0.5f" );
       fWnd->setProperty("UnifiedHeight", "0.5f" );
       fWnd->setProperty("Visible", "true" );
       fWnd->setProperty("Text", "Hello World");
       sheet->addChildWindow(fWnd);
    }
   void createFrameListener(void)
   {
       mFrameListener = new GuiFrameListener(mWindow, mCamera, mGUIRenderer);
       mRoot->addFrameListener(mFrameListener);
   }
};

Posted: Sat Feb 02, 2008 08:51
by CrazyEddie
We're all terribe for not spotting this from your first post, but anyway, here goes...

These lines are totally incorrect:

Code: Select all

fWnd->setProperty("UnifiedXPosition", "0.1f" );
fWnd->setProperty("UnifiedYPosition", "0.2f" );
fWnd->setProperty("UnifiedWidth", "0.5f" );
fWnd->setProperty("UnifiedHeight", "0.5f" );

They should be:

Code: Select all

fWnd->setProperty("UnifiedXPosition", "{0.1,0}" );
fWnd->setProperty("UnifiedYPosition", "{0.2,0}" );
fWnd->setProperty("UnifiedWidth", "{0.5,0}" );
fWnd->setProperty("UnifiedHeight", "{0.5,0}" );

Posted: Sat Feb 02, 2008 09:35
by NewAce
Success. 'Hello World' is appeared.

The case is solved. Thanks anyway. :)