My Tech Sandbox

Python‎ > ‎

Geometry Shaders from Python

If you have tried to use geometry shaders using python's PyOpenGL you will have noticed that the show-stopper here is glProgramParameteri. Using this function results in:
OpenGL.error.NullFunctionError: Attempt to call an undefined function glProgramParameteri, check for bool(glProgramParameteri) before calling

Here is an implementation that will define it using ctypes:

01#These three defines exist in OpenGL.GL, but does not correspond to those used here
02GL_GEOMETRY_INPUT_TYPE_EXT   = 0x8DDB
03GL_GEOMETRY_OUTPUT_TYPE_EXT  = 0x8DDC
04GL_GEOMETRY_VERTICES_OUT_EXT = 0x8DDA
05_glProgramParameteri = None
06def glProgramParameteri( program, pname, value  ):
07    global _glProgramParameteri
08    if not _glProgramParameteri:
09        import ctypes
10        # Open the opengl32.dll
11        gldll = ctypes.windll.opengl32
12        # define a function pointer prototype of *(GLuint program, GLenum pname, GLint value)
13        prototype = ctypes.WINFUNCTYPE( ctypes.c_int, ctypes.c_uint, ctypes.c_uint, ctypes.c_int )
14        # Get the win gl func adress
15        fptr = gldll.wglGetProcAddress( 'glProgramParameteriEXT' )
16        if fptr==0:
17            raise Exception( "wglGetProcAddress('glProgramParameteriEXT') returned a zero adress, which will result in a nullpointer error if used.")
18        _glProgramParameteri = prototype( fptr )
19    _glProgramParameteri( program, pname, value )


Comments