window.setActive(false); needs to go in the thread you do not want to do OpenGL stuff, and
window.setActive(); needs to go in the thread you want to do OpenGL stuff.
Here's a contrived modification of your original code that solves the event handling issues you'll see (ie: frozen window, can't move/resize, etc) if you don't handle events on the main thread.
#include <atomic>
#include <thread>
#include <SFML/Graphics.hpp>
std::atomic_bool run = true;
void render(sf::RenderWindow &window, sf::CircleShape &shape)
{
window.setActive();
while (run)
{
window.clear();
window.draw(shape);
window.display();
}
}
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
window.setActive(false);
std::thread t1(render, std::ref(window), std::ref(shape));
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
run = false;
window.close();
}
}
}
if (t1.joinable())
t1.join();
return 0;
}