I am using OpenGL for a specific purpose. I run opengl in one thread which opens a window and keeps running all the time. There are other threads which are spawned upon some external event. These threads also require to use the already created window for some rendering purpose.
So in order to set the windowing environment to the window which is already created in other thread, I used glutSetWindow. But this generates an error given below

X Error of failed request: BadAccess (attempt to access private resource denied)
Major opcode of failed request: 129 (GLX)
Minor opcode of failed request: 5 (X_GLXMakeCurrent)
Serial number of failed request: 44
Current serial number in output stream: 44
Which means that window created in one thread cant be used by others.

So is there any way in which I can render into the window already created from the newly created threads. Though openGL is not meant to be run in threads, it would be really helpful if I can get any assistance in this regard. Thank you very much for ur time.


Always render in one thread (I call it render thread).
If want to draw from an other thread something then you should ask the render thread to do it.
I know two solutions (I use both):

  1. Send messages to the render thread (to what to draw).
  2. Send a message to the render thread to what function to call (and the function do what you want).

Of course you have to make your message protocols, must be thread safe etc…


Not 100% sure, but it sounds like the problem is that you are attempting to make the context current in two threads simultaneously. This is not allowed. What you are attempting to do is a bit tricky with plain glut. The other poster’s solution is a pretty good one. If that won’t work for you, then you need to look at either multiple contexts, or correctly sharing one.