diff options
Diffstat (limited to 'src/glx.c')
-rw-r--r-- | src/glx.c | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/src/glx.c b/src/glx.c deleted file mode 100644 index 6712947..0000000 --- a/src/glx.c +++ /dev/null @@ -1,55 +0,0 @@ -#include "../include/mgl/glx.h" -#include <dlfcn.h> -/*#include <GL/glx.h>*/ -#include <stdio.h> - -typedef struct { - void **func; - const char *name; -} dlsym_assign; - -static void* dlsym_print_fail(void *handle, const char *name) { - dlerror(); - void *sym = dlsym(handle, name); - char *err_str = dlerror(); - - if(!sym) - fprintf(stderr, "dlsym(handle, \"%s\") failed, error: %s\n", name, err_str ? err_str : "(null)"); - - return sym; -} - -int mgl_glx_load(mgl_glx *self) { - const char *glx_path = "/usr/lib/libGLX.so.0"; - self->handle = dlopen(glx_path, RTLD_LAZY); - if(!self->handle) { - fprintf(stderr, "dlopen(\"%s\", RTLD_LAZY) failed\n", glx_path); - return -1; - } - - const dlsym_assign assign[] = { - { &self->glXChooseVisual, "glXChooseVisual" }, - { &self->glXCreateContext, "glXCreateContext" }, - { &self->glXDestroyContext, "glXDestroyContext" }, - { &self->glXMakeCurrent, "glXMakeCurrent" }, - { &self->glXSwapBuffers, "glXSwapBuffers" }, - { 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) { - mgl_glx_unload(self); - return -1; - } - } - - return 0; -} - -void mgl_glx_unload(mgl_glx *self) { - if(self->handle) { - dlclose(self->handle); - self->handle = NULL; - } -} |