From 88170928b5fb02c00a7120fd7490464c571640eb Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Fri, 25 Feb 2011 15:19:34 -0500 Subject: [PATCH] Update GL interop example. --- doc/source/misc.rst | 4 ++-- examples/gl_interop_demo.py | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/doc/source/misc.rst b/doc/source/misc.rst index f94b7162..c96af3d1 100644 --- a/doc/source/misc.rst +++ b/doc/source/misc.rst @@ -15,8 +15,8 @@ Acknowledgments * Achim Gottinger submitted a fix for an example. * Andrew Karpushin provided a fix for a whole class of crash bugs in PyOpenCL. -* Paolo Simone Gasparello provided much help in getting OpenCL-OpenGL - interoperability to work. +* Paolo Simone Gasparello, Keith Brafford, and Ian Johnson provided much help + in getting OpenCL-OpenGL interoperability to work. Guidelines ========== diff --git a/examples/gl_interop_demo.py b/examples/gl_interop_demo.py index 964682bb..99524cb3 100644 --- a/examples/gl_interop_demo.py +++ b/examples/gl_interop_demo.py @@ -21,17 +21,25 @@ __kernel void generate_sin(__global float2* a) """ def initialize(): - plats = cl.get_platforms() + platform = cl.get_platforms()[0] from pyopencl.tools import get_gl_sharing_context_properties import sys if sys.platform == "darwin": ctx = cl.Context(properties=get_gl_sharing_context_properties(), - devices=[]) + devices=[]) else: - ctx = cl.Context(properties=[ - (cl.context_properties.PLATFORM, plats[0])] - + get_gl_sharing_context_properties()) + # Some OSs prefer clCreateContextFromType, some prefer + # clCreateContext. Try both. + try: + ctx = cl.Context(properties=[ + (cl.context_properties.PLATFORM, platform)] + + get_gl_sharing_context_properties()) + except: + ctx = cl.Context(properties=[ + (cl.context_properties.PLATFORM, platform)] + + get_gl_sharing_context_properties(), + devices = [platform.get_devices()[0]]) glClearColor(1, 1, 1, 1) glColor(0, 0, 1) -- GitLab