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 / GLU / quadrics.py < prev    next >
Encoding:
Python Source  |  2008-12-07  |  1.7 KB  |  57 lines

  1. """Wrapper/Implementation of the GLU quadrics object for PyOpenGL"""
  2. from OpenGL.raw import GLU as simple
  3. from OpenGL.platform import GLU,createBaseFunction, PLATFORM
  4. import ctypes
  5.  
  6. class GLUQuadric( simple.GLUquadric ):
  7.     """Implementation class for GLUQuadric classes in PyOpenGL"""
  8.     FUNCTION_TYPE = PLATFORM.functionTypeFor(PLATFORM.GLU)
  9.     CALLBACK_TYPES = {
  10.         # mapping from "which" GLU enumeration to a ctypes function type
  11.         simple.GLU_ERROR : FUNCTION_TYPE( None, simple.GLenum )
  12.     }
  13.     def addCallback( self, which, function ):
  14.         """Register a callback for the quadric object
  15.         
  16.         At the moment only GLU_ERROR is supported by OpenGL, but
  17.         we allow for the possibility of more callbacks in the future...
  18.         """
  19.         callbackType = self.CALLBACK_TYPES.get( which )
  20.         if not callbackType:
  21.             raise ValueError(
  22.                 """Don't have a registered callback type for %r"""%(
  23.                     which,
  24.                 )
  25.             )
  26.         if not isinstance( function, callbackType ):
  27.             cCallback = callbackType( function )
  28.         else:
  29.             cCallback = function
  30.         GLU.gluQuadricCallback( self, which, cCallback )
  31.         # XXX catch errors!
  32.         if getattr( self, 'callbacks', None ) is None:
  33.             self.callbacks = {}
  34.         self.callbacks[ which ] = cCallback
  35.         return cCallback
  36. GLUquadric = GLUQuadric
  37.  
  38. def gluQuadricCallback( quadric, which=simple.GLU_ERROR, function=None ):
  39.     """Set the GLU error callback function"""
  40.     return quadric.addCallback( which, function )
  41.  
  42. # Override to produce instances of the sub-class...
  43. gluNewQuadric = createBaseFunction( 
  44.     'gluNewQuadric', dll=GLU, resultType=ctypes.POINTER(GLUQuadric), 
  45.     argTypes=[],
  46.     doc="""gluNewQuadric(  ) -> GLUQuadric
  47.     
  48. Create a new GLUQuadric object""", 
  49.     argNames=[],
  50. )
  51.  
  52. __all__ = (
  53.     'gluNewQuadric',
  54.     'gluQuadricCallback',
  55.     'GLUQuadric',
  56. )
  57.