I'm having an issue using multiple windows with SFML. At the moment all of my graphics in the program are rendered with modern OpenGL, but I want to create a separate window that I use as sort of a console for my main window. Because of this my main window is a sf::Window
and my addition window I create is a sf::RenderWindow
The problem however is that when I attempt to display both windows, my main window no longer clears the background color to blue, and my renderwindow also does not draw a simple circle. I attempted messing around with setActive()
but nothing seems to be working. Here's what I'm talking about:
What the program normally looks like
(http://i.imgur.com/b2OmeXe.png)
black background when console window drawn, circle also does not render to console window
(http://i.imgur.com/DnZpN1Q.png)
What I'm doing:
console window declaration: (Exact same context settings, but this is a renderwindow as opposed to window
ConsoleWindow.create(sf::VideoMode(400,200),
"Console",
sf::Style::Default,
sf::ContextSettings(32, 8, 0, 3, 3)
);
console window render
ParentWindow->setActive(false);
ConsoleWindow.draw(circle);
ConsoleWindow.display();
ParentWindow->setActive(true);
Just before the main loop starts, I call window.setActive(true)
During the main loop(very simplified form):
//handle events
//...
//call GL clear color to dark blue
//compute matricies
//enable vertex attrib arrays
//draw arrays instanced
//disable vertex attrib arrays
window.display(); //window to draw OpenGL to
console_window.render(); //calls console render code as seen above
Any ideas as to how I can get these two windows to render in harmony?
So update to my problem, I managed to fix the issue; however I am not too sure if this is an actual solution or a dirty workaround.
I moved the creation of the console window to before I set the initial viewport, and moved the render call to before the actual openGL draw. This works fine:
sf::Window window;
window.create(sf::VideoMode(1000,750), //declare window
"Particle Simulation", //window title
sf::Style::Default,
sf::ContextSettings(32, 8, 0, 3, 3)
); //default context settings, my custom ones were screwing with the program so I let SFML decide
ConsoleManager console_window(&window);
glViewport(0,0,window.getSize().x,window.getSize().y);
then calling each:
console_window.render();
window.display();
my console render function did not change at all, since the main window I draw to is a sf::window I don't have any options to save and push GL states, could this be why it seems the render window is not interfering with the normal window?
I was wondering if this was a valid solution to my issue if anyone is reading....