From e57daa001cc74682cdb905d8e0c6c8c3a2c29372 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 10 Oct 2021 10:59:43 +0200 Subject: Initial commit, skeleton --- src/mgl.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/mgl.c (limited to 'src/mgl.c') diff --git a/src/mgl.c b/src/mgl.c new file mode 100644 index 0000000..a7221d0 --- /dev/null +++ b/src/mgl.c @@ -0,0 +1,48 @@ +#include "../include/mgl/mgl.h" +#include +#include + +static mgl_context context; +static int init_count = 0; +static XErrorHandler prev_xerror = NULL; + +static int ignore_xerror(Display *display, XErrorEvent *ee) { + (void)display; + (void)ee; + return 0; +} + +int mgl_init(void) { + ++init_count; + if(init_count == 1) { + context.connection = XOpenDisplay(NULL); + if(!context.connection) { + fprintf(stderr, "XOpenDisplay(NULL) failed\n"); + mgl_deinit(); + return -1; + } + + prev_xerror = XSetErrorHandler(ignore_xerror); + if(mgl_glx_load(&context.glx) != 0) { + mgl_deinit(); + return -1; + } + } + return 0; +} + +void mgl_deinit(void) { + if(init_count == 1) { + mgl_glx_unload(&context.glx); + XSetErrorHandler(prev_xerror); + XCloseDisplay(context.connection); + context.connection = NULL; + } + + if(init_count > 0) + --init_count; +} + +mgl_context* mgl_get_context(void) { + return &context; +} -- cgit v1.2.3