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: https://github.com/robclark/kmscube/blob/master/kmscube.c (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.
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
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.