Re: [PyOpenGL-Users] How to use shaders in pyopengl
Brought to you by:
mcfletch
From: Don L. <go...@gm...> - 2008-11-09 17:09:19
|
I'm having a similar problem with shaders in Windows. I have a WxPython/PyOpenGL app that uses shaders and works fine in Ubuntu 8.10, but when I try to run it in Windows XP, I get this error: File "c:\program files\python\lib\site-packages\PyOpenGL-3.0.0b6-py2.5.egg\OpenGL\platform\baseplatform.py", line 280, in __call__ self.__name__, self.__name__, OpenGL.error.NullFunctionError: Attempt to call an undefined function glCreateProgram, check for bool(glCreateProgram) before calling If I understand correctly, this is because OpenGL for Windows is stuck at version 1.1 and needs extensions to use shaders. I'm not exactly clear on how to use extensions, but judging from your OpenGL/tests/tests.py file, all you have to do is import the proper extension. I also found this snippet on your blog and in a tutorial: from OpenGL.GL import * from OpenGL.GL.ARB.shader_objects import * from OpenGL.GL.ARB.fragment_shader import * from OpenGL.GL.ARB.vertex_shader import * from OpenGL.extensions import alternate glCreateShader = alternate( 'glCreateShader', glCreateShader, glCreateShaderObjectARB ) glShaderSource = alternate( 'glShaderSource', glShaderSource, glShaderSourceARB) glCompileShader = alternate( 'glCompileShader', glCompileShader, glCompileShaderARB) glCreateProgram = alternate( 'glCreateProgram', glCreateProgram, glCreateProgramObjectARB) glAttachShader = alternate( 'glAttachShader', glAttachShader,glAttachObjectARB ) glValidateProgram = alternate( 'glValidateProgram',glValidateProgram,glValidateProgramARB ) glLinkProgram = alternate( 'glLinkProgram',glLinkProgram,glLinkProgramARB ) glDeleteShader = alternate( 'glDeleteShader', glDeleteShader,glDeleteObjectARB ) glUseProgram = alternate('glUseProgram',glUseProgram,glUseProgramObjectARB ) But adding this doesn't help. I just get this error instead: File "c:\program files\python\lib\site-packages\PyOpenGL-3.0.0b6-py2.5.egg\OpenGL\extensions.py", line 65, in __call__ self.__name__, OpenGL.error.NullFunctionError: Attempt to call an undefined alterate function (glCreateProgram, glCreateProgramObjectARB), check for bool(glCreateProgram) before calling Do I need to do something first to make the extensions available to use? To see which extensions are available, I added the following line to my program just before the glCreateProgram call: print "\n".join(glGetString(GL_EXTENSIONS).split(' ')) And this is what it says: GL_WIN_swap_hint GL_EXT_bgra GL_EXT_paletted_texture Do I need to use glewpy or something to get access to the shader extensions in Windows? I've confirmed that OpenGL shader extensions work on this computer with OpenGL Extensions Viewer. I've also tried the release version of PyOpenGL 3.0.0b6 as well as the CVS head version (but not the bzr version). I'm stumped... The OpenGL red book states that "OpenGL 1.2 introduces the first ARB-approved extensions." Is that relevant, considering OpenGL is 1.1 in Windows? I've attached my program. The OpenGL code is in fft/map/viewer.py. Any help would be appreciated. Thanks, -gomtuu |