From af2178a8da3b0fe33b0a44acb4b89831581b3a30 Mon Sep 17 00:00:00 2001 From: Matthias Goerner <1239022+unhyperbolic@users.noreply.github.com> Date: Wed, 31 Jan 2024 12:19:25 -0800 Subject: [PATCH] Making SimpleImageShaderWidget use glew so that it works on windows. --- opengl/CyOpenGL.pyx | 7 ------- opengl/initGlew.pxi | 21 ++++++++++---------- opengl/modern/simple_image_shader_widget.pyx | 11 ++++++++++ 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/opengl/CyOpenGL.pyx b/opengl/CyOpenGL.pyx index c453642c..5386ecb1 100644 --- a/opengl/CyOpenGL.pyx +++ b/opengl/CyOpenGL.pyx @@ -108,13 +108,6 @@ class RawOpenGLWidget(Tk_.Widget, Tk_.Misc): # initialize self.make_current() - # If we are using GLEW, call glewInit. - # This will set all gl function pointers. - cdef GLenum err - err = callGlewInitIfNecessary() - if err != 0: - raise Exception("Failed to initialize GLEW: %d" % err) - # Check that GLEW set all function pointers that we are calling # below. cdef char * missing_gl_function diff --git a/opengl/initGlew.pxi b/opengl/initGlew.pxi index 64768fad..bdc79363 100644 --- a/opengl/initGlew.pxi +++ b/opengl/initGlew.pxi @@ -5,23 +5,17 @@ cdef extern from *: """ - int callGlewInitIfNecessary() - { - - #ifdef USE_GLEW - return glewInit(); - #else - return 0; - #endif - - } - #define CHECK_GLEW_FOR_FUNCTION(name) if (!name) { return #name; } /* Check that GLEW set the gl function pointers */ char * checkGlewForLegacyOpenGL() { #ifdef USE_GLEW + GLenum err = glewInit(); + if (err != 0) { + return "glewInit failed"; + } + CHECK_GLEW_FOR_FUNCTION(glMatrixMode); CHECK_GLEW_FOR_FUNCTION(glLoadIdentity); CHECK_GLEW_FOR_FUNCTION(glOrtho); @@ -82,6 +76,11 @@ cdef extern from *: char * checkGlewForModernOpenGL() { #ifdef USE_GLEW + GLenum err = glewInit(); + if (err != 0) { + return "glewInit failed"; + } + CHECK_GLEW_FOR_FUNCTION(glCreateShader); CHECK_GLEW_FOR_FUNCTION(glAttachShader); CHECK_GLEW_FOR_FUNCTION(glShaderSource); diff --git a/opengl/modern/simple_image_shader_widget.pyx b/opengl/modern/simple_image_shader_widget.pyx index 79d25bd1..5e7ac23d 100644 --- a/opengl/modern/simple_image_shader_widget.pyx +++ b/opengl/modern/simple_image_shader_widget.pyx @@ -56,6 +56,17 @@ class SimpleImageShaderWidget(GLCanvas): self.textures = [] self.report_time_callback = None + self.make_current() + + cdef char * missing_gl_function + missing_gl_function = checkGlewForModernOpenGL() + if missing_gl_function: + raise Exception( + ("Missing gl function: %s. Your graphics card probably does " + "not support the required OpenGL version (3.2 or later). Your " + "OpenGL version is %s.") % (missing_gl_function, + get_gl_string('GL_VERSION'))) + def set_textures(self, texture_files): self.make_current()