Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: glXChooseVisual return always NULL!

  1. #1

    glXChooseVisual return always NULL!

    Please may anyone help me to let this simple code run?
    I post the first lines of my code that return a NULL pointer in the last line.

    The problem is that visual is never created even if I use empty attributes.
    (Only a geforce3 runs this correctly,
    but I have not got it!))

    display = XOpenDisplay(NULL);
    screenNumber = DefaultScreen(display);
    rootWindow = RootWindow(display,screenNumber);

    visualInfo =
    glXChooseVisual(display, screenNumber, glxAttributes);


  2. #2

    Re: glXChooseVisual return always NULL!

    I think that the problem is with glxAttributes. Check the man page for glXChooseVisual. Here is a complete little example that should work:
    Code :
    #include <GL/glx.h>
    #include <GL/gl.h>
    #include <unistd.h>
    static int attributeList[] = { GLX_RGBA, None };
    static Bool WaitForNotify(Display *d, XEvent *e, char *arg) {
        return (e->type == MapNotify) &amp;&amp; (e->xmap.window == (Window)arg);
    int main(int argc, char **argv) {
        Display *dpy;
        XVisualInfo *vi;
        Colormap cmap;
        XSetWindowAttributes swa;
        Window win;
        GLXContext cx;
        XEvent event;
        /* get a connection */
        dpy = XOpenDisplay(0);
        /* get an appropriate visual */
        vi = glXChooseVisual(dpy, DefaultScreen(dpy), attributeList);
        /* create a GLX context */
        cx = glXCreateContext(dpy, vi, 0, GL_TRUE);
        /* create a colormap */
        cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen),
                               vi->visual, AllocNone);
        /* create a window */
        swa.colormap = cmap;
        swa.border_pixel = 0;
        swa.event_mask = StructureNotifyMask;
        win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 100, 100,
                            0, vi->depth, InputOutput, vi->visual,
                            CWBorderPixel|CWColormap|CWEventMask, &amp;swa);
        XMapWindow(dpy, win);
        XIfEvent(dpy, &amp;event, WaitForNotify, (char*)win);
        /* connect the context to the window */
        glXMakeCurrent(dpy, win, cx);
        /* clear the buffer */
        /* wait a while */

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts