#include #include #include #define ATTRIBUTE GLX_HEIGHT //callback for the next function static Bool WaitForNotify(Display *d, XEvent *e, char *arg) { return (e->type == MapNotify) && (e->xmap.window == *((Window*)arg)); } // Create XWindow according to GLXConfig and wait for CreateNotify event. Window tglCreateXWindow(Display* dpy, GLXFBConfig config) { XEvent event; int height = 600; int width = 800; XVisualInfo* vi = glXGetVisualFromFBConfig(dpy, config); assert(vi != NULL); XSetWindowAttributes swa; swa.border_pixel = 0; swa.event_mask = StructureNotifyMask; swa.colormap = XCreateColormap( dpy, XRootWindow(dpy, vi->screen), vi->visual, AllocNone ); int swaMask = CWBorderPixel | CWColormap | CWEventMask; Window win = XCreateWindow( dpy, XRootWindow(dpy, vi->screen), 0, 0, width, height, 0, vi->depth, InputOutput, vi->visual, swaMask, &swa ); XFree(vi); assert(win != 0); XMapWindow(dpy, win); XIfEvent(dpy, &event, WaitForNotify, (char*)(&win)); return win; } int main() { Window win = 0; GLXWindow glxWindow = 0; Display* display = XOpenDisplay(NULL); assert(display != NULL); int attribs[] = { GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_DOUBLEBUFFER, True, GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, None}; int nelems; GLXFBConfig* configs = glXChooseFBConfig(display, DefaultScreen(display), attribs, &nelems); assert((configs != NULL) && (nelems != 0)); GLXFBConfig config = configs[0]; XFree(configs); win = tglCreateXWindow(display, config); assert(win != 0); glxWindow = glXCreateWindow(display, config, win, NULL); assert(glxWindow != 0); unsigned int value = -1; glXQueryDrawable(display, glxWindow, ATTRIBUTE, &value); printf("Value became %u.\n", value); //cleanup if(display) { if(glxWindow) glXDestroyWindow(display, glxWindow); if(win) XDestroyWindow(display, win); XCloseDisplay(display); } return 0; }