glx_window_management.cpp

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) Massimo Cora' 2006 <maxcvs@gmail.com>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021 
00022 #include "glx_window_management.h"
00023 
00024 static GLXContext ctx;
00025 /*
00026  * Create a simple double-buffered RGBA window.
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    /* Choose GLX visual / pixel format */
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    /* Create the window */
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    /* Display the window */
00068 //   XMapWindow(dpy, win);
00069 
00070    /* Create GLX rendering context */
00071    ctx = glXCreateContext(dpy, visinfo, NULL, True);
00072    if (!ctx) {
00073       printf("Error: glXCreateContext failed\n");
00074       exit(1);
00075    }
00076 
00077    /* Bind the rendering context and window */
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 

Generated on Tue Dec 26 10:32:38 2006 for Omnimeeting by  doxygen 1.4.7