I'm having a bit of a problem loading extensions under Windows and I'm wondering if I'm understanding the semantics of extension modules correctly.

If I run the following snippet (modeled after the sample extension snippet in the PyOpenGL for OpenGL Programmers page)

from OpenGL.GLUT import *
from OpenGL.GL.ARB.shader_objects import *
import sys
# initialize GLUT
argv = glutInit(sys.argv)
# create a window, needs to be done before glInitMultitextureARB
glutCreateWindow('foo')
# see if GL_ARB_multitexture is supported
if not glInitShaderObjectsARB():
# it's not supported...panic!
print "Help, I'm lost without GL_ARB_shader_objects!"
sys.exit(1)
# do something with it...
print glCreateProgramObjectARB
print bool(glCreateProgramObjectARB)


on Python 2.5, I get the following result:

<OpenGL.platform.glCreateProgramObjectARB object at 0x00F77EB0>
False

It seems that PyOpenGL is not finding the function pointers for the extension functions.  Digging through the raw 
and platform directories, it seems that function pointers are found using
wglGetProcAddress, which, according to the MSDN, returns a OpenGL context-dependent pointer.  Specifically:

    When no current rendering context exists or the function fails, the return value is NULL.

Hence, I modified my snippet to the following, by moving the import of the ARB extension module to after I have a context:


from OpenGL.GLUT import *
import sys
# initialize GLUT
argv = glutInit(sys.argv)
# create a window, needs to be done before glInitMultitextureARB
glutCreateWindow('foo')
from OpenGL.GL.ARB.shader_objects import *
# see if GL_ARB_multitexture is supported
if not glInitShaderObjectsARB():
# it's not supported...panic!
print "Help, I'm lost without GL_ARB_shader_objects!"
sys.exit(1)
# do something with it...
print glCreateProgramObjectARB
print bool(glCreateProgramObjectARB)


which results in an output of:

<WinFunctionType object at 0x00F7D288>
True

This time, it seems to have gotten the correct function.  I don't think this problem is going to appear on Linux, since glXGetProcAddressARB is supposed to return
context-independent function pointers and thus wouldn't have a problem
finding these pointers at module import time even when there is no GL
context available.

So, my question is, what is the correct way to do module import of ARB extension modules?  Should they be imported *after* I have gotten an OpenGL context or can they be imported at any time before I want to use the functions?

If the former, that would make using QGLWidget a little bit trickier, as I would have to do a module import in the initializeGL()
function and then retain the module for the other functions, like paintGL()

If the latter, then I think there may be a problem in the auto-generated wrappers
in the raw package, since those wrappers grab the function pointers at
module-load time instead of glInitXXX time.

Thanks for your time.

zaltor