Skip to content

Commit

Permalink
Making SimpleImageShaderWidget use glew so that it works on windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
unhyperbolic committed Jan 31, 2024
1 parent abf1b10 commit af2178a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
7 changes: 0 additions & 7 deletions opengl/CyOpenGL.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 10 additions & 11 deletions opengl/initGlew.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions opengl/modern/simple_image_shader_widget.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit af2178a

Please sign in to comment.