PyOpenGL - A tutorial about shaders that doesn't work
Question: 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?](http://stackoverflow.com/questions/16945500/why-is-this-tutorial-example-
of-a-shader-not-displaying-any-geometry-as-it-is-su) 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 :)


Answer: It is failing because you don't have GLUT installed.

GLUT is the GL Utility Toolkit, a very widely used simple framework for
creating OpenGL programs that runs on MS Windows, Macs, Linux, SGI, ... All
the functions and constants have a glut or GLUT_ prefix, and
glutInitDisplayMode is the usually the first function that gets called.

[ REMOVE INSTALLATION NOTES ]

OK, you've done the install and it still doesn't work. That means that while
you have GLUT installed, the Python program can't load the GLUT DLL. Dynamic
linking, oh joy.

Find where glut32.dll got installed.

A quick and dirty solution for a single program is to copy the glut DLL into
the same directory as the program itself.

GLUT is 32 bit (AFAIK, unless you built it yourself) and this can be tricky if
you have a 64 bit version of Windows 7. The advice online is that on 64 bit
Windows a 32 bit DLL should be in C:\Windows\SysWoW64\ and a 64 bit DLL in
C:\Windows\System32\

(Seriously. I have not swapped the two directory names by mistake.)

If that doesn't work, I'm out of ideas.

