SFML community forums

Help => General => Topic started by: Putarda on August 02, 2016, 07:43:54 pm

Title: Is it possible to run the RenderWindow in the background?
Post by: Putarda on August 02, 2016, 07:43:54 pm
Hello :), is it possible to run the RenderWindow thread in the background? If so, can anyone give me a simple code.

#include <SFML\Graphics.hpp>

sf::RenderWindow window;

void openWindow() {

        window.create(sf::VideoMode(800, 800), "Window");

        while (window.isOpen()) {

                sf::Event event;

                while (window.pollEvent(event)) {

                        switch (event.type) {

                        case sf::Event::Closed:

                                window.close();

                                break;
                        }

                }

        }

}
 

Thanks ;D.
Title: Re: Is it possible to run the RenderWindow in the background?
Post by: Jesper Juhl on August 02, 2016, 08:18:57 pm
What are you actually trying to achieve?
Title: Re: Is it possible to run the RenderWindow in the background?
Post by: Putarda on August 02, 2016, 08:21:01 pm
Something like this:

#include "Game.h"
#include <thread>

int main() {

        std::thread t([] {createGame();});

}
 
Title: Re: Is it possible to run the RenderWindow in the background?
Post by: Jesper Juhl on August 02, 2016, 10:13:18 pm
That didn't actually help.

Could you describe the problem you are having and trying to solve.?
Title: Re: Is it possible to run the RenderWindow in the background?
Post by: Yohdu on August 03, 2016, 12:37:15 pm
If you're not on MacOS, yes you can. However, events need to be polled in the same thread (so you're code seems correct)  : http://www.sfml-dev.org/tutorials/2.3/window-window.php
Title: Re: Is it possible to run the RenderWindow in the background?
Post by: Hapax on August 03, 2016, 08:48:52 pm
Although it is possible except - as Yohdu already said - on Mac, it is very likely there are better design choices.

At the bottom of the tutorial article to which Yohdu linked (http://www.sfml-dev.org/tutorials/2.3/window-window.php#things-to-know-about-windows) is some information that explains that it's mostly possible but not advisable.
Quote
If you really want to split things between threads, it is more convenient to keep event handling in the main thread and move the rest (rendering, physics, logic, ...) to a separate thread instead.
Title: Re: Is it possible to run the RenderWindow in the background?
Post by: Putarda on August 04, 2016, 01:25:07 pm
I get this error when i start it.
http://i.imgur.com/JaYooUB.png