PDA

View Full Version : Multithreading problem!



HanWu
08-26-2008, 02:18 AM
The glGenList() is not working under multithreading but it works fine without multithreading. Can anyone help me? Thanks.

V-man
08-26-2008, 08:50 AM
You need to make the GL context to your thread before making GL calls. Use wglMakeCurrent on Windows.

HanWu
08-26-2008, 06:41 PM
You need to make the GL context to your thread before making GL calls. Use wglMakeCurrent on Windows.

Hi, if say I initialize the device Context and rendering context in the main thread, later I create a new thread to create fonts which will call glGenList() and after finish the process the thread will end and the fonts that created in the new thread will be used in the main thread. May I know how to make the "GL context to the thread" Is it recreate a new device Context and rendering context in the new thread by the following function ?

IntPtr dc = User.GetDC(windowHandle); // Attempt to get the device context
IntPtr rc = Wgl.wglCreateContext(dc); // Attempt to get the rendering context
wglMakeCurrent(dc, rc);

When I go back to the main thread, do I need to recreate a new device Context and rendering context for the main thread?

Zengar
08-26-2008, 11:36 PM
An OpenGL context is bound to a thread. You cannot call GL commands for a context from a different thread. With other words, keep all GL commands in the same thread. You can also create a new context in a new thread and use wglShareLists to share their list space. This should be described in the wiki.

HanWu
08-27-2008, 09:07 PM
An OpenGL context is bound to a thread. You cannot call GL commands for a context from a different thread. With other words, keep all GL commands in the same thread. You can also create a new context in a new thread and use wglShareLists to share their list space. This should be described in the wiki.

Thanks for the reply ! I will try it later.