static TFB_ColorMap * clone_colormap (TFB_ColorMap *from, int index) // returns an addrefed object { TFB_ColorMap *map; map = alloc_colormap (); if (!map) { log_add (log_Warning, "FATAL: clone_colormap(): " "could not allocate a map"); exit (EXIT_FAILURE); } else { // fresh new map map->index = index; if (from) map->version = from->version; } map->version++; return map; }
int main(int argc, char *argv[]) { static int glAttribs[] = { GLX_DOUBLEBUFFER, GLX_RGBA, GLX_DEPTH_SIZE, 1, None }; Display *dpy; XVisualInfo *visInfo; int scrn; Window root; Colormap cmap; Window win; XSetWindowAttributes winAttribs; unsigned long winAttribsMask; GLXContext glCtx; int ignore; const char *name = "OpenGL in a Shaped Window"; dpy = XOpenDisplay(NULL); if (!dpy) { fprintf(stderr, "Couldn't open default display\n"); return 1; } /* check that we can use the shape extension */ if (!XQueryExtension(dpy, "SHAPE", &ignore, &ignore, &ignore )) { fprintf(stderr, "Display doesn't support shape extension\n"); return 1; } scrn = DefaultScreen(dpy); root = RootWindow(dpy, scrn); visInfo = glXChooseVisual(dpy, scrn, glAttribs); if (!visInfo) { fprintf(stderr, "Couldn't get RGB, DB, Z visual\n"); return 1; } glCtx = glXCreateContext(dpy, visInfo, 0, True); if (!glCtx) { fprintf(stderr, "Couldn't create GL context\n"); return 1; } cmap = alloc_colormap(dpy, root, visInfo->visual); if (!cmap) { fprintf(stderr, "Couln't create colormap\n"); return 1; } winAttribs.border_pixel = 0; winAttribs.colormap = cmap; winAttribs.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; winAttribsMask = CWBorderPixel | CWColormap | CWEventMask; win = XCreateWindow(dpy, root, 0, 0, Width, Height, 0, visInfo->depth, InputOutput, visInfo->visual, winAttribsMask, &winAttribs); { XSizeHints sizehints; /* sizehints.x = xpos; sizehints.y = ypos; sizehints.width = width; sizehints.height = height; */ sizehints.flags = 0; XSetNormalHints(dpy, win, &sizehints); XSetStandardProperties(dpy, win, name, name, None, (char **)NULL, 0, &sizehints); } XMapWindow(dpy, win); glXMakeCurrent(dpy, win, glCtx); printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); printf("Press ESC to exit.\n"); printf("Press up/down to change window shape.\n"); event_loop(dpy, win); return 0; }