Page 1 of 1

[SOLVED] Integrating 0.8.3 with SFML 2.1 and OpenGL

Posted: Thu Jan 02, 2014 17:13
by slack41
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!

Re: Integrating 0.8.3 with SFML 2.1 and OpenGL

Posted: Thu Jan 02, 2014 21:04
by slack41
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();

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

Posted: Fri Jan 03, 2014 14:55
by Ident
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.