SFML community forums

Help => General => Topic started by: Khatharr on March 06, 2023, 01:55:41 am

Title: Run SFML without a window for linux with no X11 installed
Post by: Khatharr on March 06, 2023, 01:55:41 am
Hello. I've used SFML in Windows to create a utility that will generate a png representation of some text data. The program does not create a window, since it's just rendering to an sf::RenderTexture and then getting the texture out of that and saving it to a file. I'm intending to use this on a Raspberry Pi 4 that's running OSMC (2022.03-1) in order to generate a background image for my media center.

I was able to install SFML and compile the program, but when I try to run the program I get the output:
Quote
Failed to open X11 display; make sure the DISPLAY environment variable is set correctly

X is not installed on this device, since the OS generates its own GUI. I'm wondering if there's something I can do to bypass the requirement for it, since SFML is not being required to draw to the screen. I'm fine with downloading the SFML source and making changes, but I'm not familiar enough with the situation to know where to start looking.

Any advice would be greatly appreciated.   :D
Title: Re: Run SFML without a window for linux with no X11 installed
Post by: eXpl0it3r on March 06, 2023, 10:51:53 am
That's one of the main reason we had help from some community members to add support for DRM/KVM (https://github.com/SFML/SFML/pull/2029) for SFML 2.6

Build SFML with the SFML_USE_DRM flag set in CMake.
Title: Re: Run SFML without a window for linux with no X11 installed
Post by: Khatharr on March 06, 2023, 12:17:11 pm
Oh, cool.

Thank you!  ;D
Title: Re: Run SFML without a window for linux with no X11 installed
Post by: Khatharr on March 07, 2023, 12:29:41 am
So I grabbed the SFML 2.6.x source from GitHub, and I installed as follows:
Quote
mkdir build
cd build
cmake .. -DSFML_USE_DRM=TRUE
make -j4
sudo make install
sudo ldconfig

and then I was able to build my project with:
Quote
g++ main.cpp -lsfml-system -lsfml-graphics -o imgGen.exe

but when I run the exe I get:
Quote
No drm device found!
Could not open drm device
Error initializing DRM
Segmentation fault

I'm not familiar with DRM. Do I need to install/include some driver libraries for it or something?

--

Reading a little more about it, it seems that it has something to do with "/dev/dri/card*". I have card0 and card1 in there.
Title: Re: Run SFML without a window for linux with no X11 installed
Post by: eXpl0it3r on March 07, 2023, 08:53:47 am
I'm not really familiar with it either, but you'll need some DRM driver.
Hope a web search will reveal some more information.
Title: Re: Run SFML without a window for linux with no X11 installed
Post by: Khatharr on March 07, 2023, 09:05:39 am
I'll try asking the OSMC people about it and also hunt around google a bit more. If I figure it out I'll post the solution here.

Thank you for helping me get this far!
Title: Re: Run SFML without a window for linux with no X11 installed
Post by: Khatharr on May 21, 2023, 11:51:57 pm
After a lot of running around I haven't gotten very far.

While snooping around I did notice https://github.com/SFML/SFML/pull/2442 which added Mesa support in order to allow software rendering in the CI. Is it possible to compile SFML to use Mesa and LLVMpipe in order to sidestep the driver issue? The performance hit would be irrelevant in my use case, since I'm only drawing one frame.
Title: Re: Run SFML without a window for linux with no X11 installed
Post by: eXpl0it3r on May 22, 2023, 07:43:36 am
If that's easier to setup than DRM, then sure! Keep in mind that, this is only available on the master branch, which is targeting WIP SFML 3 with a few breaking changes.
Title: Re: Run SFML without a window for linux with no X11 installed
Post by: Powereleven on March 01, 2025, 10:04:25 pm
I found a simple solution: mocking X11 by installing xvfb (apt install -y xvfb) and running the executable with xvfb-run (xvfb-run ./a.out).
I did try many alternatives before finding this one, like compiling from source with the DRM and/or MESA3D flags. But Mesa3D seems to be supported only on Windows currently, and DRM has other issues.