diff options
Diffstat (limited to 'src/gl.c')
-rw-r--r-- | src/gl.c | 34 |
1 files changed, 26 insertions, 8 deletions
@@ -1,6 +1,6 @@ #include "../include/mgl/gl.h" #include <dlfcn.h> -/*#include <GL/gl.h>*/ +/*#include <GL/glx.h>*/ #include <stdio.h> typedef struct { @@ -20,28 +20,46 @@ static void* dlsym_print_fail(void *handle, const char *name) { } int mgl_gl_load(mgl_gl *self) { - const char *gl_path = "/usr/lib/libOpenGL.so.0"; - self->handle = dlopen(gl_path, RTLD_LAZY); + const char *glx_path = "/usr/lib/libGL.so.1"; + self->handle = dlopen(glx_path, RTLD_LAZY); if(!self->handle) { - fprintf(stderr, "dlopen(\"%s\", RTLD_LAZY) failed\n", gl_path); + fprintf(stderr, "dlopen(\"%s\", RTLD_LAZY) failed\n", glx_path); return -1; } - const dlsym_assign assign[] = { + const dlsym_assign required_dlsym[] = { + { &self->glXChooseVisual, "glXChooseVisual" }, + { &self->glXCreateContext, "glXCreateContext" }, + { &self->glXDestroyContext, "glXDestroyContext" }, + { &self->glXMakeCurrent, "glXMakeCurrent" }, + { &self->glXSwapBuffers, "glXSwapBuffers" }, + { &self->glViewport, "glViewport" }, { &self->glClearColor, "glClearColor" }, { &self->glClear, "glClear" }, + { NULL, NULL } }; - for(int i = 0; assign[i].func; ++i) { - *assign[i].func = dlsym_print_fail(self->handle, assign[i].name); - if(!assign[i].func) { + for(int i = 0; required_dlsym[i].func; ++i) { + *required_dlsym[i].func = dlsym_print_fail(self->handle, required_dlsym[i].name); + if(!required_dlsym[i].func) { mgl_gl_unload(self); return -1; } } + const dlsym_assign optional_dlsym[] = { + { &self->glXSwapIntervalEXT, "glXSwapIntervalEXT" }, + { &self->glXSwapIntervalMESA, "glXGetSwapIntervalMESA" }, + { &self->glXSwapIntervalSGI, "glXSwapIntervalSGI" }, + { NULL, NULL } + }; + + for(int i = 0; optional_dlsym[i].func; ++i) { + *optional_dlsym[i].func = dlsym_print_fail(self->handle, optional_dlsym[i].name); + } + return 0; } |