Problem when making 'Hello World' @_@

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

NewAce
Just popping in
Just popping in
Posts: 5
Joined: Wed Jan 30, 2008 17:51

Problem when making 'Hello World' @_@

Postby NewAce » Wed Jan 30, 2008 19:07

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?

Rackle
CEGUI Team (Retired)
Posts: 534
Joined: Mon Jan 16, 2006 11:59
Location: Montréal

Postby Rackle » Wed Jan 30, 2008 19:33

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);
    }

NewAce
Just popping in
Just popping in
Posts: 5
Joined: Wed Jan 30, 2008 17:51

Postby NewAce » Thu Jan 31, 2008 12:20

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   


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

Postby CrazyEddie » Thu Jan 31, 2008 13:15

Code: Select all

#include <CEGUIFontManager.h>

:?:

NewAce
Just popping in
Just popping in
Posts: 5
Joined: Wed Jan 30, 2008 17:51

Postby NewAce » Fri Feb 01, 2008 14:37

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.

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Fri Feb 01, 2008 20:43

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.
Check out my released snake game using Cegui!

NewAce
Just popping in
Just popping in
Posts: 5
Joined: Wed Jan 30, 2008 17:51

Postby NewAce » Sat Feb 02, 2008 06:18

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);
   }
};

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

Postby CrazyEddie » Sat Feb 02, 2008 08:51

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}" );

NewAce
Just popping in
Just popping in
Posts: 5
Joined: Wed Jan 30, 2008 17:51

Postby NewAce » Sat Feb 02, 2008 09:35

Success. 'Hello World' is appeared.

The case is solved. Thanks anyway. :)


Return to “Help”

Who is online

Users browsing this forum: No registered users and 29 guests