PDA

View Full Version : Unsupported Binding in PyOpenGL (Python)



Gangerolf
05-10-2010, 09:22 AM
In python's Open GL wrapper, there are several bindings missing. E.g. if we would like to implement a geometry shader, the glProgramParameteri is missing (defined as a zero function pointer).

Here (http://sites.google.com/site/dlampetest/python/geometry-shaders-from-python) is a small piece of code that defines glProgramParameteri, but this could easily be modified to define any missing opengl call.


#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:
raise Exception( "wglGetProcAddress('glProgramParameteriEXT') returned a zero adress, which will result in a nullpointer error if used.")
_glProgramParameteri = prototype( fptr )
_glProgramParameteri( program, pname, value )


Good luck :)