Page 1 of 1

[SOLVED]Problems of CEGUI and Irrlicht

Posted: Sat Jul 24, 2010 04:40
by qiao-y
Hello all,

I am using CEGUI 0.7.1 and Irrlicht-1.7.1 and have managed to run some basic applications. I wanted to set a static text window to display the FPS in real-time. However, when I was trying to set the text of a static text window within the main loop, a problem occurred. The engine only renders the CEGUI window, and all the Irrlicht scene nodes were not rendered. I've searched the solutions for hours and I couldn't find one... Please help me. Thanks.
The problem seems to be similiar tohttp://www.cegui.org.uk/phpBB2/viewtopic.php?f=10&t=4992, but I do not use OGRE...

IDE:Visual Studio 2008 SP1.

Log File:

Code: Select all

24/07/2010 12:06:50 (Std)    ---- Version 0.7.1 (Build: Jul 22 2010 Debug Microsoft Windows MSVC++ 9.0 32 bit) ----
24/07/2010 12:06:50 (Std)    ---- Renderer module is: CEGUI::IrrlichtRenderer - Official Irrlicht based 2nd generation renderer module.  RenderTarget support is enabled. ----
24/07/2010 12:06:50 (Std)    ---- XML Parser module is: CEGUI::ExpatParser - Official expat based parser module for CEGUI ----
24/07/2010 12:06:50 (Std)    ---- Image Codec module is: IrrlichtImageCodec - Integrated ImageCodec using the Irrlicht engine. ----
24/07/2010 12:06:50 (Std)    ---- Scripting module is: None ----



Source Code(key):

Code: Select all


   while(device->run())
   {
                  int fps = driver->getFPS();
     char * FPS = new char[10];
     itoa(fps,FPS,10);

     fWnd->setText(FPS);

     delete FPS;
                  driver->beginScene(true, true, SColor(255,100,101,140));
                  smgr->drawAll();
                  CEGUI::System::getSingleton().renderGUI();
                  driver->endScene();
   }





Re: Problems of CEGUI and Irrlicht

Posted: Sat Jul 24, 2010 07:29
by CrazyEddie
It should be:

Code: Select all

delete[] FPS;


not sure if that causes the bug, but it undoubtedly causes memory corruption, so fix that first :P

A tip: If you're doing new/delete of small data / objects at the same level in the same function, it's almost always better to use an auto variable / object instead.

CE

Re: Problems of CEGUI and Irrlicht

Posted: Sat Jul 24, 2010 08:42
by qiao-y
Thank you very much. I've fixed it and the problem still exists...

Actually, what I really want is a text window displaying the text on top of the screen. The text changes with on each frame. The code above was just for demonstration :D

So, the problem is, if SetText(maybe some other) method is called within the main loop, only CEGUI is rendered and the background is totally blank... Is it a bug or I misused CEGUI?

Thanks.

Re: Problems of CEGUI and Irrlicht

Posted: Mon Jul 26, 2010 08:41
by CrazyEddie
I'm not sure what could cause this to be honest. You're saying that if you remove the setText call, but leave everything else as-is - including the CEGUI render call - things are then drawn correctly? As in the scene and the CEGUI window (with no text!) and the CEGUI cursor?

It actually sounds like some kind of rendering state issue. though I've never heard of such things in conjunction with Irrlicht before, and absolutely never due to a simple setText call :?

CE

Re: Problems of CEGUI and Irrlicht

Posted: Mon Jul 26, 2010 13:56
by qiao-y
CrazyEddie wrote:I'm not sure what could cause this to be honest. You're saying that if you remove the setText call, but leave everything else as-is - including the CEGUI render call - things are then drawn correctly? As in the scene and the CEGUI window (with no text!) and the CEGUI cursor?

It actually sounds like some kind of rendering state issue. though I've never heard of such things in conjunction with Irrlicht before, and absolutely never due to a simple setText call :?

CE


Exactly. When I put the setText call inside the while loop, only CEGUI windows will be rendered. When I put the call outside, everything goes fine. I've beening trying hundreds of times...

Here's the code with setText call outside.

Code: Select all

#include <irrlicht.h>
#include <iostream>
#include "CEGUI.h"
#include "CEGUIBase.h"
#include "CEGUISchemeManager.h"
#include "CEGUIDefaultResourceProvider.h"
#include "CEGUIIrrlichtRenderer.h"

using namespace irr;
using namespace std;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
using namespace CEGUI;

#pragma comment(lib, "Irrlicht.lib")
#pragma comment(lib, "CEGUIBase_d.lib")
#pragma comment(lib, "CEGUIIrrlichtRenderer_d.lib")

int main()

{
   IrrlichtDevice *device =   createDevice( video::EDT_OPENGL, dimension2d<u32>(640, 480), 16,
         false, false, false, 0);

   if (!device)
      return 1;

   try{
      CEGUI::IrrlichtRenderer &CEGUIRenderer = CEGUI::IrrlichtRenderer::bootstrapSystem(*device);
   }

  catch ( CEGUI::Exception &e)
  {
     cout << e.getMessage() << endl;
  }

  CEGUI::DefaultResourceProvider * rp = static_cast<CEGUI::DefaultResourceProvider*>
       (CEGUI::System::getSingleton().getResourceProvider());

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

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

    try{
          CEGUI::SchemeManager::getSingleton().create("TaharezLook.scheme");
      }

      catch ( CEGUI::Exception &e)
     {
       cout << e.getMessage() << endl;
     }

     WindowManager& wmgr = WindowManager::getSingleton();
     Window* myRoot = wmgr.createWindow( "DefaultWindow", "root" );
     System::getSingleton().setGUISheet( myRoot );
     FrameWindow* fWnd = static_cast<FrameWindow*>(
    wmgr.createWindow( "TaharezLook/FrameWindow", "testWindow" ));
     myRoot->addChildWindow( fWnd );
    fWnd->setPosition( UVector2( UDim( 0.25f, 0 ), UDim( 0.25f, 0 ) ) );
     fWnd->setSize( UVector2( UDim( 0.5f, 0 ), UDim( 0.5f, 0 ) ) );
     fWnd->setText( "Hello World!" );
 
    device->setWindowCaption(L"Hello World!");

   IVideoDriver* driver = device->getVideoDriver();
   ISceneManager* smgr = device->getSceneManager();
    while(device->run())
   {
      driver->beginScene(true, true, SColor(255,100,101,140));
      smgr->drawAll();
      CEGUI::System::getSingleton().renderGUI();
      driver->endScene();
   }
   device->drop();
   return 0;
}



Here's the screenshot:
[img]
http://i3.6.cn/cvbnm/51/0f/f0/0a3773155 ... 44f492.png
[/img]


Here's the code with setText call outside. Problems occurred

Code: Select all

//omitted for brevity
    while(device->run())
   {
[color=#FF0000]     //here's the problem
      fWnd->setText("Hello");[/color]


      driver->beginScene(true, true, SColor(255,100,101,140));
      smgr->drawAll();
      CEGUI::System::getSingleton().renderGUI();
      driver->endScene();
   }
   device->dro


Screenshot:
[img]
http://i3.6.cn/cvbnm/ca/8c/fd/fbaffa473 ... 603ece.png
[/img]

--------------------------------------------------------------------
I've tried hunderds of times. One of my friend managed to generate the same error with the code above(Irrlicht 1.7.1 and CEGUI 0.7.1, the same as mine). But those who use OGRE has never come across the same problem. Please help :D

Many thanks again.

Re: Problems of CEGUI and Irrlicht

Posted: Tue Jul 27, 2010 01:25
by qiao-y
BTW: I found Titlebar control has no such problem just now.

Re: Problems of CEGUI and Irrlicht

Posted: Tue Jul 27, 2010 03:38
by Timo
Have you tried any of the newer versions of CEGUI, either from SVN or one the snapshots?

Because this kinda looks to me like the bug with Irrlicht renderer that was fixed some months ago. (Updating the FrameWindow causes the RTT to be redrawn which also clears the main buffer even though it shouldn't.)

Or you could try

Code: Select all

fWnd->setUsingAutoRenderingSurface(false);

to see if my theory is correct.

Re: Problems of CEGUI and Irrlicht

Posted: Tue Jul 27, 2010 04:06
by qiao-y
Thank you very much Timo. I used your code and solved the problem!!!

Code: Select all

fWnd->setUsingAutoRenderingSurface(false);


Great!

Re: [SOLVED]Problems of CEGUI and Irrlicht

Posted: Tue Jul 27, 2010 05:05
by Timo
Cool. But as I said you probably want to update CEGUI if you want to use a rendering surface for the FrameWindow. It makes rendering a lot faster. :)

Re: [SOLVED]Problems of CEGUI and Irrlicht

Posted: Tue Jul 27, 2010 08:52
by CrazyEddie
I agree. With Timo's reminder about the bug from 0.7.1, this is almost certainly fixed in the newer code, and you'd then be able to use the rendering surfaces for extra speed and other effects :)

CE.