xglcomp

view 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 source
1 #include "opengl.h"
2 #include "logger.h"
4 extern Display *dpy;
5 extern Window root_win;
6 extern int screen_num;
7 extern int root_width, root_height;
9 GLXContext create_gl(Window xwin)
10 {
11 static int glxattr[] = {
12 GLX_USE_GL, 1,
13 GLX_RGBA,
14 GLX_DOUBLEBUFFER,
15 GLX_RED_SIZE, 8,
16 GLX_GREEN_SIZE, 8,
17 GLX_BLUE_SIZE, 8,
18 GLX_DEPTH_SIZE, 16,
19 None
20 };
22 XVisualInfo *vis_info = glXChooseVisual(dpy, screen_num, glxattr);
23 if(!vis_info) {
24 log_error("failed to find suitable GLX visual\n");
25 return 0;
26 }
28 GLXContext ctx = glXCreateContext(dpy, vis_info, 0, True);
29 if(!ctx) {
30 log_error("failed to create OpenGL context\n");
31 XFree(vis_info);
32 return 0;
33 }
34 XFree(vis_info);
36 if(!glXMakeCurrent(dpy, xwin, ctx)) {
37 log_error("failed to attach OpenGL context to window\n");
38 glXDestroyContext(dpy, ctx);
39 return 0;
40 }
41 return ctx;
42 }
44 void destroy_gl(GLXContext ctx)
45 {
46 glXMakeCurrent(dpy, 0, 0);
47 glXDestroyContext(dpy, ctx);
48 }