[Solved] OpenGL/SFML Rendering Woes
Posted: 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.
when I comment out
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.
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:
Full draw(dt) function with all my SFML rendering action:
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.
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.