user3115932
user3115932

Reputation: 19

Opening an X11 window for GL on a specific display

I'm taking over some legacy code, and it's using Xlib + glX to create its drawing windows. However, the window creation fails when the display name is set to be anything than :0.0.

I was able to reproduce this behavior in a minimal example:

#include <X11/Xlib.h>
#include <GL/glew.h>
#include <GL/glx.h>

int main()
{
    Display* display = XOpenDisplay(":0.1");

    GLint vi_att[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None };
    XVisualInfo* vi = glXChooseVisual(display, 0, vi_att);

    Window root = DefaultRootWindow(display);
    Colormap cmap = XCreateColormap(display, root, vi->visual, AllocNone);
    XSetWindowAttributes swa;
    swa.colormap = cmap;
    swa.event_mask = ExposureMask;

    Window window = XCreateWindow(display, root, 0, 0, 200, 400, 0,
        vi->depth, InputOutput, vi->visual, CWColormap | CWEventMask,
        &swa);

    GLXContext context = glXCreateContext(display, vi, NULL, GL_TRUE);
    glXMakeCurrent(display, window, context);
    XMapWindow(display, window);
    XFlush(display);

    return 0;
}

Executing this example I get a console message

X Error of failed request:  BadMatch (invalid parameter attributes)
    Major opcode of failed request:  78 (X_CreateColormap)
    Serial number of failed request:  21
    Current serial number in output stream:  23

and the stepping through the various routines I find that I do get a valid display, and I do get a valid visual. Problems arise at glXCreateContext.

To make things clear, :0.1 is a valid display (I've set up separate X displays for my monitors to test this), and, interestingly, it does not make a difference from what display I'm executing the code. At first I thought that it wouldn't work to set up the window on a different display, but running the example with :0.0 from display :0.1 works fine. Running :0.1 from :0.1 does not.

More interestingly, choosing NULL as XOpenDisplay parameter, and running it on the :0.1 display also produces the same error.

Upvotes: 1

Views: 3301

Answers (1)

datenwolf
datenwolf

Reputation: 162164

Having multiple screens indicates that your X server has been set up in Zaphod mode. Depending on which driver you're using and how graphics output has been configured OpenGL may work not at all or on only one of the screens.

Please post your /var/log/Xorg.0.log so that I can give you more details.

But I can tell you already that Zaphod mode and OpenGL are on difficult terms with most drivers and system configurations.

Update due to comment

Okay, given your Xorg.0.log it's no surprise that you can create OpenGL contexts on only one of the screens: You got only a single GPU as indicated by the lines (note the identical PCI Bus-ID):

[    18.192] (II) NVIDIA(0): NVIDIA GPU GeForce GTS 450 (GF116) at PCI:1:0:0 (GPU-0)
…
[    18.214] (II) NVIDIA(1): NVIDIA GPU GeForce GTS 450 (GF116) at PCI:1:0:0 (GPU-0)

and use it on multiple X screens with different outputs. It's simply not supported by the drivers and it's been perfectly well documented:

(…) windows cannot be dragged between X screens, hardware accelerated OpenGL cannot span the (…) X screens (…)

However the actual question is: Why for bob's sake are you using multiple screen (=Zaphod) mode in the first place? There's only one situation in which doing this is sensible. And that is if you have multiple graphics cards, which you cannot interconnect (SLi or CrossFire or different models or vendors) in a single machine and you'd like to use them all together in a single X display multiple screen configuration.

Apart from that you should be using TwinView, because that does what you trivially expect from it.


Note that if your desire is to get more screen real estate by plugging several graphics cards into a box, you can use a combination of DMX (Distributed Multihead X) and Xpra or Chromium, but this requires some serious tinkering and AFAIK nobody did documented the Xpra method to this data (could be a nice weekend project though).

Upvotes: 2

Related Questions