diff options
Diffstat (limited to 'src/window')
-rw-r--r-- | src/window/window.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/window/window.c b/src/window/window.c index 2e9a1ba..f29b920 100644 --- a/src/window/window.c +++ b/src/window/window.c @@ -49,6 +49,12 @@ static int mgl_window_init(mgl_window *self, const char *title, int width, int h if(parent_window == 0) parent_window = DefaultRootWindow(context->connection); + self->glx_context = context->gl.glXCreateContext(context->connection, context->visual_info, NULL, 1); + if(!self->glx_context) { + fprintf(stderr, "glXCreateContext failed\n"); + return -1; + } + Colormap color_map = XCreateColormap(context->connection, DefaultRootWindow(context->connection), ((XVisualInfo*)context->visual_info)->visual, AllocNone); if(!color_map) { fprintf(stderr, "XCreateColormap failed\n"); @@ -68,6 +74,7 @@ static int mgl_window_init(mgl_window *self, const char *title, int width, int h if(!XChangeWindowAttributes(context->connection, existing_window, CWColormap | CWEventMask | CWBitGravity, &window_attr)) { fprintf(stderr, "XChangeWindowAttributes failed\n"); XFreeColormap(context->connection, color_map); + mgl_window_deinit(self); return -1; } XFreeColormap(context->connection, color_map); @@ -89,8 +96,8 @@ static int mgl_window_init(mgl_window *self, const char *title, int width, int h XFlush(context->connection); - /* TODO: Switch current when rendering to another window, and set current to NULL when destroying the currently selected context */ - context->gl.glXMakeCurrent(context->connection, self->window, context->glx_context); + /* TODO: Check for failure? */ + context->gl.glXMakeCurrent(context->connection, self->window, self->glx_context); set_vertical_sync_enabled(self->window, 1); context->gl.glEnable(GL_TEXTURE_2D); context->gl.glEnable(GL_BLEND); @@ -123,6 +130,10 @@ int mgl_window_init_from_existing_window(mgl_window *self, mgl_window_handle exi void mgl_window_deinit(mgl_window *self) { mgl_context *context = mgl_get_context(); + if(self->glx_context) { + context->gl.glXDestroyContext(context->connection, self->glx_context); + self->glx_context = NULL; + } if(self->window) { XDestroyWindow(context->connection, self->window); self->window = 0; @@ -172,3 +183,4 @@ void mgl_window_display(mgl_window *self) { mgl_context *context = mgl_get_context(); context->gl.glXSwapBuffers(context->connection, self->window); } + |