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 / win32.py < prev   
Encoding:
Python Source  |  2008-12-07  |  2.5 KB  |  79 lines

  1. """Windows-specific platform features"""
  2. import ctypes
  3. from OpenGL.platform import ctypesloader, baseplatform
  4.  
  5. class Win32Platform( baseplatform.BasePlatform ):
  6.     """Win32-specific platform implementation"""
  7.  
  8.     GLUT_GUARD_CALLBACKS = True
  9.     GL = OpenGL = ctypesloader.loadLibrary( ctypes.windll, 'opengl32', mode = ctypes.RTLD_GLOBAL )
  10.     GLU = ctypesloader.loadLibrary( ctypes.windll, 'glu32', mode = ctypes.RTLD_GLOBAL )
  11.     try:
  12.         GLUT = ctypesloader.loadLibrary( ctypes.windll, 'glut32', mode = ctypes.RTLD_GLOBAL )
  13.     except WindowsError, err:
  14.         GLUT = None
  15.     GLE = None
  16.     for libName in ('gle32','opengle32'):
  17.         try:
  18.             GLE = ctypesloader.loadLibrary( ctypes.cdll, libName )
  19.             GLE.FunctionType = ctypes.CFUNCTYPE
  20.         except WindowsError, err:
  21.             pass
  22.         else:
  23.             break
  24.     
  25.     DEFAULT_FUNCTION_TYPE = staticmethod( ctypes.WINFUNCTYPE )
  26.     # Win32 GLUT uses different types for callbacks and functions...
  27.     GLUT_CALLBACK_TYPE = staticmethod( ctypes.CFUNCTYPE )
  28.     WGL = ctypes.windll.gdi32
  29.     getExtensionProcedure = staticmethod( OpenGL.wglGetProcAddress )
  30.  
  31.     GLUT_FONT_CONSTANTS = {
  32.         'GLUT_STROKE_ROMAN': ctypes.c_void_p( 0),
  33.         'GLUT_STROKE_MONO_ROMAN': ctypes.c_void_p( 1),
  34.         'GLUT_BITMAP_9_BY_15': ctypes.c_void_p( 2),
  35.         'GLUT_BITMAP_8_BY_13': ctypes.c_void_p( 3),
  36.         'GLUT_BITMAP_TIMES_ROMAN_10': ctypes.c_void_p( 4),
  37.         'GLUT_BITMAP_TIMES_ROMAN_24': ctypes.c_void_p( 5),
  38.         'GLUT_BITMAP_HELVETICA_10': ctypes.c_void_p( 6),
  39.         'GLUT_BITMAP_HELVETICA_12': ctypes.c_void_p( 7),
  40.         'GLUT_BITMAP_HELVETICA_18': ctypes.c_void_p( 8),
  41.     }
  42.  
  43.  
  44.     def getGLUTFontPointer( self,constant ):
  45.         """Platform specific function to retrieve a GLUT font pointer
  46.         
  47.         GLUTAPI void *glutBitmap9By15;
  48.         #define GLUT_BITMAP_9_BY_15        (&glutBitmap9By15)
  49.         
  50.         Key here is that we want the addressof the pointer in the DLL,
  51.         not the pointer in the DLL.  That is, our pointer is to the 
  52.         pointer defined in the DLL, we don't want the *value* stored in
  53.         that pointer.
  54.         """
  55.         return self.GLUT_FONT_CONSTANTS[ constant ]
  56.  
  57.     GetCurrentContext = CurrentContextIsValid = staticmethod(
  58.         GL.wglGetCurrentContext
  59.     )
  60.  
  61.  
  62.     def safeGetError( self ):
  63.         """Provide context-not-present-safe error-checking
  64.         
  65.         Under OS-X an attempt to retrieve error without checking 
  66.         context will bus-error.  Likely Windows will see the same.
  67.         This function checks for a valid context before running 
  68.         glGetError
  69.         
  70.         Note:
  71.             This is a likely candidate for rewriting in C, as it
  72.             is called for every almost function in the system!
  73.         """
  74.         if self.CurrentContextIsValid():
  75.             return glGetError()
  76.         return None
  77.  
  78. glGetError = Win32Platform.OpenGL.glGetError
  79.