PDA

View Full Version : Threads and OpenGL



loopguru
10-30-2002, 12:08 PM
I have a really simple need for threads in my application (WIN32):
Open a window from the main application -> Render a scene in that window.
I'd like to support multiple windows. Unfortunately, I see no simple way of doing this without using a separate thread per window - particularly being that each thread can have at most ONE rendering context. Has anybody out there done this before? I'm really pressed for time so some good, detailed info - or better yet source code - would really help.
Also, I've read "when using multiple threads the modified message pump (using PeekMessage) should be replaced with the usual GetMessage/TranslateMessage combination." Could someone explain this? We're talking about the message pump in the main application ( or associated with the spawned window ), right?
Thanks for the help.
Cheers!
ks

vladk
10-30-2002, 10:02 PM
Rendering contexts are similar to device context. That means that each window with a handle has a DC, that also means that each window can be rendered separately.

Use glMakeCurrent(handle, RC) to set current
rendering context for OpenGL engine. Mind this: there is only one engine. CURRENT RC
defines the output of the engine.

So:

glMakeCurrent (handle, RC1);
// draw in window 1
glMakeCurrent (handle, RC2);
// draw in window 2;
etc...