This is an example from: http://pyopengl.sourceforge.net/context/tutorials/shader_1.xhtml
It is creating a vbo, binging it, and running it with a shader, but somewhere along the way, it is not working properly. I searched a lot on the internet and didn't find any precise answers for my problem (the best pick I had was on this topic on StackOverflow : Why is this tutorial example of a shader not displaying any geometry as it is supposed to? but even if the author was working on the same tutorial, he didn't have the same problem and solved it by himself...)
from OpenGLContext import testingcontext
BaseContext = testingcontext.getInteractive()
from OpenGL.GL import *
from OpenGL.arrays import vbo
from OpenGLContext.arrays import *
from OpenGL.GL import shaders
class TestContext( BaseContext ):
def OnInit( self ):
VERTEX_SHADER = shaders.compileShader("""#version 330
void main() {
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}""", GL_VERTEX_SHADER)
FRAGMENT_SHADER = shaders.compileShader("""#version 330
void main() {
gl_FragColor = vec4( 0, 3, 6, 1 );
}""", GL_FRAGMENT_SHADER)
self.shader = shaders.compileProgram(VERTEX_SHADER,FRAGMENT_SHADER)
self.vbo = vbo.VBO(
array( [
[ 0, 1, 0 ],
[ -1,-1, 0 ],
[ 1,-1, 0 ],
[ 2,-1, 0 ],
[ 4,-1, 0 ],
[ 4, 1, 0 ],
[ 2,-1, 0 ],
[ 4, 1, 0 ],
[ 2, 1, 0 ],
],'f')
)
def Render( self, mode):
shaders.glUseProgram(self.shader)
try:
self.vbo.bind()
try:
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointerf(self.vbo)
glDrawArrays(GL_TRIANGLES, 0, 9)
finally:
self.vbo.unbind()
glDisableClientState(GL_VERTEX_ARRAY);
finally:
shaders.glUseProgram(0)
if __name__ == "__main__":
TestContext.ContextMainLoop()
Running this program from the windows command-line give me that error:
Traceback(most recent call last):
File "openGL-test.py', line 70, in <module>
TestContext.ContextMainLoop()
File "C:\Python27\lib\site-package\openglcontext-2.2.0a2-py2.7.egg\OpenGLContext\glutcontext.py", line 159, in ContextMainLoop
render = cls( *args, **named)
File "C:\Python27\lib\site-package\openglcontext-2.2.0a2-py2.7.egg\OpenGLContext\glutcontext.py", line 35, in __init__
glutInitDisplayMode( self.DISPLAYMODE )
File "C:\Python27\lib\site-package\OpenGL\platform\baseplatform.py", line 384, in __call__
self.__name__, self.__name__,
OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInitDisplayMode, check for bool(glutInitDisplayMode) before calling
Any idea of what that means ? I have to precise, I began to learn Python two months ago, so I'm pretty newbie, even if I had to work it a lot for my internship period. (ho, and that's my first question on StackOverflow :)