Lots of questions in my first test!

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

reixons
Just popping in
Just popping in
Posts: 12
Joined: Fri Nov 28, 2008 21:40

Lots of questions in my first test!

Postby reixons » Sun Dec 14, 2008 23:26

Hi again!

First I will show you my first code running (quite nooby)

Code: Select all

#include<CEGUI/CEGUI.h>
#include<CEGUI/CEGUIDefaultResourceProvider.h>
#include<CEGUI/RendererModules/OpenGLGUIRenderer/openglrenderer.h>
using namespace CEGUI;
#include <allegro.h>
#include <GL/glut.h>
#include <iostream>
#include <GL/gl.h>
#include <GL/glu.h>
#include <SDL/SDL.h>

int main ()
{
   SDL_Surface * screen;
   atexit (SDL_Quit);
   SDL_Init (SDL_INIT_VIDEO);
   screen = SDL_SetVideoMode (600, 480, 0, SDL_OPENGL);
   
      
   CEGUI::OpenGLRenderer* myRenderer = new CEGUI::OpenGLRenderer(0, 800, 600);
   new CEGUI::System( myRenderer );
   
   //SDL_ShowCursor(SDL_DISABLE);
   // 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/");

   // This is only needed if you are using Xerces and need to
   // specify the schemas location
   rp->setResourceGroupDirectory("schemas", "../XMLRefSchema/");
   
   // 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");

   // Again, you only need to this one if you are using xerces and have
   // defined a group for schemas.
   //CEGUI::XercesParser::setSchemaDefaultResourceGroup("schemas");

   // load in the scheme file, which auto-loads the TaharezLook imageset
   CEGUI::SchemeManager::getSingleton().loadScheme( "TaharezLook.scheme" );

   // load in a font.  The first font loaded automatically becomes the default font.
   if(! CEGUI::FontManager::getSingleton().isFontPresent( "Commonwealth-10" ) )
      CEGUI::FontManager::getSingleton().createFont( "Commonwealth-10.font" );

   System::getSingleton().setDefaultFont( "Commonwealth-10" );
   System::getSingleton().setDefaultMouseCursor( "TaharezLook", "MouseArrow" );
   //System::getSingleton().setDefaultToolTip( "TaharezLook/Tooltip" );
   
   WindowManager& wmgr = WindowManager::getSingleton();
   Window* myRoot = wmgr.createWindow( "DefaultWindow", "root" );
   System::getSingleton().setGUISheet( myRoot );
   FrameWindow* fWnd = (FrameWindow*)wmgr.createWindow( "TaharezLook/FrameWindow", "testWindow" );
   myRoot->addChildWindow( fWnd );

   
   fWnd->setPosition(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.25f)));
    fWnd->setSize(UVector2(cegui_reldim(0.5f), cegui_reldim( 0.5f)));

    fWnd->setMaxSize(UVector2(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
    fWnd->setMinSize(UVector2(cegui_reldim(0.1f), cegui_reldim( 0.1f)));
   
   
   fWnd->setText( "Hello World!" );
   
   
   while (true)
   {
      glClear( GL_COLOR_BUFFER_BIT );
      CEGUI::System::getSingleton().renderGUI();      
      SDL_GL_SwapBuffers();
   }
   
}


I finally got sth drawn on the screen. Now I have some questions:

- The mouse cursor doesn't appear on screen... Why? I know I dissable it by SDL but the tutorial says that...
- If I show the mouse and I try to move the window or resize it, it doesn't work. Should it?
- When I try to integrate this code on another application that uses OpenGL I don't get the same result, I mean, the screen doesn't shows the window. Why?

Any more advices would be great!

Thanks!

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

Postby CrazyEddie » Mon Dec 15, 2008 09:53

The mouse cursor doesn't appear on screen... Why? I know I dissable it by SDL but the tutorial says that...

A minor oddity of the system is that the mouse cursor isn't shown until the first mouse movement injection occurs (actually, what is going on is that initially there is no mouse image set, and the system does not set the actual image to the specified default image until after the first mouse movement), since you do not seem to be injecting inputs (see this tutorial) this is why no CEGUI based mouse cursor is showing.

If I show the mouse and I try to move the window or resize it, it doesn't work. Should it?

Nope. Same issue as above :)

When I try to integrate this code on another application that uses OpenGL I don't get the same result, I mean, the screen doesn't shows the window. Why?

Because you've done something wrong? :) Seriously, you'll have to go through the usual diagnostic / debugging procedures, and maybe post some of the actual code for anybody to have the slightest idea - remember, we are not psychic.

HTH

CE

reixons
Just popping in
Just popping in
Posts: 12
Joined: Fri Nov 28, 2008 21:40

Postby reixons » Mon Dec 15, 2008 13:04

Ok, let's see... I have followed the whole tutorial and now in my small application I show a window and I can resize and move it. Now, I am trying to insert get CEGUI running with OpenGL and SDL in a bigger application in which I need a way of showing windows and buttons and bars etc (that is why I starte using CEGUI).

In my initialization function I have this code:

Code: Select all

GLfloat luzAmbiente[]   = {0.25, 0.2, 0.2, 1.0};
   GLfloat luzDifusa[]     = {1, 1, 1, 1.0};
   GLfloat luzEspecular[]  = {1, 1, 1, 1.0};
   GLfloat luzExponente[]  = {64.0, 64.0, 64.0, 1.0};

   // Posición de la luz en coordenadas homogéneas,
   // soluciona el bug de exception error de OpenGL (x,y,z,w)
   GLfloat luzPosicion0[]  = {100.0,    20.0,  30.0, 1.0}; 
   /*GLfloat luzPosicion1[]  = {0.0, -5000.0,    0.0, 1.0};
   GLfloat luzPosicion2[]  = {0.0,    0.0, -5000.0, 1.0};*/
   

   glEnable (GL_POLYGON_SMOOTH);
   glEnable (GL_POLYGON_SMOOTH_HINT);
   glEnable (GL_LINE_SMOOTH);
   glEnable (GL_LINE_SMOOTH_HINT);
   glEnable (GL_POINT_SMOOTH);
   glEnable (GL_POINT_SMOOTH_HINT);
   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);   
   glHint(GL_POLYGON_SMOOTH_HINT, GL_DONT_CARE);

   glEnable(GL_NORMALIZE);
   glShadeModel(GL_SMOOTH);
   glEnable (GL_CULL_FACE);
   
   // Habilita Z-Buffer, Transparencias e Iluminación
   glEnable(GL_DEPTH_TEST);
   glEnable(GL_BLEND);
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);
   glEnable(GL_LIGHT1);
   glEnable(GL_LIGHT2);

   // Habilita los materiales
   glEnable(GL_COLOR_MATERIAL);
   glMaterialfv(GL_FRONT, GL_AMBIENT, luzAmbiente);
   glMaterialfv(GL_FRONT, GL_DIFFUSE, luzDifusa);
   glMaterialfv(GL_FRONT, GL_SPECULAR, luzEspecular);
   glMaterialfv(GL_FRONT, GL_SHININESS, luzExponente);

   // Establece el foco de luz 0
   glLightfv(GL_LIGHT0, GL_DIFFUSE, luzDifusa);
   glLightfv(GL_LIGHT0, GL_SPECULAR, luzEspecular);
   glLightfv(GL_LIGHT0, GL_POSITION, luzPosicion0);

   // Establece el foco de luz 1
/*   glLightfv(GL_LIGHT1, GL_DIFFUSE, luzDifusa);
   glLightfv(GL_LIGHT1, GL_SPECULAR, luzEspecular);
   glLightfv(GL_LIGHT1, GL_POSITION, luzPosicion1);

   // Establece el foco de luz 2
   glLightfv(GL_LIGHT2, GL_DIFFUSE, luzDifusa);
   glLightfv(GL_LIGHT2, GL_SPECULAR, luzEspecular);
   glLightfv(GL_LIGHT2, GL_POSITION, luzPosicion2);*/

   // Luz Ambiente
   glLightModelfv(GL_LIGHT_MODEL_AMBIENT, luzAmbiente);
   
   
   glClearDepth(1);
   glClearColor(1.0,1.0,1.0,0.0);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   gluPerspective(theta,width/(GLfloat) height,zNear,zFar);
   glMatrixMode(GL_MODELVIEW);

   glMatrixMode(GL_TEXTURE);
   // Quitamos ésto para CEGUI de momento
   //glRotatef(180.0f,0.0f,0.0f,1.0f);
   //glScalef(-1.0f,1.0f,1.0f);
   glMatrixMode(GL_MODELVIEW);


Only if I erase the first 2 of the las 3 lines (glRotate and glScale) I see the window on the screen. But I don't see the rest of the elements that must be shown.
Imagine a 3Dgame (similar to AgeOfEmpires) in which I paint lots of 3D objects but, at the same time I want to use CEGUI to paint the bottom states bar and a lateral panel.

How should I do it? Is there any tutorial where I can get that explanation more or less?

I hope you understand what I mean...
ThankYou

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

Postby CrazyEddie » Mon Dec 15, 2008 14:29

Hi,

I had a look at our code and it seems in our per-frame set up we do not consider the texture matrix - which means it gets used in whatever state the client app leaves it in - so that's not good and is the reason the window is not showing unless you comment those lines.

You could patch the source code to include the required set up in openglrenderer.cpp in the function OpenGLRenderer::initPerFrameStates though obviously if you wish others to use your application they'd also need a patched version of CEGUI.

Another alternative would be to add a couple of lines prior to the call to CEGUI::System::getSingleton().renderGUI(); that basically push the GL_TEXTURE matrix, set the matrix back to identity, then pop it off again afterwards. So basically, maybe something like:

Code: Select all

glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();

CEGUI::System::getSingleton().renderGUI();

glPopMatrix();


We'll fix this issue in the next release.

With regards to the question about a tutorial, do you mean you want to use CEGUI to draw the status / health bars of the units in the scene? I'm not aware of any existing tutorials on how one might approach that.

CE.

Pompei2
Home away from home
Home away from home
Posts: 489
Joined: Tue May 23, 2006 16:31

Postby Pompei2 » Mon Dec 15, 2008 19:35

CrazyEddie wrote:With regards to the question about a tutorial, do you mean you want to use CEGUI to draw the status / health bars of the units in the scene? I'm not aware of any existing tutorials on how one might approach that.

@CE: No, he means show a panel with buttons for every command like attack, build, ... and a bar that shows the current gold, wood, ... amount, I think ;)

@reixons: You need to first draw all of your 3D stuff like you would draw it without CEGUI. Then you need to setup the OpenGL matrices to an ortogonal view like in the CEGUI tutorials, call CEGUI's render method. swap the GL buffers then switch back the OpenGL matrices to draw 3D later on. (PS: "Imagine a 3Dgame (similar to AgeOfEmpires)" may I ask for a link?)

reixons
Just popping in
Just popping in
Posts: 12
Joined: Fri Nov 28, 2008 21:40

Postby reixons » Mon Dec 15, 2008 22:21

Ok thanks both! I meant what Pompei2 said. I am trying to use cegui to paint the classic RTS bottom panel, where you can choose the different options (build, attack etc.)

Pompei2, I will try what you said.

Thanks both again

Pompei2
Home away from home
Home away from home
Posts: 489
Joined: Tue May 23, 2006 16:31

Postby Pompei2 » Tue Dec 16, 2008 09:49

Something else, reixon, you said these are your first tests but I see you don't use any try/catch at all.

you should surround EVERY CEGUI codeblock/call with a try/catch statement that catches a CEGUI::Exception. This will save you a lot of time and make your game more robust.

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

Postby CrazyEddie » Tue Dec 16, 2008 10:30

Cool :) I got a bit confused about what you meant; it doesn't take much these days :D

With regards to the GL setup, the renderer module is handling most of the required state changes, including setting up the other matrices - it's just the GL_TEXTURE matrix set up we're missing (and the example above should solve that until we issue a release with a fix).

And yeah, use try/catch blocks - it's the difference between being able to say "it crashed" and "oh, I caught an exception! how can I deal with this". Admittedly, for clarity much of our example code is without try/catch blocks, this has unfortunately encouraged bad habits in others, it seems :?

CE.

reixons
Just popping in
Just popping in
Posts: 12
Joined: Fri Nov 28, 2008 21:40

Postby reixons » Tue Dec 16, 2008 18:57

Yep I finally got it running as I wanted. Now everythins is easier.

Another question, what kinds of object can I choose among?
I know that there are, windows, framewindows, buttons, comboboxes etc... Where can I find a complete list?

Lots of thanks guys your help is being quite important for my work!

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

Postby CrazyEddie » Wed Dec 17, 2008 09:51

reixons wrote:Another question, what kinds of object can I choose among?
I know that there are, windows, framewindows, buttons, comboboxes etc... Where can I find a complete list?

Although it could do with a minor update, Widget Galore on the Wiki lists and describes the widgets and various information about them. I think the only missing widgets from that are the Tree widget that I hate, and the GroupBox :)

reixons wrote:Lots of thanks guys your help is being quite important for my work!

Happy to help where possible :)

CE

Pompei2
Home away from home
Home away from home
Posts: 489
Joined: Tue May 23, 2006 16:31

Postby Pompei2 » Wed Dec 17, 2008 15:32

CrazyEddie wrote:.. and the GroupBox :)


D'oh I didn't even know about that one and created my own -.- Your lib is like a relationship IRL, always full of good surprises ;)

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

Postby CrazyEddie » Thu Dec 18, 2008 09:25

Pompei2 wrote:Your lib is like a relationship IRL, always full of good surprises ;)

:lol: And, inevitably, some nasty surprises too :P

reixons
Just popping in
Just popping in
Posts: 12
Joined: Fri Nov 28, 2008 21:40

Postby reixons » Thu Dec 18, 2008 22:09

Hi again! I am here with my new problem!
This one goes with the events. I am mixing SDL and CEGUI to work with the events...so...
I manage them as it is done in the tutorial and everything works ok but, for example, in a FrameWindow, when I try to move it (click on the top bar and while the left mouse button y pressed I move the mouse) the window maximizes and minimizes repeatedly. Do you know something about this? Maybe you need some code, I post the code where the events are managed and the Cegui manager functions are called. The called functions are implemented as the tutorials explain.

Code: Select all

while (SDL_PollEvent( &event ))
      {
         switch(event.type)
         {
            case SDL_ACTIVEEVENT:
            {
               if (event.active.gain == 0)
                  pintar = true;
               else
                  pintar = true;
               break;
            }
            case SDL_KEYDOWN:
            {
               // CEGUI maneja el evento
               gc.manejarKeyDown(event.key.keysym);
               eventoTeclado(event);
               pintar = true;
               break;
            }
            case SDL_KEYUP:
            {
               // CEGUI  maneja el evento
               gc.manejarKeyUp(event.key.keysym);
               eventoTeclado(event);
               pintar = true;
               break;
            }
            case SDL_MOUSEMOTION:
            {
               // CEGUI maneja las coordenadas del ratón
               gc.manejarMouseMotion (static_cast<float>(event.motion.x), static_cast<float>(event.motion.y));
            }
            case SDL_MOUSEBUTTONDOWN:
            {
               // CEGUI maneja el evento
               gc.manejarMouseDown (event.button.button);
               
               eventoRaton(event);
               break;
            }
            case SDL_MOUSEBUTTONUP:
            {
               // CEGUI maneja el evento
               gc.manejarMouseUp (event.button.button);
               
               eventoRaton(event);
               break;
            }
            case SDL_VIDEORESIZE:
            {
               // CEGUI maneja el evento
               gc.manejarVideoResize (event.resize.w, event.resize.h);
               
               pintar = true;
               surface = SDL_SetVideoMode( event.resize.w,event.resize.h,this->bpp, this->videoFlags );
               // Comprobamos si se ha creado el surface
               if(surface == NULL)
               {
                  // Se ha producido un error
                  cerr << "ERROR: Problema al obtener el surface: " <<  SDL_GetError( ) << endl;
                  SDL_Quit( );      
               }
               redimensionarVentana(event.resize.w,event.resize.h);
               break;
            }
            case SDL_QUIT:
            {
               salir = true;
               break;
            }
         }
      }


Thanks!

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

Postby CrazyEddie » Fri Dec 19, 2008 09:41

the window maximizes and minimizes repeatedly. Do you know something about this?

It sounds like multiple mouse button down events are getting sent. What I think is happening is that a new 'down' event is being sent each iteration through the event loop whilst the button is held down, as opposed to just one when you actually push the button down.

I'm not certain why this might be happening; I have zero working knowledge of SDL, so I'm not sure if the code is right or not :o

CE.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 8 guests