00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021
00022 #include "glx_window_management.h"
00023
00024 static GLXContext ctx;
00025
00026
00027
00028 Window glx_init (Display * dpy, unsigned int width, unsigned int height)
00029 {
00030 int visAttributes[] = {
00031 GLX_RGBA,
00032 GLX_RED_SIZE, 1,
00033 GLX_GREEN_SIZE, 1,
00034 GLX_BLUE_SIZE, 1,
00035 GLX_DOUBLEBUFFER,
00036 None
00037 };
00038
00039 XSetWindowAttributes attr;
00040 unsigned long attrMask;
00041 Window root;
00042 Window win;
00043 XVisualInfo *visinfo;
00044
00045 root = RootWindow(dpy, 0);
00046
00047
00048 visinfo = glXChooseVisual(dpy, 0, visAttributes);
00049 if (!visinfo) {
00050 printf("Error: couldn't get an RGB, Double-buffered visual\n");
00051 exit(1);
00052 }
00053
00054
00055 attr.background_pixel = 0;
00056 attr.border_pixel = 0;
00057 attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
00058 attrMask = CWBackPixel | CWBorderPixel | CWColormap;
00059 win = XCreateWindow(dpy, root, 0, 0, width, height,
00060 0, visinfo->depth, InputOutput,
00061 visinfo->visual, attrMask, &attr);
00062 if (!win) {
00063 printf("Error: XCreateWindow failed\n");
00064 exit(1);
00065 }
00066
00067
00068
00069
00070
00071 ctx = glXCreateContext(dpy, visinfo, NULL, True);
00072 if (!ctx) {
00073 printf("Error: glXCreateContext failed\n");
00074 exit(1);
00075 }
00076
00077
00078 glXMakeCurrent(dpy, win, ctx);
00079
00080 return win;
00081 }
00082
00083
00084 void glx_deinit (Display *dpy)
00085 {
00086 glXDestroyContext (dpy, ctx);
00087 }
00088