[Solved] OpenGL/SFML Rendering Woes

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

Ido
Just popping in
Just popping in
Posts: 5
Joined: Wed Jun 21, 2017 08:55

[Solved] OpenGL/SFML Rendering Woes

Postby Ido » Thu Jul 06, 2017 13:04

I'm back guys! I wanted to solve this one on my own but I feel the rabbit hole might be too deep for a noobie surface dweller like me. The problem I now run into seems to be the way I implemented CEGUI rendering causing conflicts with SFML rendering. Basically all my CEGUI layouts show up just fine but SFML will just render blackness.
To be more specific it will render the window.clear() function call in my code below but nothing else.

Code: Select all

   this->game->window.clear(sf::Color::Black);

   this->game->window.setView(this->guiView);
   this->game->window.draw(this->game->background);
   
    this->game->window.setView(this->gameView);
    this->city.map.draw(this->game->window, dt);

   // old built-in gui stuff
   this->game->window.setView(this->guiView);
   for(auto gui : this->guiSystem) this->game->window.draw(gui.second);


when I comment out

Code: Select all

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

everything in SFML renders just fine.
when I only comment out all CEGUI window creation like the code below, my normal SFML will render but with some problems. For instance, the font used on my old built-in gui just becomes a series of black rectangles. My textures also run into some problems but that will take a bit to explain and the details probably aren't relevant.

Code: Select all

CEGUI::Window* mainMenuRoot = CEGUI::WindowManager::getSingleton().loadLayoutFromFile("MainMenu.layout");
   CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(mainMenuRoot);


One interesting detail is that for a split second as soon as my program switches to a new state and new root window I can see what SFML should render before it goes black.

Another important detail I should probably point out is that the documentation(https://www.sfml-dev.org/documentation/2.0/classsf_1_1RenderTarget.php) for the SFML sf::RenderTarget::setView and sf::RenderTarget::draw mention that to use functions that prevent conflicts when combining SFML and regular opengl calls by using popGLStates() and pushGLStates() around my SFML draw calls. I tried this as well as resetGLStates() but to no avail.

Anyway here is all the code that should be relevant. The debug console doesn't throw anything and the CEGUI log looks clean but I can include that if you think it could still be useful.

Main Loop:

Code: Select all

void Game::gameLoop()
{
    sf::Clock clock;
   CEGUI::GUIContext& context = CEGUI::System::getSingleton().getDefaultGUIContext();

    while(this->window.isOpen())
    {
        sf::Time elapsed = clock.restart(); // returns the time elapse between frame updates
        float dt = elapsed.asSeconds() * speed;
      context.injectTimePulse(dt);

        if(peekState() == nullptr) continue;
        peekState()->handleInput();
        peekState()->update(dt);
        this->window.clear(sf::Color::Black);
   peekState()->draw(dt);

   // Draw CEGUI
   Gui_Manager.drawGUI();

        this->window.display();
    }
}


Full draw(dt) function with all my SFML rendering action:

Code: Select all

void GameStateEditor::draw(const float dt)
{
   //this->game->window.pushGLStates();
   
   //this->game->window.resetGLStates();
   
   this->game->window.clear(sf::Color::Black);

   this->game->window.setView(this->guiView);
   this->game->window.draw(this->game->background);
   
    this->game->window.setView(this->gameView);
    this->city.map.draw(this->game->window, dt);

   // old built-in gui stuff
   this->game->window.setView(this->guiView);
   for(auto gui : this->guiSystem) this->game->window.draw(gui.second);
   //this->game->window.popGLStates();

   return;
}


I appreciate any suggestions or help you can give me. Please let me know if it looks like I need to include any other portions of code or files.

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

Re: OpenGL/SFML Rendering Woes

Postby Ident » Thu Jul 06, 2017 18:44

CrazyEddie: "I don't like GUIs"

Ido
Just popping in
Just popping in
Posts: 5
Joined: Wed Jun 21, 2017 08:55

Re: OpenGL/SFML Rendering Woes

Postby Ido » Thu Jul 06, 2017 20:58

By Jove, :shock: that will teach me not to take a cursory glance at OpenGLRendererBase and OpenGL3Renderer again! I was mistakenly running on the assumption that the solution lay deeper down on the SFML side of things for some reason. Anyway, Ident you have my eternal thanks yet again. I'll make sure to look more carefully at the underlying classes next time :wink:

P.S. I just wanna say that from the perspective of someone that is largely removed from the whole dev scene, the more I interact with CEGUI the more I'm amazed at the dedication of 10+ years of work building the multitude of tools like CEED and Falagard (and the enableExtraStateSettings function :mrgreen: ) and helping noobs like me use them. The fact that it's all done by a handful of dedicated volunteers is crazy. Cheers


Return to “Help”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest