Original Post
I'm having trouble getting opengl to work in multiple threads on windows. I followed the sample code from the opengl wiki but Its simply not working for me.
I tried to generate and build a display list on my main thread and within the other thread, both with the same opengl configuration (2 contexts sharing lists). When on the main thread it works perfectly. When on the separate thread, it generates the id but seems to ignore all the commands associated with actually building the list.
I've monitored the processes memory usage during both trials and it is clear that the display list is never generated when called to do so in the other thread.
I've encountered this problem before and gave up on multi-threading opengl, I really want to get it to work this time. Any help is appreciated.
Here is the related code:
I tried to generate and build a display list on my main thread and within the other thread, both with the same opengl configuration (2 contexts sharing lists). When on the main thread it works perfectly. When on the separate thread, it generates the id but seems to ignore all the commands associated with actually building the list.
I've monitored the processes memory usage during both trials and it is clear that the display list is never generated when called to do so in the other thread.
I've encountered this problem before and gave up on multi-threading opengl, I really want to get it to work this time. Any help is appreciated.
Here is the related code:
DWORD WINAPI Windows::thread_callback(void* arg)
{
Windows* window = static_cast<Windows*> (arg);
wglMakeCurrent(window->hdc, window->thd_hrc);
while (!window->done)
window->ThreadLoop();
if (!wglMakeCurrent(0,0))
error("Could not Thread context", "", "Shutdown Error").print();
if (!wglDeleteContext(window->thd_hrc))
error("Could not delete thread context", "", "Shutdown Error").print();
}
// During Window creation...
if (!(hdc=GetDC(hwd)) ||
!(PixelFormat=ChoosePixelFormat(hdc,&pfd)) ||
!(SetPixelFormat(hdc,PixelFormat,&pfd)) ||
!(hrc=wglCreateContext(hdc)) ||
!(thd_hrc=wglCreateContext(hdc)) )
{
destroy_window();
return false;
}
if (!wglShareLists(hrc, thd_hrc))
{
DWORD errorCode=GetLastError();
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, errorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPTSTR) &lpMsgBuf, 0, NULL);
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
LocalFree(lpMsgBuf);
wglDeleteContext(thd_hrc);
destroy_window();
return false;
}
if (!wglMakeCurrent(hdc, hrc))
{
destroy_window();
return false;
}