Hello,
I’m trying to create multiple opengl rendering contexts on different windows.
I tried it with using multiple HDC’s and HGRLC’s and in a single thread.
That didn’t worked because opengl uses all its stuff globally?
Then i tried adding multi threading.
The threads run fine but only in 1 window a triangles is been drawn.
Here is the code for a single thread.
The other thread is the same except it draws a different colored triangle:
DWORD WINAPI DrawOne(LPVOID n)
{
while(true)
{
MSG msg;
BOOL MsgReturn = GetMessage(&msg, NULL, DRAWSCENE, QUITSCENE);
if (MsgReturn)
{
switch(msg.message)
{
case DRAWSCENE:
{
wglMakeCurrent(GlWindow1.hdc, GlWindow1.hrc);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -5.0f);
glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_TRIANGLES);
glVertex2f(0.0f, 0.0f);
glVertex2f(1.0f, 0.0f);
glVertex2f(1.0f, 1.0f);
glEnd();
SwapBuffers(GlWindow1.hdc);
}
break;
case QUITSCENE:
return 0;
break;
}
}
}
}
And here is the main message loop which calls the threads to draw:
while(!done)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message == WM_QUIT)
{
done = true;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
{
wglMakeCurrent(GlWindow1.hdc, GlWindow1.hrc);
PostThreadMessage(thread_ids[1], DRAWSCENE , 0 , 0 );
wglMakeCurrent(GlWindow.hdc, GlWindow.hrc);
PostThreadMessage(thread_ids[0], DRAWSCENE , 0 , 0 );
}
}
I create the opengl windows using the code from nehe.gamedev lesson 1 but i only get 1 triangle drawn.