I have Win32 windows and GLUT windows running at the same time (migrating away from GLUT). Unfortunately the GLUT window do not always update- I receive the redraw and reshape window callbacks, i even explicitly try to activate the window using glutActivateWindow, but most of the time the OpenGL renderings do not show up.
I tracked the error down to __glutSetWindow in glut_win.c. In fact, in __glutSetWindow, there is a comment for X windows I believe that is the same problem I am having in windows.
/* It is tempting to try to short-circuit the call to
glXMakeCurrent if we “know” we are going to make current
to a window we are already current to. In fact, this
assumption breaks when GLUT is expected to integrated with
other OpenGL windowing APIs that also make current to
OpenGL contexts. Since glXMakeCurrent short-circuits the
“already bound” case, GLUT avoids the temptation to do so
too. */
I_MAKE_CURRENT_LAYER(__glutCurrentWindow);
On the windows implementation, however, I_MAKE_CURRENT_LAYER does the check anyways, and will not call wglMakeCurrent():
void I_MAKE_CURRENT_LAYER(GLUTwindow *window)
{
HGLRC currentContext = wglGetCurrentContext();
HDC currentDc = wglGetCurrentDC();
if (currentContext != window->renderCtx
|| currentDc != window->renderDc)
{
wglMakeCurrent(window->renderDc, window->renderCtx);
}
}
If i remove the if check and always call “wglMakeCurrent” the renderings happen as expected. For some reason wgl is returning wglGetCurrentContext() and wglGetCurrentDC() as the current GLUT windows, but rendering does not have any effect. Sounds like the “already bound case” in glXMakeCurrent.
I do not want to modify GLUT since other remote developers are using this code-base, and I don’t want to have to manage changes to GLUT.
Has anyone else run into this? Is this a bug in the WIn32 implementation of GLUT?
Is there a way I can get GLUT to activate the window without having to modify the code?
Thanks for any suggestions.
-Corey