Two OpenGL Windows in an Application

Hi all,

I tried to run two opengl windows (without GLUT) in an application. There is a problem when I quit (kill) the 2nd window and go back to the 1st one (a memory error…).
Do I have to kill the 1st window before running the other or just change the current context ?

Thanks for answering


Can you be a bit more specific, please. Do you use glx, wgl, agl … ?

Originally posted by plastichead:
Can you be a bit more specific, please. Do you use glx, wgl, agl … ?

Excuse me, I use wgl and I code in VB.


OpenGL state variables are OS based and not application based. I guess this means that there can exist only one OpenGL window. This will mean that only one window can display OpenGL images. So if you want to switch between windows, you should properly change the rendering contexts.

I use multiple windows with opengl in VB all the time. The trick is to have

wglMakeCurrent(Me.hdc, m_hRC)

in your form’s Activate and Resize events. “Me” in this case, is the form, if you are writing directly to the form. You might be writing opengl to a picture window. In that case, use the hdc of the picture window.

If the problem is only when you kill the window, you may not be releasing the rendering context properly. In your Form_Unload command you need

wglMakeCurrent(Me.hdc, 0&)

Also, before this call, release any display lists, etc that you may have created. This will keep memory happy.

Hope this helps.


Thanks a lot for your answer.
In fact, I think I had a Pb of screen resolution(I’ve upgraded my Video Card driver !!!).

But the behaviour of my app depends on OS. It works very fine (like I want) on Win2k, but not so good on WinNT 4.

Do you something about wgl and OpenGL under WinNT and Win2k ?

Thanks again