Page 1 of 1

Problem with xerces.

Posted: Tue Nov 17, 2009 17:20
by Antares
Hi, I'm new in this board but I have already search for a similar problem.

The source code :

Code: Select all

 /*
 * Adapted by: Johnny Souza - johnnysouza.js@gmail.com
 * Date: 19/01/07 17:00
 * Description: Using CEGUI with SDL and OpenGL
 */

#include <stdio.h>
#include <stdlib.h>

#include <SDL/SDL.h>

#include <CEGUI/CEGUI.h>
/* for release 0.4.X use:
 * #include <renderers/OpenGLGUIRenderer/openglrenderer.h>
 */
#include <CEGUI/RendererModules/OpenGLGUIRenderer/openglrenderer.h>

#include <GL/gl.h>
#include <GL/glu.h>
#include <CEGUIDefaultResourceProvider.h>
#include <CEGUI/XMLParserModules/XercesParser/CEGUIXercesParser.h>
CEGUI::OpenGLRenderer *renderer;
using namespace CEGUI;


void handle_mouse_down(Uint8 button)
{
   switch ( button ) {
      case SDL_BUTTON_LEFT:
         CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);
         break;
      case SDL_BUTTON_MIDDLE:
         CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::MiddleButton);
         break;
      case SDL_BUTTON_RIGHT:
         CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);
         break;

      case SDL_BUTTON_WHEELDOWN:
         CEGUI::System::getSingleton().injectMouseWheelChange( -1 );
         break;
      case SDL_BUTTON_WHEELUP:
         CEGUI::System::getSingleton().injectMouseWheelChange( +1 );
         break;
   }
}


void handle_mouse_up(Uint8 button)
{
   switch ( button )
   {
      case SDL_BUTTON_LEFT:
         CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);
         break;
      case SDL_BUTTON_MIDDLE:
         CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::MiddleButton);
         break;
      case SDL_BUTTON_RIGHT:
         CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);
         break;
   }
}


void inject_input (bool & must_quit)
{
   SDL_Event e;
   /* go through all available events */
   while (SDL_PollEvent(&e)) {
      /* we use a switch to determine the event type */
      switch (e.type) {
         /* mouse motion handler */
         case SDL_MOUSEMOTION:
            /* we inject the mouse position directly. */
            CEGUI::System::getSingleton().injectMousePosition(static_cast<float>(e.motion.x),static_cast<float>(e.motion.y));
            break;

         /* mouse down handler */
         case SDL_MOUSEBUTTONDOWN:
            /* let a special function handle the mouse button down event */
            handle_mouse_down (e.button.button);
            break;

         /* mouse up handler */
         case SDL_MOUSEBUTTONUP:
            /* let a special function handle the mouse button up event */
            handle_mouse_up (e.button.button);
            break;

         /* key down */
         case SDL_KEYDOWN:
            /* to tell CEGUI that a key was pressed, we inject the scancode. */
            CEGUI::System::getSingleton().injectKeyDown(e.key.keysym.scancode);
            /* as for the character it's a litte more complicated.
             * we'll use for translated unicode value.
             * this is described in more detail below.
             */
            if ((e.key.keysym.unicode & 0xFF80) == 0) {
               CEGUI::System::getSingleton().injectChar(e.key.keysym.unicode & 0x7F);
            }
            break;

         /* key up */
         case SDL_KEYUP:
            /* like before we inject the scancode directly. */
            CEGUI::System::getSingleton().injectKeyUp(e.key.keysym.scancode);
            break;

         /* WM quit event occured */
         case SDL_QUIT:
            must_quit = true;
            break;

         case SDL_VIDEORESIZE:
            renderer->setDisplaySize(CEGUI::Size(e.resize.w, e.resize.h));
            break;
      }
   }
}


void inject_time_pulse(double& last_time_pulse)
{
   /* get current "run-time" in seconds */
   double t = 0.001*SDL_GetTicks();
   /* inject the time that passed since the last call */
   CEGUI::System::getSingleton().injectTimePulse( float(t-last_time_pulse) );
   /* store the new time as the last time */
   last_time_pulse = t;
}

void render_gui()
{
   /* clear the colour buffer */
   glClear( GL_COLOR_BUFFER_BIT );
   /* render the GUI :) */
   CEGUI::System::getSingleton().renderGUI();
   /* Update the screen */
   SDL_GL_SwapBuffers();
}


void main_loop ()
{
   bool must_quit = false;
   /* get "run-time" in seconds */
   double last_time_pulse = 0.001*static_cast<double>(SDL_GetTicks());
   while (!must_quit) {
      inject_input (must_quit);
      inject_time_pulse (last_time_pulse);
      render_gui ();
   }
}


int main (int argc, char **argv)
{
   SDL_Surface * screen;
   atexit (SDL_Quit);
   SDL_Init (SDL_INIT_VIDEO);
   screen = SDL_SetVideoMode (600, 480, 0, SDL_OPENGL);
   if (screen == NULL) {
      /* Se ainda não der, desiste! */
      fprintf (stderr, "Impossível ajustar ao vídeo: %s\n", SDL_GetError ());
      exit (1);
   }
   renderer = new CEGUI::OpenGLRenderer (0, 600, 480);
   new CEGUI::System (renderer);


   // setup default group for validation schemas
   // initialise the required dirs for the DefaultResourceProvider
    CEGUI::DefaultResourceProvider* rp = static_cast<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/");

    rp->setResourceGroupDirectory("schemas", "./");

    CEGUI::XercesParser::setSchemaDefaultResourceGroup("schemas");

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

    SchemeManager::getSingleton().loadScheme("TaharezLook.scheme");
    System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");

    Window* myRoot = WindowManager::getSingleton().loadWindowLayout( "test.layout" );
    System::getSingleton().setGUISheet( myRoot );

   SDL_ShowCursor (SDL_DISABLE);
   SDL_EnableUNICODE (1);
   SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
   main_loop();
}


The log :

Code: Select all

17/11/2009 18:10:52 (InfL1)   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
17/11/2009 18:10:52 (InfL1)   +                     Crazy Eddie's GUI System - Event log                    +
17/11/2009 18:10:52 (InfL1)   +                          (http://www.cegui.org.uk/)                         +
17/11/2009 18:10:52 (InfL1)   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

17/11/2009 18:10:52 (InfL1)   CEGUI::Logger singleton created.
17/11/2009 18:10:52 (InfL1)   ---- Begining CEGUI System initialisation ----
17/11/2009 18:10:52 (InfL1)   CEGUI::ImagesetManager singleton created
17/11/2009 18:10:52 (InfL1)   CEGUI::FontManager singleton created.
17/11/2009 18:10:52 (InfL1)   CEGUI::WindowFactoryManager singleton created
17/11/2009 18:10:52 (InfL1)   CEGUI::WindowManager singleton created
17/11/2009 18:10:52 (InfL1)   CEGUI::SchemeManager singleton created.
17/11/2009 18:10:52 (InfL1)   CEGUI::MouseCursor singleton created.
17/11/2009 18:10:52 (InfL1)   CEGUI::GlobalEventSet singleton created.
17/11/2009 18:10:52 (InfL1)   CEGUI::WidgetLookManager singleton created.
17/11/2009 18:10:52 (InfL1)   CEGUI::WindowRendererManager singleton created
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'DefaultWindow' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'DragContainer' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'ScrolledContainer' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'ClippedContainer' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/Checkbox' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/PushButton' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/RadioButton' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/Combobox' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/ComboDropList' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/Editbox' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/FrameWindow' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/ItemEntry' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/Listbox' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/ListHeader' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/ListHeaderSegment' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/Menubar' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/PopupMenu' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/MenuItem' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/MultiColumnList' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/MultiLineEditbox' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/ProgressBar' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/ScrollablePane' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/Scrollbar' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/Slider' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/Spinner' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/TabButton' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/TabControl' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/Thumb' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/Titlebar' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/Tooltip' windows added.
17/11/2009 18:10:52 (InfL1)   WindowFactory for 'CEGUI/ItemListbox' windows added.
17/11/2009 18:10:52 (InfL1)   Window type alias named 'DefaultGUISheet' added for window type 'DefaultWindow'.
17/11/2009 18:10:52 (InfL1)   CEGUI::System singleton created.
17/11/2009 18:10:52 (InfL1)   ---- CEGUI System initialisation completed ----
17/11/2009 18:10:52 (InfL1)   ---- Version 0.5.0 ----
17/11/2009 18:10:52 (InfL1)   ---- Renderer module is: CEGUI::OpenGLRenderer - Official OpenGL based renderer module for CEGUI ----
17/11/2009 18:10:52 (InfL1)   ---- XML Parser module is: CEGUI::XercesParser - Official Xerces-C++ based parser module for CEGUI ----
17/11/2009 18:10:52 (InfL1)   ---- Scripting module is: None ----
17/11/2009 18:10:52 (InfL1)   Attempting to load Scheme from file 'TaharezLook.scheme'.
17/11/2009 18:10:52 (InfL1)   XercesParser::initialiseSchema - Attempting to load schema from file 'GUIScheme.xsd'.
17/11/2009 18:10:52 (InfL1)   XercesParser::initialiseSchema - XML schema file 'GUIScheme.xsd' has been initialised.
17/11/2009 18:10:52 (InfL1)   Attempting to create an Imageset from the information specified in file 'TaharezLook.imageset'.
17/11/2009 18:10:52 (InfL1)   XercesParser::initialiseSchema - Attempting to load schema from file 'Imageset.xsd'.
17/11/2009 18:10:52 (InfL1)   XercesParser::initialiseSchema - XML schema file 'Imageset.xsd' has been initialised.
17/11/2009 18:10:52 (InfL1)   Started creation of Imageset from XML specification:
17/11/2009 18:10:52 (InfL1)   ---- CEGUI Imageset name: TaharezLook
17/11/2009 18:10:52 (InfL1)   ---- Source texture file: TaharezLook.tga in resource group: (Default)



I think there is a problem with the ressource manager.

The window appear and disapear immediately when I run the program.

I don't understand why there is no error in the logfile, thats why I post here.

Sorry for my bad english, I'm a french.

Re: Problem with xerces.

Posted: Wed Nov 18, 2009 17:29
by Jamarr
I cannot see anything particularly wrong with your code. Then again I am not familiar with SDL, and you are using a very old version of CEGUI. One thing I did notice is that you are setting your root-window to the test window you are loading - I don't think this is typical? Typically you would create a DefaultWindow or a DefaultGUISheet, and then attach your windows to it, like so:

Code: Select all

CEGUI::Window* root = CEGUI::WindowManager::getSingleton().createWindow(_T("DefaultGUISheet"), _T("Root"));
CEGUI::System::getSingleton().setGUISheet(root);
CEGUI::Window* win = CEGUI::WindowManager::getSingleton().loadWindowLayout( "test.layout" );
root->addChildWindow(win);


Other than that, I'm not sure what might cause the window to disappear.

Re: Problem with xerces.

Posted: Thu Nov 19, 2009 07:10
by Antares
Thanks for your post, I'v test this in my program like that :

Code: Select all

 /*
 * Adapted by: Johnny Souza - johnnysouza.js@gmail.com
 * Date: 19/01/07 17:00
 * Description: Using CEGUI with SDL and OpenGL
 */

#include <stdio.h>
#include <stdlib.h>

#include <SDL/SDL.h>

#include <CEGUI/CEGUI.h>
/* for release 0.4.X use:
 * #include <renderers/OpenGLGUIRenderer/openglrenderer.h>
 */
#include <CEGUI/RendererModules/OpenGLGUIRenderer/openglrenderer.h>

#include <GL/gl.h>
#include <GL/glu.h>
#include <CEGUIDefaultResourceProvider.h>
#include <CEGUI/XMLParserModules/XercesParser/CEGUIXercesParser.h>
CEGUI::OpenGLRenderer *renderer;
using namespace CEGUI;


void handle_mouse_down(Uint8 button)
{
   switch ( button ) {
      case SDL_BUTTON_LEFT:
         CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);
         break;
      case SDL_BUTTON_MIDDLE:
         CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::MiddleButton);
         break;
      case SDL_BUTTON_RIGHT:
         CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);
         break;

      case SDL_BUTTON_WHEELDOWN:
         CEGUI::System::getSingleton().injectMouseWheelChange( -1 );
         break;
      case SDL_BUTTON_WHEELUP:
         CEGUI::System::getSingleton().injectMouseWheelChange( +1 );
         break;
   }
}


void handle_mouse_up(Uint8 button)
{
   switch ( button )
   {
      case SDL_BUTTON_LEFT:
         CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);
         break;
      case SDL_BUTTON_MIDDLE:
         CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::MiddleButton);
         break;
      case SDL_BUTTON_RIGHT:
         CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);
         break;
   }
}


void inject_input (bool & must_quit)
{
   SDL_Event e;
   /* go through all available events */
   while (SDL_PollEvent(&e)) {
      /* we use a switch to determine the event type */
      switch (e.type) {
         /* mouse motion handler */
         case SDL_MOUSEMOTION:
            /* we inject the mouse position directly. */
            CEGUI::System::getSingleton().injectMousePosition(static_cast<float>(e.motion.x),static_cast<float>(e.motion.y));
            break;

         /* mouse down handler */
         case SDL_MOUSEBUTTONDOWN:
            /* let a special function handle the mouse button down event */
            handle_mouse_down (e.button.button);
            break;

         /* mouse up handler */
         case SDL_MOUSEBUTTONUP:
            /* let a special function handle the mouse button up event */
            handle_mouse_up (e.button.button);
            break;

         /* key down */
         case SDL_KEYDOWN:
            /* to tell CEGUI that a key was pressed, we inject the scancode. */
            CEGUI::System::getSingleton().injectKeyDown(e.key.keysym.scancode);
            /* as for the character it's a litte more complicated.
             * we'll use for translated unicode value.
             * this is described in more detail below.
             */
            if ((e.key.keysym.unicode & 0xFF80) == 0) {
               CEGUI::System::getSingleton().injectChar(e.key.keysym.unicode & 0x7F);
            }
            break;

         /* key up */
         case SDL_KEYUP:
            /* like before we inject the scancode directly. */
            CEGUI::System::getSingleton().injectKeyUp(e.key.keysym.scancode);
            break;

         /* WM quit event occured */
         case SDL_QUIT:
            must_quit = true;
            break;

         case SDL_VIDEORESIZE:
            renderer->setDisplaySize(CEGUI::Size(e.resize.w, e.resize.h));
            break;
      }
   }
}


void inject_time_pulse(double& last_time_pulse)
{
   /* get current "run-time" in seconds */
   double t = 0.001*SDL_GetTicks();
   /* inject the time that passed since the last call */
   CEGUI::System::getSingleton().injectTimePulse( float(t-last_time_pulse) );
   /* store the new time as the last time */
   last_time_pulse = t;
}

void render_gui()
{
   /* clear the colour buffer */
   glClear( GL_COLOR_BUFFER_BIT );
   /* render the GUI :) */
   CEGUI::System::getSingleton().renderGUI();
   /* Update the screen */
   SDL_GL_SwapBuffers();
}


void main_loop ()
{
   bool must_quit = false;
   /* get "run-time" in seconds */
   double last_time_pulse = 0.001*static_cast<double>(SDL_GetTicks());
   while (!must_quit) {
      inject_input (must_quit);
      inject_time_pulse (last_time_pulse);
      render_gui ();
   }
}


int main (int argc, char **argv)
{
   SDL_Surface * screen;
   atexit (SDL_Quit);
   SDL_Init (SDL_INIT_VIDEO);
   screen = SDL_SetVideoMode (600, 480, 0, SDL_OPENGL);
   if (screen == NULL) {
      /* Se ainda não der, desiste! */
      fprintf (stderr, "Impossível ajustar ao vídeo: %s\n", SDL_GetError ());
      exit (1);
   }
   renderer = new CEGUI::OpenGLRenderer (0, 600, 480);
   new CEGUI::System (renderer);


   // setup default group for validation schemas
   // initialise the required dirs for the DefaultResourceProvider
    CEGUI::DefaultResourceProvider* rp = static_cast<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/");

    rp->setResourceGroupDirectory("schemas", "./");

    CEGUI::XercesParser::setSchemaDefaultResourceGroup("schemas");

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

    SchemeManager::getSingleton().loadScheme("TaharezLook.scheme");
    System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");

CEGUI::Window* root = CEGUI::WindowManager::getSingleton().createWindow(("DefaultGUISheet"), ("Root"));
CEGUI::System::getSingleton().setGUISheet(root);
CEGUI::Window* win = CEGUI::WindowManager::getSingleton().loadWindowLayout( "test.layout" );
root->addChildWindow(win);

    Window* myRoot = WindowManager::getSingleton().loadWindowLayout( "test.layout" );
  //  System::getSingleton().setGUISheet( myRoot );

   SDL_ShowCursor (SDL_DISABLE);
   SDL_EnableUNICODE (1);
   SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
   main_loop();
}


but the log is the same and there is again the same problem.
For the version of cegui, I cannot control this because this is a scholar computer at my university on a debian lenny.
Any other idea?

Re: Problem with xerces.

Posted: Thu Nov 19, 2009 08:10
by scriptkid
Hi,

So you are seeing the window for a short while? Maybe there is something wrong with the double-buffering setup? Maybe you can simplify your code (just for testing of course) by disabling double buffering?

HTH.

Re: Problem with xerces.

Posted: Thu Nov 19, 2009 09:39
by Antares
I add this to my code : SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);

But it is the same things, maybe its my datafile who have some problem? But there no error in the log file.

I give you my test.layout :

Code: Select all

<?xml version="1.0" ?>
<GUILayout>
    <Window Type="DefaultWindow" Name="root">
        <Window Type="TaharezLook/FrameWindow" Name="testWindow">
            <Property Name="UnifiedPosition" Value="{ {0.25, 0}, {0.25, 0} }" />
            <Property Name="UnifiedSize" Value="{ {0.5, 0}, {0.5, 0} }" />
            <Property Name="Text" Value="Hello World!" />
        </Window>
    </Window>
</GUILayout>


edit: I have delete all my window, and there is the same end in the log :

Code: Select all

19/11/2009 10:43:07 (InfL1)   ---- CEGUI Imageset name: TaharezLook
19/11/2009 10:43:07 (InfL1)   ---- Source texture file: TaharezLook.tga in resource group: (Default)


I think I have a problem with the default ressource manager