I'm initializing my OpenGL context(SDL/GLEW) in the main thread. But rendering is done in a different thread(things like SDL_GL_SwapWindow or glDrawElements).
The thing is, that nothing happens if I call SDL_GL_SwapWindow. I was trying to simply change the clear color after every swap, but nothing happens.
void render(){
// Rendering...
}
int main(){
// Initialization...
thread rendering(render);
}
Could this be problem?
asked Jan 10, 2014 at 16:06
user2630015
1 Answer 1
Not going to work as you expect. OpenGL Context is thread local. Whichever thread you create the context is where the actual OpenGL rendering calls will have to be made from.
answered Jan 10, 2014 at 16:08
thecoshman
8,6608 gold badges58 silver badges77 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
datenwolf
It's perfectly possible to transition an OpenGL context to another thread. It just can't be active in two threads at the same time.
Andon M. Coleman
@thecoshman: The thread a context is associated with is not immutable. There is a property that a thread can only have one context bound to it at a time and that a context can only be bound in one thread at a time, but you can release the context from one thread and give it to another. The window system APIs all refer to this as the "current" context (e.g.
wglMakeCurrent (...), glXMakeCurrent (...), aglMakeCurrent (...)). To that end, even frameworks that wrap OpenGL like Qt have makeCurrent (...) methods.lang-cpp