OpenGL and Win32 created opengl contexts?

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. */

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.


I have a quick fix, in every single GLUT callback function (like the redraw callback, reshape callback, etc.), I have to call these two functions first…

glutSetWindow ( myWinID );

Kind of ugly. Does anyone know if there a performance hit to calling wglMakeCurrent() too often?

Is that on the old original glut, or the maintained equivalent freeglut ?

It’s not a good idea to run multiple OpenGL windows at a time if you expecting more than one to render multiple times each second. OpenGL requires you to change contexts so it knows which window it should render to, and yes there is a performance hit causing you to never hit your 60fps. You can help speed things up by having the secondary window(s) render only when you really have to.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.