diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-10-10 13:56:10 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-10-10 13:59:44 +0200 |
commit | 54b2376adad98d91d32378efc3f241f120ba970f (patch) | |
tree | 4556581f7c51f88e9cb1e5610bc8afef524340e1 /src/gl.c | |
parent | 3b2fceed064c06d55e1cd33d51e855e909c81f75 (diff) |
Draw every frame instead of x11 expose, enable vsync (if available)
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; } |