Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Is it possible to run the RenderWindow in the background?  (Read 4730 times)

0 Members and 1 Guest are viewing this topic.

Putarda

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Is it possible to run the RenderWindow in the background?
« 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.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Is it possible to run the RenderWindow in the background?
« Reply #1 on: August 02, 2016, 08:18:57 pm »
What are you actually trying to achieve?

Putarda

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Re: Is it possible to run the RenderWindow in the background?
« Reply #2 on: August 02, 2016, 08:21:01 pm »
Something like this:

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

int main() {

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

}
 

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Is it possible to run the RenderWindow in the background?
« Reply #3 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.?

Yohdu

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
Re: Is it possible to run the RenderWindow in the background?
« Reply #4 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

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Is it possible to run the RenderWindow in the background?
« Reply #5 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 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Putarda

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Re: Is it possible to run the RenderWindow in the background?
« Reply #6 on: August 04, 2016, 01:25:07 pm »
I get this error when i start it.
http://i.imgur.com/JaYooUB.png