xglcomp
diff src/opengl.cc @ 2:876efea9424c
OpenGL
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 22 Jan 2016 06:31:03 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/opengl.cc Fri Jan 22 06:31:03 2016 +0200 1.3 @@ -0,0 +1,48 @@ 1.4 +#include "opengl.h" 1.5 +#include "logger.h" 1.6 + 1.7 +extern Display *dpy; 1.8 +extern Window root_win; 1.9 +extern int screen_num; 1.10 +extern int root_width, root_height; 1.11 + 1.12 +GLXContext create_gl(Window xwin) 1.13 +{ 1.14 + static int glxattr[] = { 1.15 + GLX_USE_GL, 1, 1.16 + GLX_RGBA, 1.17 + GLX_DOUBLEBUFFER, 1.18 + GLX_RED_SIZE, 8, 1.19 + GLX_GREEN_SIZE, 8, 1.20 + GLX_BLUE_SIZE, 8, 1.21 + GLX_DEPTH_SIZE, 16, 1.22 + None 1.23 + }; 1.24 + 1.25 + XVisualInfo *vis_info = glXChooseVisual(dpy, screen_num, glxattr); 1.26 + if(!vis_info) { 1.27 + log_error("failed to find suitable GLX visual\n"); 1.28 + return 0; 1.29 + } 1.30 + 1.31 + GLXContext ctx = glXCreateContext(dpy, vis_info, 0, True); 1.32 + if(!ctx) { 1.33 + log_error("failed to create OpenGL context\n"); 1.34 + XFree(vis_info); 1.35 + return 0; 1.36 + } 1.37 + XFree(vis_info); 1.38 + 1.39 + if(!glXMakeCurrent(dpy, xwin, ctx)) { 1.40 + log_error("failed to attach OpenGL context to window\n"); 1.41 + glXDestroyContext(dpy, ctx); 1.42 + return 0; 1.43 + } 1.44 + return ctx; 1.45 +} 1.46 + 1.47 +void destroy_gl(GLXContext ctx) 1.48 +{ 1.49 + glXMakeCurrent(dpy, 0, 0); 1.50 + glXDestroyContext(dpy, ctx); 1.51 +}