Dynamically load glGetString(), to avoid direct dependency on OpenGL.
authorRyan C. Gordon <icculus@icculus.org>
Sat, 01 Mar 2014 21:33:48 -0500
changeset 8278 e60a7bb2b80b
parent 8277 cd0a00060738
child 8279 7e22273aed11
Dynamically load glGetString(), to avoid direct dependency on OpenGL.
src/video/cocoa/SDL_cocoaopengl.m
--- a/src/video/cocoa/SDL_cocoaopengl.m	Sat Mar 01 20:59:43 2014 -0500
+++ b/src/video/cocoa/SDL_cocoaopengl.m	Sat Mar 01 21:33:48 2014 -0500
@@ -162,6 +162,7 @@
 Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
 {
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+    const GLubyte *(APIENTRY * glGetStringFunc)(GLenum) = NULL;
     NSAutoreleasePool *pool;
     SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
@@ -275,7 +276,14 @@
         return NULL;
     }
 
-    glversion = (const char *)glGetString(GL_VERSION);
+    glGetStringFunc = (const GLubyte *(APIENTRY *)(GLenum)) SDL_GL_GetProcAddress("glGetString");
+    if (!glGetStringFunc) {
+        Cocoa_GL_DeleteContext(_this, context);
+        SDL_SetError ("Failed getting OpenGL glGetString entry point");
+        return NULL;
+    }
+
+    glversion = (const char *)glGetStringFunc(GL_VERSION);
     if (glversion == NULL) {
         Cocoa_GL_DeleteContext(_this, context);
         SDL_SetError ("Failed getting OpenGL context version");