5

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

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

2 Comments

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.
@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.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.