SFML community forums
Help => Window => Topic started by: mercurio7891 on December 31, 2010, 12:26:00 pm
-
hi if i have multiple sf::Window, can they be on different threads? and if I am to call glBegin() glEnd() from a different thread will it work?
e,g
thread1 : sf::Window A
thread2 : sf::Window B
thread3 : sf::Window C
thread4 : glBegin()/glEnd() other opengl commands
is this allowed?? or mus all sf::Window(s) reside on the same thread along with all opengl commands?
-
hi if i have multiple sf::Window, can they be on different threads?
Yes.
and if I am to call glBegin() glEnd() from a different thread will it work?
It will work, but a window cannot be active on two threads at the same time. So you must call window.SetActive(false) from the initial thread before you can call window.SetActive(true) on the other thread and then call glBegin etc. Be careful, some functions such as Display() automatically activate the window.
-
ahh thanks, then I guess opengl will then draw to which ever window is active then??
If 2 windows on separate threads are active at the same time, would it cause an error? or what would happen? as in would an exception be thrown or would any error flag be set?
-
OpenGL shares nothing between threads, when you activate a context it is active only on the current thread. So you can have multiple contexts active on multiple threads at the same time, there's no problem.
-
Hi Laurent, I don't quite understand what you mean, could you explain it abit further?
Does that mean, that each thread with a different sf::Window have a different rendering context?
say I have a function with draw a cube, basically a glBeing, glEnd pair and some glVertex3f. How would I know which window will it appear on?
-
Does that mean, that each thread with a different sf::Window have a different rendering context?
Absolutely. Calling wglGetCurrentContext() on different threads at the same time will return a different result for each thread.
say I have a function with draw a cube, basically a glBeing, glEnd pair and some glVertex3f. How would I know which window will it appear on?
The one you activated in this thread before calling your OpenGL functions.
-
hi, sorry for reviving this thread. Recently I have gotten around to write a simple app with multiple windows on different along with opengl and I am facing a problem.
Basically here is the simplified equivalent flow
thread A: Create WindowOne, and poll input, WindowOne.Display()
thread B: Create WindowTwo, and poll input, WindowTwo.Display()
thread C (command thread): calls WindowOne.SetActive(true), Draw Cube using Opengl
However nothing is being drawn in the window. Is there something I am missing out?
As from the previous posts, what I "understood" is that setting SetActive(true) would set the window to the primary window.
-
Is there something I am missing out?
WindowOne.SetActive(false). And a mutex to make sure that SetActive and Display are not called concurrently.