Hi guys!
I'm using SFML v2.3, Mingw32 v4.9.2 and Windows 10.
I'm trying to render in a thread, and runtime errors keep coming no matter what I do (Failed to activate the window's context). Here's the code I'm using.
#include <future>
#include <SFML/Graphics.hpp>
int main()
{
// create the window
sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
window.setVerticalSyncEnabled(true);
// run the program as long as the window is open
while (window.isOpen()) {
// handle events
{
sf::Event event;
while (window.pollEvent(event)) {
// "close requested" event: we close the window
if (event.type == sf::Event::Closed) {
window.close();
}
}
}
// clear the window with black color
window.clear(sf::Color::Black);
window.setActive(false);
std::async(std::launch::async, [&]() {
window.draw(sf::CircleShape(20));
}).wait();
// end the current frame
window.display();
}
return 0;
}
Am I missing something? Thanks.