Thread: 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
Attachments:
map2gl19-beta.zip
|
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 |
From: Mike C. F. <mcf...@vr...> - 2008-11-09 17:28:28
|
Don Laursen wrote: > I'm having a similar problem with shaders in Windows. > ... > 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 > This is why PyOpenGL is considering the functions unavailable. If you have access to GL_ARB_* then it should show up in that list. It's possible, I suppose, that you've got two different OpenGL implementations and PyOpenGL is picking up the software version? Can you print out the GL_VENDOR and GL_VERSION string as well? That should tell us which driver you're using. IIRC under Win32 that should be showing "nVidia something" (or "ATI something") if you've got the accelerated driver loaded, but Microsoft if you've got the default software renderer (without extensions). If that's the problem, then we'll need to look into whether there's some Win32 mechanism to select the vendor driver on-the-fly for this kind of stuff. Not being a Windows user I don't have much familiarity there, but I'll try to work through it with you. > 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? > CVS head is getting a bit long in the tooth, but this seems more like a platform/configuration issue. > I've attached my program. The OpenGL code is in fft/map/viewer.py. Any > help would be appreciated. > I'll try to get some time to test this on my old Win2K box today. Take care, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com |
From: Mike C. F. <mcf...@vr...> - 2008-11-09 18:33:10
|
Don Laursen wrote: > I'm having a similar problem with shaders in Windows. > ... > I've attached my program. The OpenGL code is in fft/map/viewer.py. Any > help would be appreciated. > One thing I note is that it appears you may be doing OpenGL calls potentially before you get a valid OpenGL context. On windows that can often wind up crashing and/or using the non-accelerated driver. On my Gentoo workstation I get an Invalid Operation GL exception when I try to run your code, the most likely cause for that would be an invalid context. You should likely run all of your OpenGL code in a display callback from wxPython. At the very least you should "set current" in order to force a given context to be active. PS, a few fixes in bzr head for the shader object log operations and the like, if you're using them. Good luck, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com |
From: Don L. <go...@gm...> - 2008-11-09 18:44:26
|
Mike, Thanks for replying so quickly! On Sun, Nov 9, 2008 at 12:28 PM, Mike C. Fletcher <mcf...@vr...> wrote: >> GL_WIN_swap_hint >> GL_EXT_bgra >> GL_EXT_paletted_texture > This is why PyOpenGL is considering the functions unavailable. If you have > access to GL_ARB_* then it should show up in that list. It's possible, I > suppose, that you've got two different OpenGL implementations and PyOpenGL > is picking up the software version? Can you print out the GL_VENDOR and > GL_VERSION string as well? That should tell us which driver you're using. Here they are: Microsoft Corporation 1.1.0 I also ran OpenGL Extensions Viewer again and I noticed that I have two renderer choices at the top: "GeForce 8800 GTX/PCI/SSE2" (which was selected when I ran the tests before) and "GDI Generic." For GDI Generic, it shows the same three extensions I listed above, and only the OpenGL 1.1 and 1.2 tests pass. So it looks like you're right about the wrong driver being chosen. On Sun, Nov 9, 2008 at 1:33 PM, Mike C. Fletcher <mcf...@vr...> wrote: > One thing I note is that it appears you may be doing OpenGL calls > potentially before you get a valid OpenGL context. On windows that can > often wind up crashing and/or using the non-accelerated driver. On my > Gentoo workstation I get an Invalid Operation GL exception when I try to run > your code, the most likely cause for that would be an invalid context. > > You should likely run all of your OpenGL code in a display callback from > wxPython. At the very least you should "set current" in order to force a > given context to be active. You are running map2gl.py, right? If it's not setting up a context, then I don't know why, because I thought it did that. :( I'll look at it again. Thanks again! -gomtuu |
From: Don L. <go...@gm...> - 2008-11-09 20:30:26
|
I took a look at the GLCanvas.py demo that comes in the wxPython demo package and moved some things around in my program to be more like that example. It still wouldn't work (though it would get further before printing an error), until I removed the "attribList=[wx.glcanvas.WX_GL_DOUBLEBUFFER" from my GLCanvas constructor call. Once that was gone, it worked just fine. Just having the attribList parameter causes my program to fall back on the Microsoft driver and fail to work. This happens even when I set attribList=[], so it's not the fact that I'm trying to use double-buffering that's causing it. So is this a wxPython issue or a PyOpenGL issue? Thanks, -gomtuu |
From: Mike C. F. <mcf...@vr...> - 2008-11-09 22:46:15
|
Don Laursen wrote: > I took a look at the GLCanvas.py demo that comes in the wxPython demo > package and moved some things around in my program to be more like > that example. It still wouldn't work (though it would get further > before printing an error), until I removed the > "attribList=[wx.glcanvas.WX_GL_DOUBLEBUFFER" from my GLCanvas > constructor call. Once that was gone, it worked just fine. > > Just having the attribList parameter causes my program to fall back on > the Microsoft driver and fail to work. This happens even when I set > attribList=[], so it's not the fact that I'm trying to use > double-buffering that's causing it. > > So is this a wxPython issue or a PyOpenGL issue? > IIRC the GL visual selection is supposed to take the attribute bitmask as a "minimum requirement", but it's possible that without glcanvas.WX_GL_RGBA the algorithm is giving you an un-accelerated implementation, maybe a 256-color display or something silly like that? You could try fully-specifying the attributes, i.e. [ WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 24 ] and see if that selects the proper visual. HTH, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com |
From: Don L. <go...@gm...> - 2008-11-10 00:09:16
|
On Sun, Nov 9, 2008 at 5:46 PM, Mike C. Fletcher <mcf...@vr...> wrote: > IIRC the GL visual selection is supposed to take the attribute bitmask as a > "minimum requirement", but it's possible that without glcanvas.WX_GL_RGBA > the algorithm is giving you an un-accelerated implementation, maybe a > 256-color display or something silly like that? You could try > fully-specifying the attributes, i.e. > > [ WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 24 ] > > and see if that selects the proper visual. That did the trick! Thank you! -gomtuu |