Multi Screen Application with GLFW

Hello,

I’m working with GLFW. I want to set up an app dealing with multiple screens, i.e 6, connected to a single graphics card. I have found out that GLFW can’t specify the display i want to use with some command like “-display :0.1” (https://github.com/glfw/glfw/issues/29). Since GLX can do that and GLFW is using GLX, i’m wondering if one could easily modify GLFW, so one have access to this option.

Since i’m new in this field there might also be a simple workaround, which i couldn’t find yet.

At first i considered using glfwgetmonitors to obtain the different screens, but this function only finds the primary screen. (GLFW has a working tests program called monitors, which outputs all connected monitors with some related data, but it finds only one monitor while 6 are connected). This might be caused because all the screens are in the same graphics card. Is there a way to modify, maybe, the xorg.conf file so that the system knows about the different screens? (I have Ubuntu 14.04) At the moment all the screens in the xorg.conf are adressed to the PCI bus 3:0:0.

Please give me some thoughts on either of these options, thanks

I have been using GLFW 3.0 and glfwGetMonitors(…) returns all the monitors I have connected (2 in my case) in a single GPU. If you start your program as console application you can first get the monitors and have the user decide which monitor to use by printing all the necessary information for the user. After you get the input just use that monitor in the window creation parts of your program.

Well, the problem is, that GLFW only finds one monitor (the primary) and not all 6, so i have no possibility to choose…

What does


int count;
GLFWmonitor** monitors = glfwGetMonitors(&count)

give you for the count variable’s value?

I loop the monitors like this

int count;
        GLFWmonitor** monitors = glfwGetMonitors(&count);
        for(int i = 0; i<count; i++)
        {
            monitorList.push_back(new Monitor(monitors[i]));
        }

As I said, it only gives one monitor, so 1 for the count…

My current solution is a modification of the GLFW library, don’t know if this is stable, but i worked for a simple test.

I report my steps:

first I have to pass down the information which Display to use, so I edit the declaration

GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, const char* title, GLFWmonitor* monitor, GLFWwindow* share)

to have

GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,const char* title,GLFWmonitor* monitor,GLFWwindow* share, char* dpyname)

in the header file “glfw3.h” and “window.c”

Then in glfwCreateWindow give the Displayname to another function

_glfwPlatformCreateWindow(window, &wndconfig, &ctxconfig, &fbconfig, dpyname)

To do this we have to change the declaration of this function in “internal.h” like before. The function is defined in “x11_window.c” (under linux). Now some modification to this function:

int _glfwPlatformCreateWindow(_GLFWwindow* window,
                              const _GLFWwndconfig* wndconfig,
                              const _GLFWctxconfig* ctxconfig,
                              const _GLFWfbconfig* fbconfig, char* dpyname)
{
    _glfw.x11.display = XOpenDisplay(dpyname);
    if (!_glfw.x11.display)
    {
        _glfwInputError(GLFW_PLATFORM_ERROR, "X11: Failed to open X display");
        return GL_FALSE;
    }

    _glfw.x11.screen = DefaultScreen(_glfw.x11.display);
    _glfw.x11.root = RootWindow(_glfw.x11.display, _glfw.x11.screen);
    _glfw.x11.context = XUniqueContext();

  

    if (!_glfwCreateContext(window, ctxconfig, fbconfig))
        return GL_FALSE;

    if (!createWindow(window, wndconfig))
        return GL_FALSE;

    if (wndconfig->monitor)
    {
        _glfwPlatformShowWindow(window);
        enterFullscreenMode(window);
    }

    return GL_TRUE;
}

and adding

#include <X11/Xresource.h>

to the header of x11_window.c

finally, after recompiling the library it works for now…

It appears that you’re trying to create windows on multiple displays (as opposed to multiple screens), and I don’t think that GLFW will be of use there.

It isn’t just an issue of specifying a display when you create a window. E.g. each display has its own event queue, so GLFW would need to poll all the displays for events.

You might consider using GTK instead. That supports using multiple displays. You can get a list of screens for each display and create a window on a specific screen using gtk_window_set_screen().

You won’t find equivalent functionality on most other toolkits. Typically, it only exists on toolkits which are either specific to X11 (e.g. Xt) or have X11 as their primary target (i.e. GTK).

Ok thanks, i’ll look into GTK… i just hoped i don’t need to rewrite the whole app…

Qt also has some widget which can deal with multiple displays

Needed to do a bit of googling to try to figure out what you are trying to do. So are you trying to create something like this Build a Six-headed, Six-user Linux System LG #124 or do you just want multiple input devices like keyboards to be handled through GLFW?

Qt cannot handle multiple displays. It can handle multiple screens, but they must all belong to the same display.

I want to create a seamless display with 6 projectors connected to a single GPU… Therefore i have an app that needs to create a window on every screen.

i guess i messed up the nomenclature of those things, I’m sorry for that :slight_smile:

Since GLFW can deal with multiple windows, it maybe is just an issue of specifying the screen.

Nevertheless, my changed library got me multiple windows now and also the Qt widget (which i got from someone else) is also able to do that. Don’t ask me why :slight_smile: