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