1
Graphics / Can't render in a thread
« on: November 06, 2015, 08:10:20 am »
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.
Am I missing something? Thanks.
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;
}
#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.