xglcomp

annotate src/opengl.cc @ 10:be18500d76d1

better error message in xerr_debug
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 03 Feb 2016 03:55:52 +0200
parents
children
rev   line source
nuclear@2 1 #include "opengl.h"
nuclear@2 2 #include "logger.h"
nuclear@2 3
nuclear@2 4 extern Display *dpy;
nuclear@2 5 extern Window root_win;
nuclear@2 6 extern int screen_num;
nuclear@2 7 extern int root_width, root_height;
nuclear@2 8
nuclear@2 9 GLXContext create_gl(Window xwin)
nuclear@2 10 {
nuclear@2 11 static int glxattr[] = {
nuclear@2 12 GLX_USE_GL, 1,
nuclear@2 13 GLX_RGBA,
nuclear@2 14 GLX_DOUBLEBUFFER,
nuclear@2 15 GLX_RED_SIZE, 8,
nuclear@2 16 GLX_GREEN_SIZE, 8,
nuclear@2 17 GLX_BLUE_SIZE, 8,
nuclear@2 18 GLX_DEPTH_SIZE, 16,
nuclear@2 19 None
nuclear@2 20 };
nuclear@2 21
nuclear@2 22 XVisualInfo *vis_info = glXChooseVisual(dpy, screen_num, glxattr);
nuclear@2 23 if(!vis_info) {
nuclear@2 24 log_error("failed to find suitable GLX visual\n");
nuclear@2 25 return 0;
nuclear@2 26 }
nuclear@2 27
nuclear@2 28 GLXContext ctx = glXCreateContext(dpy, vis_info, 0, True);
nuclear@2 29 if(!ctx) {
nuclear@2 30 log_error("failed to create OpenGL context\n");
nuclear@2 31 XFree(vis_info);
nuclear@2 32 return 0;
nuclear@2 33 }
nuclear@2 34 XFree(vis_info);
nuclear@2 35
nuclear@2 36 if(!glXMakeCurrent(dpy, xwin, ctx)) {
nuclear@2 37 log_error("failed to attach OpenGL context to window\n");
nuclear@2 38 glXDestroyContext(dpy, ctx);
nuclear@2 39 return 0;
nuclear@2 40 }
nuclear@2 41 return ctx;
nuclear@2 42 }
nuclear@2 43
nuclear@2 44 void destroy_gl(GLXContext ctx)
nuclear@2 45 {
nuclear@2 46 glXMakeCurrent(dpy, 0, 0);
nuclear@2 47 glXDestroyContext(dpy, ctx);
nuclear@2 48 }