diff --git a/OpenGL/platform/glx.py b/OpenGL/platform/glx.py index 3fd684ac..99c1ca8a 100644 --- a/OpenGL/platform/glx.py +++ b/OpenGL/platform/glx.py @@ -12,9 +12,13 @@ class GLXPlatform(baseplatform.BasePlatform): @baseplatform.lazy_property def GL(self): try: - return ctypesloader.loadLibrary( - ctypes.cdll, "OpenGL", mode=ctypes.RTLD_GLOBAL - ) + for name in ('OpenGL', 'GL'): + lib = ctypesloader.loadLibrary( + ctypes.cdll, name, mode=ctypes.RTLD_GLOBAL + ) + if lib: + return lib + raise ImportError("Unable to find an OpenGL or GL library") except OSError as err: try: # libGL was the original name, older devices likely still need it... @@ -43,7 +47,12 @@ def GLUT(self): @baseplatform.lazy_property def GLX(self): try: - return ctypesloader.loadLibrary(ctypes.cdll, "GLX", mode=ctypes.RTLD_GLOBAL) + for name in ('GLX', 'OpenGL', 'GL'): + lib = ctypesloader.loadLibrary( + ctypes.cdll, name, mode=ctypes.RTLD_GLOBAL + ) + if lib and getattr(lib, 'glXCreateContext', None): + return lib except OSError as err: return self.GL diff --git a/tests/test_glx_pygame.py b/tests/test_glx_pygame.py deleted file mode 100644 index 2a2e56d1..00000000 --- a/tests/test_glx_pygame.py +++ /dev/null @@ -1,75 +0,0 @@ -from __future__ import print_function -#import OpenGL -#OpenGL.USE_ACCELERATE=False -from OpenGL.GL import * -import pytest -import sys -if not sys.platform.startswith('linux'): - pytest.skip("Skipping GLX tests on non-linux platforms", allow_module_level=True) -from OpenGL.GLX import * -from OpenGL.GLX.EXT.texture_from_pixmap import * -from pygamegltest import pygametest -import os - -attributes = [ -# GLX_BIND_TO_TEXTURE_RGBA_EXT, 1, -# GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT, -# GLX_BIND_TO_TEXTURE_TARGETS_EXT, GLX_TEXTURE_2D_BIT_EXT, - GLX_DOUBLEBUFFER, 1, -# GLX_Y_INVERTED_EXT, GLX_DONT_CARE, - GL_NONE -] - -#from OpenGL import platform -import ctypes -from OpenGL.platform import ctypesloader - -X11 = ctypesloader.loadLibrary( ctypes.cdll, 'X11' ) -XDefaultScreen = X11.XDefaultScreen -XDefaultScreen.argtypes = [ctypes.POINTER(Display)] -XOpenDisplay = X11.XOpenDisplay -XOpenDisplay.restype = ctypes.POINTER(Display) - -@pygametest() -def main(): - dsp = XOpenDisplay( os.environ.get( 'DISPLAY' )) - screen = XDefaultScreen( dsp ) - print('X Display %s Screen %s'%( dsp, screen )) - major,minor = GLint(),GLint() - glXQueryVersion(dsp, major, minor) - version = (major.value,minor.value) - print('glX Version: %s.%s'%version) - if version >= (1,1): - print(glXQueryExtensionsString(dsp,screen)) - if version >= (1,2): - d = glXGetCurrentDisplay()[0] - print('Current display', d) - else: - d = dsp - if version >= (1,3): - elements = GLint(0) - configs = glXChooseFBConfig( - dsp, - screen, - (GLint * len(attributes))( * attributes ), - elements - ) - print('%s configs found'%( elements.value )) - for config in range( elements.value ): - print('Config: %s %s'%(config,configs[config][0])) - samples = ctypes.c_int() - for attribute in ( - 'GLX_FBCONFIG_ID','GLX_BUFFER_SIZE', - 'GLX_LEVEL','GLX_DOUBLEBUFFER', - 'GLX_STEREO', - 'GLX_SAMPLES','GLX_SAMPLE_BUFFERS', - 'GLX_DRAWABLE_TYPE', - ): - glXGetFBConfigAttrib( dsp, configs[config], globals()[attribute], samples ) - print('%s -> %s'%( attribute, samples.value )) - print() - from OpenGL.raw.GLX import _types - print('Extension List', _types.GLXQuerier.getExtensions()) - -if __name__ == "__main__": - main() diff --git a/tests/test_glx_raw_x.py b/tests/test_glx_raw_x.py new file mode 100644 index 00000000..a573609f --- /dev/null +++ b/tests/test_glx_raw_x.py @@ -0,0 +1,93 @@ +from __future__ import print_function + +# import OpenGL +# OpenGL.USE_ACCELERATE=False +from OpenGL.GL import * +import sys + +if not sys.platform.startswith('linux'): + import pytest + + pytest.skip("Skipping GLX tests on non-linux platforms", allow_module_level=True) +from OpenGL.GLX import * +from OpenGL.GLX.EXT.texture_from_pixmap import * + +import os + +attributes = [ + # GLX_BIND_TO_TEXTURE_RGBA_EXT, 1, + # GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT, + # GLX_BIND_TO_TEXTURE_TARGETS_EXT, GLX_TEXTURE_2D_BIT_EXT, + GLX_DOUBLEBUFFER, + 1, + # GLX_Y_INVERTED_EXT, GLX_DONT_CARE, + GL_NONE, +] + +# from OpenGL import platform +import ctypes +from OpenGL.platform import ctypesloader + +X11 = ctypesloader.loadLibrary(ctypes.cdll, 'X11') +XDefaultScreen = X11.XDefaultScreen +XDefaultScreen.argtypes = [ctypes.POINTER(Display)] +XOpenDisplay = X11.XOpenDisplay +XOpenDisplay.restype = ctypes.POINTER(Display) +XDefaultScreenOfDisplay = X11.XDefaultScreenOfDisplay +XDefaultScreenOfDisplay.argtypes = [ctypes.POINTER(Display)] + + +def main(): + dsp = XOpenDisplay(os.environ.get('DISPLAY')) + if not dsp: + print("Could not get the display", os.environ.get('DISPLAY')) + dsp = XOpenDisplay("") + screen = XDefaultScreen(dsp) + else: + screen = XDefaultScreenOfDisplay(dsp) + print('X Display %s Screen %s' % (dsp, screen)) + major, minor = GLint(), GLint() + glXQueryVersion(dsp, major, minor) + version = (major.value, minor.value) + print('glX Version: %s.%s' % version) + if version >= (1, 1): + print(glXQueryExtensionsString(dsp, screen)) + if version >= (1, 2): + d = glXGetCurrentDisplay() + if d: + print('Current display', d) + else: + print('GLX could not find the current display') + else: + d = dsp + if version >= (1, 3): + elements = GLint(0) + configs = glXChooseFBConfig( + dsp, screen, (GLint * len(attributes))(*attributes), elements + ) + print('%s configs found' % (elements.value)) + for config in range(elements.value): + print('Config: %s %s' % (config, configs[config][0])) + samples = ctypes.c_int() + for attribute in ( + 'GLX_FBCONFIG_ID', + 'GLX_BUFFER_SIZE', + 'GLX_LEVEL', + 'GLX_DOUBLEBUFFER', + 'GLX_STEREO', + 'GLX_SAMPLES', + 'GLX_SAMPLE_BUFFERS', + 'GLX_DRAWABLE_TYPE', + ): + glXGetFBConfigAttrib( + dsp, configs[config], globals()[attribute], samples + ) + print('%s -> %s' % (attribute, samples.value)) + print() + from OpenGL.raw.GLX import _types + + print('Extension List', _types.GLXQuerier.getExtensions()) + + +if __name__ == "__main__": + main()