Hacker News new | ask | show | jobs
by CodeArtisan 558 days ago
On Linux, you may mmap /dev/fb0 to access the front buffer like you would have on old computers. Not all kernel configs and GPU devices allow that. You can test if fb0 is usable with cat /dev/random > /dev/fb0 to see if the screen is filled with garbage (you may also need root privilege).
2 comments

You could also implement a Wayland or X11 client by yourself. Those libraries are also implemented in C after all. No need for external libraries to write to some sockets.

Whether it's worth doing is another matter.

This is not actually that difficult if you just want the basics. I have a project that implements just the x11 key & mouse events, and the shared memory extension in 400 lines of Rust. Was worth it for me since it eliminated dependency on libx11 and libc, which removed a dependency on something like 800,000 lines of code across those two libraries. (Determined by a basic cloc on each library source. Actually compiled code for a specific architecture would probably be less than that, but still orders of magnitude more than 400.)
I probably wouldn't bother with implementing X11 from scratch for a game as even simply fullscreening it would likely require some diverging code paths to actually work everywhere, but Wayland should be a breeze. Having worked on SDL's Wayland backend I'd say that most of the difficulty came from impedance mismatches with preexisting SDL APIs, so if you design your thing from scratch all you really need to deal with there are the protocol bits - which you could just mostly hardcode and automatically get rid of most of libwayland's complexity that deals with protocol extensions and their XML descriptions.
For this reason, I have added framebuffer support in https://exaequos.com.