[SOLVED] Integrating 0.8.3 with SFML 2.1 and OpenGL

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

slack41
Just popping in
Just popping in
Posts: 9
Joined: Thu Jan 02, 2014 17:04

[SOLVED] Integrating 0.8.3 with SFML 2.1 and OpenGL

Postby slack41 » Thu Jan 02, 2014 17:13

I am following this outdated SFML + CEGUI tutorial, using SFML 2.1 and CEGUI 0.8.3 (on Linux, with the GLRenderer).

I've made numerous modifications to the code, and the SFML skeleton is working. However, CEGUI is only working partially: The initial view renders correctly, but it doesn't seem to be repainted properly, so the mouse cursor leaves a visible trail. Moreover, once I start adding a native SFML "draw()" of an "sf::Text" piece of string, the CEGUI mouse cursor disappears entirely.

Moreover, the edit box doesn't show any text. However, if I remove the line "mWindow.draw(mString);" in the code below, the edit box does show the text.

Update: If I add "mWindow.clear()" at the beginning of the loop, the trails disappear, but as soon as I try drawing the SFML text, all the CEGUI graphics disappear entirely and the window is just black, and with the SFML string the only thing on it.

I believe that my rendering integration of CEGUI into SFML is broken. Could you perhaps advise on what the basic rendering logic should look like, or perhaps spot the error in my design?

Code: Select all

    while (mWindow.isOpen())
    {
      if (mDone) { mWindow.close(); return; }

      for (sf::Event event; mWindow.pollEvent(event); )
      {
        if (mGUIManager.handleEvent(event))
        {
          continue;
        }

        switch (event.type)
        {
        case sf::Event::Closed:
          Stop();
          break;
        case sf::Event::KeyPressed:
          if (event.key.code == sf::Keyboard::Escape) { Stop(); }
          break;
        default:
          ;
        }
      }

      // Is this correct?
      // sf::Window mWindow; sf::Text mString;

      mWindow.draw(mString);
      mGUIManager.Draw();
      mWindow.display();
    }


The code for "mGUIManager.Draw()" is:

Code: Select all

  void Draw()
  {
    CEGUI::System::getSingleton().renderAllGUIContexts();
  }


Many thanks!

slack41
Just popping in
Just popping in
Posts: 9
Joined: Thu Jan 02, 2014 17:04

Re: Integrating 0.8.3 with SFML 2.1 and OpenGL

Postby slack41 » Thu Jan 02, 2014 21:04

I've resolved this! The crucial information is in this SFML OpenGL documentation.

Basically, I've replaced SFML's Window::clear() with a GL-clear, and the important change is to save the GL state while doing SFML drawing. My render loop now looks like this:

Code: Select all

      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

      mWindow.pushGLStates();
      mWindow.draw(mString);    // this is a native SFML drawing operation
      mWindow.popGLStates();

      mGUIManager.Draw();       // this is CEGUI

      mWindow.display();

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: [SOLVED] Integrating 0.8.3 with SFML 2.1 and OpenGL

Postby Ident » Fri Jan 03, 2014 14:55

Thanks for resolving the issue yourself. Please feel free to update the outdated wiki article with your forum account so that thenext person will have an easier time finding a solution.
CrazyEddie: "I don't like GUIs"


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 9 guests