Off-screen rendering and x-windows


I would like to make a program with glfw that could do off-screen rendering without even needing an x-window display. Is it possible to do it with LGFW? What would be the recommended approach to solve this problem?

Ideally, the same program started with different options, should be able to use normal OpenGL windows.

You cannot do that with GLFW (at least currently). To use OpenGL in GLFW on Linux you need either X11, Wayland or MIR.
If you want to render without running x11 (or others) you’ll need use KMS functionality before setting up GL context. Here’s a good example how to do that: (it initializes GLES context, but for regular GL context it is pretty much the same). This program should run without any graphics display server running in background.

For getting keyboard/mouse/joystick input you need to use different API’s - for example, parsing data out from dev/input/event* devices.

I’d just like to add a bit more information as the meaning of “without an x-window display” could mean several things.

GLFW now supports offscreen contexts without a visible window.. If this is what you are looking for then follow the linked documentation.

Thanks for the answer.

Wouldn’t be a valuable addition for glfw that, when requesting an offscreen context without a visible window, the library used egl instead of glx in linux?

@ramsan Could you explain why you want the library to do this? You can already specify which context you want using context hints.

Note that if you’re referring to @mmozeiko’s answer their example uses OpenGL ES but could equally well use OpenGL - the method they’re referring to is an approach which doesn’t use a window (whereas GLFW creates an invisible window).

My use case is to have a unique program that can be used in two modes:

  • Mode 1: Standard interactive program with OpenGL windows
  • Mode 2: Windowless program that could make offscreen rendering

In mode 2 in Linux, program should be able to run without a DISPLAY, so as it can be used from a web server in order to generate pictures or any other graphical material

So, I am requesting that when user does this:

GLFWwindow* offscreen_context = glfwCreateWindow(640, 480, “”, NULL, NULL);

and there is no DISPLAY nor X-Windows active, OpenGL was initialized in a different way, for example using egl

An extension to this would be that the program could be used interactively and with graphical windows from a remote server (like an HPC computer) by using vnc or a similar protocol and having hardware accelerated OpenGL.

Two kinds of true headless rendering for Linux are being merged for 3.3. Both are fully separate backends and will not allow the same binary to work with X, but that will be supported at some point after 3.3.

1 Like

Thanks @ramsan - I wrongly misread EGL as GLES, my apologies.