foxygit / doom Log in
commit 13704286f092e6c889bf7362ea0252f7d1544342
Author:     Jonathan Dowland <jon+github@alcopop.org>
AuthorDate: Thu Jul 14 17:16:40 2016 +0100
Commit:     Jonathan Dowland <jon+github@alcopop.org>
CommitDate: Thu Jul 14 17:09:22 2016 +0100

    use SDL_GL_GetProcAddress to avoid GL dependency

    Using SDL_GL_GetProcAddress we can get a function pointer to the
    GL routine we want at runtime, if it's available, and avoid a
    static dependency on GL libraries.

    Thanks to fraggle for the suggestion and Mike for fixing Linux
    builds (alas PKG_CHECK_MODULES for GL broke OS X builds)
---
 configure.ac  |  8 --------
 src/i_video.c | 13 ++++++++++---
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/configure.ac b/configure.ac
index 75a2d6d4..eb16c6de 100644
--- a/configure.ac
+++ b/configure.ac
@@ -38,14 +38,6 @@ PKG_CHECK_MODULES(SDL, [sdl2 >= 2.0.1])
 PKG_CHECK_MODULES(SDLMIXER, [SDL2_mixer >= 2.0.0])
 PKG_CHECK_MODULES(SDLNET, [SDL2_net >= 2.0.0])
 PKG_CHECK_MODULES(SDLIMAGE, [SDL2_image >= 2.0.0])
-PKG_CHECK_MODULES(GL, [gl >= 10.0.0])
-
-# Additional LDFLAGS for OS X are required for OpenGL
-case "$host" in
-  *-darwin*)
-    LDFLAGS="$LDFLAGS -framework OpenGL"
-    ;;
-esac

 # Check for libsamplerate.
 AC_ARG_WITH([libsamplerate],
diff --git a/src/i_video.c b/src/i_video.c
index 1a7fcfbe..b14bf432 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -1157,11 +1157,18 @@ static const char *hw_emu_warning =

 static void CheckGLVersion(void)
 {
-    const GLubyte* version = glGetString(GL_VERSION);
+    const char * version;
+    typedef const GLubyte* (APIENTRY * glStringFn_t)(GLenum);
+    glStringFn_t glfp = (glStringFn_t)SDL_GL_GetProcAddress("glGetString");

-    if (version && strstr((const char *)version, "Mesa"))
+    if (glfp)
     {
-        printf("%s", hw_emu_warning);
+        version = (const char *)glfp(GL_VERSION);
+
+        if (version && strstr(version, "Mesa"))
+        {
+            printf("%s", hw_emu_warning);
+        }
     }
 }