Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML and CEGUI (openGL3 rendering problem)  (Read 938 times)

0 Members and 1 Guest are viewing this topic.

Nical

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
SFML and CEGUI (openGL3 rendering problem)
« on: May 17, 2020, 01:17:44 pm »
I'm trying to setup an SFML project with CEGUI for GUI management.

Here is a reproduction of the bug.
I removed any GUI configuration and event management since they are not part of the issue.

int main(int argc, char* argv[])
{
  sf::RenderWindow window(sf::VideoMode(400, 400), "Foo");
  sf::Font font;
  font.loadFromFile("/home/nico/sandboxes/sfml/DejaVuSansMono.ttf");

  // init CEGUI
  CEGUI::OpenGL3Renderer& guiRenderer = CEGUI::OpenGL3Renderer::bootstrapSystem();

  // stripped: CEGUI resource management
  // stripped: A window is created and set as CEGUI root window

  sf::Clock clock;

  sf::Text text;
  text.setFont(font);
  text.setCharacterSize(24);
  text.setString("hello");
  text.setPosition(50, 50);
  text.setFillColor(sf::Color::Red);

  while (window.isOpen())
  {
    sf::Event event;
    float frameTime = clock.restart().asSeconds();

    guiContext.injectTimePulse(frameTime);
    CEGUI::System::getSingleton().injectTimePulse(frameTime);

    while (window.pollEvent(event))
    {
      // stripped: CEGUI event injection
    }

    window.clear(sf::Color::Black);
    text.move(frameTime * 10, 0);
    window.draw(text);
    // render GUI
    CEGUI::System::getSingleton().renderAllGUIContexts();

    window.display();
  }

  // destroy CEGUI
  CEGUI::OpenGL3Renderer::destroySystem();

  return EXIT_SUCCESS;
}

The GUI is correctly displayed, the text is moving but is not rendered correctly:


If I remove the line triggering the GUI rendering, the text is correctly rendered and is moving.
All is fine, but I obviously I miss the GUI...

If I remove the call to sf::RenderWindow::clear(), the text is also correctly rendered, so is the GUI.
But the text is not moving anymore. The GUI is responding though.

I had a similar issue when using SFGUI, but it was solved by calling window.resetGLStates() after the RenderWindow creation.
I also tried a similar approach, but in the current case it does not change anything.

I don't know what to do at this point. Any help ?

EDIT: I replaced the CEGUI renderer from the OpenGL3 to OpenGL (seems to be version 1.2 of openGL) and the problem was solved. I still don't understand what could be goin on... I can of course stay with this renderer, but I would really like to use the more up to date version of the renderer. Is this issue is SFML related or is it CEGUI that is to blame. I may be that I am the one to blame for not using all this tools correctly...
« Last Edit: May 18, 2020, 11:01:06 am by Nical »