Windows deactivates OpenGL context?

I’ve been trying to get OpenGL to work under Windows 7 and have run into a curious issue. I am finding that the OpenGLSurface.ContextHandle becomes inactive under certain situations. Specifically, if I stick all my OpenGL calls within the OpenGLSurface.Render method everything seems fine, but calling OpenGL outside of this results in mixed results.

For example, an OpenGL call placed within a Window.Method (a Window containing an OpenGLSurface I might add) will fail – testing with wglGetCurrentContext shows that no OpenGL context is active at that time (i.e.: it returns 0, which means NULL). A similar thing happens within Modules and custom Classes – if I don’t route it somehow through the OpenGLSurface, I am not guaranteed the OpenGL context is active.

I’ve tried using wglMakeCurrent(window1.Handle, OpenGLSurface1.ContextHandle), but even that fails (and only seems to work when called within OpenGLSurface1, funnily enough).

Under OS X, I’ve found that the OpenGL context remains active at all times, so I’m not sure if I’m doing something wrong. Any ideas?

OpenGLSurface has a MakeCurrent function which might do what you need.

I think this became more important in a recent Xojo version where they changed the threading model in Win32 builds - I had the same issue in my ‘roll your own’ OpenGL code, where I had to set the GL context explicitly.

Thanks Joe, of course the answer was always right in front of my face: must read LR more carefully!

And thanks for pointing that out Michael, I should have noticed the Windows threading change earlier as I had things working up until Xojo.