home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / lib / site-packages / OpenGL / platform / glx.py < prev    next >
Encoding:
Python Source  |  2008-12-07  |  2.3 KB  |  73 lines

  1. """GLX (x-windows)-specific platform features"""
  2. import ctypes, ctypes.util
  3. from OpenGL.platform import baseplatform, ctypesloader
  4.  
  5. assert hasattr( ctypes, 'RTLD_GLOBAL' ), """Old ctypes without ability to load .so for global resolution: Get ctypes CVS branch_1_0, not CVS HEAD or released versions!"""
  6.  
  7.  
  8. class GLXPlatform( baseplatform.BasePlatform ):
  9.     """Posix (Linux, FreeBSD, etceteras) implementation for PyOpenGL"""
  10.     # On Linux (and, I assume, most GLX platforms, we have to load 
  11.     # GL and GLU with the "global" flag to allow GLUT to resolve its
  12.     # references to GL/GLU functions).
  13.     GL = OpenGL = ctypesloader.loadLibrary(
  14.         ctypes.cdll,
  15.         'GL', 
  16.         mode=ctypes.RTLD_GLOBAL 
  17.     )
  18.     GLU = ctypesloader.loadLibrary(
  19.         ctypes.cdll,
  20.         'GLU',
  21.         mode=ctypes.RTLD_GLOBAL 
  22.     )
  23.     # glut shouldn't need to be global, but just in case a dependent library makes
  24.     # the same assumption GLUT does...
  25.     try:
  26.         GLUT = ctypesloader.loadLibrary(
  27.             ctypes.cdll,
  28.             'glut', 
  29.             mode=ctypes.RTLD_GLOBAL 
  30.         )
  31.     except OSError, err:
  32.         GLUT = None
  33.     # GLX doesn't seem to have its own loadable module?
  34.     GLX = GL
  35.     glXGetProcAddressARB = GL.glXGetProcAddressARB
  36.     glXGetProcAddressARB.restype = ctypes.c_void_p
  37.     getExtensionProcedure = staticmethod( glXGetProcAddressARB )
  38.     try:
  39.         GLE = ctypesloader.loadLibrary(
  40.             ctypes.cdll,
  41.             'gle', 
  42.             mode=ctypes.RTLD_GLOBAL 
  43.         )
  44.     except OSError, err:
  45.         GLE = None
  46.  
  47.     DEFAULT_FUNCTION_TYPE = staticmethod( ctypes.CFUNCTYPE )
  48.  
  49.     # This loads the GLX functions from the GL .so, not sure if that's
  50.     # really kosher...
  51.     GetCurrentContext = CurrentContextIsValid = staticmethod(
  52.         GL.glXGetCurrentContext
  53.     )
  54.  
  55.  
  56.     def getGLUTFontPointer( self, constant ):
  57.         """Platform specific function to retrieve a GLUT font pointer
  58.         
  59.         GLUTAPI void *glutBitmap9By15;
  60.         #define GLUT_BITMAP_9_BY_15        (&glutBitmap9By15)
  61.         
  62.         Key here is that we want the addressof the pointer in the DLL,
  63.         not the pointer in the DLL.  That is, our pointer is to the 
  64.         pointer defined in the DLL, we don't want the *value* stored in
  65.         that pointer.
  66.         """
  67.         name = [ x.title() for x in constant.split( '_' )[1:] ]
  68.         internal = 'glut' + "".join( [x.title() for x in name] )
  69.         pointer = ctypes.c_void_p.in_dll( self.GLUT, internal )
  70.         return ctypes.c_void_p(ctypes.addressof(pointer))
  71.     
  72.     safeGetError = staticmethod( OpenGL.glGetError )
  73.