# SDL without X?



## ProphetOfDoom (Aug 15, 2022)

Hi,
Is it possible to use SDL (Simple DirectMedia Layer) without X? Like how on MSDOS you could start a game from the command line without starting Windows first? I couldn’t find anything about this on the SDL forum.
Thanks.


----------



## kpedersen (Aug 15, 2022)

There is the `SDL_VIDEODRIVER` environment variable:

https://wiki.libsdl.org/FAQUsingSDL

I suppose `kmsdrm` will be the most useful for you?

If its only a frame buffer you need (i.e not the rest of SDL), I did a quick port of GNUboy gameboy emulator to run on libdrm directly. The code for a "dumb" DRM buffer isn't too fiddly if you want to pick parts out of that:

https://gitlab.com/osen/openbsd_drmfb_gnuboy/-/blob/main/src/sys/Screen.c


----------



## ProphetOfDoom (Aug 19, 2022)

Hi kpedersen, thanks very much for your reply I will get back to you soon things are a bit hectic right now...


----------



## ProphetOfDoom (Aug 19, 2022)

Hi kpedersen again.
So this probably comes under the banner of "idle speculation" at this stage... but I'll explain what I was thinking. I wanted to create a kind of Commodore 64/TempleOS -like environment where you boot into a minimal command prompt that lets you run BASIC commands, handled behind the scenes by SDL. Just basically a kind of programmer's playground, and you don't need to care about X or playing nicely with other graphical programs. I realise this is ambitious but I've already written a BASIC compiler and a debugger so I'm part of the way there. It would need to have the full functionality of SDL. I was just curious if SDL could do this. But yeah I was just thinking out loud really.


----------



## kpedersen (Aug 19, 2022)

AlexanderProphet said:


> I wanted to create a kind of Commodore 64/TempleOS -like environment where you boot into a minimal command prompt that lets you run BASIC commands, handled behind the scenes by SDL. Just basically a kind of programmer's playground, and you don't need to care about X or playing nicely with other graphical programs. I realise this is ambitious but I've already written a BASIC compiler and a debugger so I'm part of the way there. It would need to have the full functionality of SDL. I was just curious if SDL could do this. But yeah I was just thinking out loud really.


It is a cool idea, bringing back the simpler days of programming is a really nice goal. In many ways I feel SDL might be a bit overkill (especially SDL2). For example you don't really need an SDL_Renderer because it likely isn't accelerated anyway, so transformations (i.e rotate, scale) would either be emulated so much of SDL2 would be wasted. Instead dealing with a raw pixel buffer (with convenience functions) could be a simpler way.

I saw this a while back which could be along the same lines of thought:
https://archive.fosdem.org/2020/sch..._2020_nicolas_caramelli_linux_framebuffer.pdf

I did contact him but he seems mostly concerned with Linux-only at the moment. However libdrm or dumb framebuffers via fbcon with some small wrapping around them might provide a nicer setup for your BASIC compiler / platform. Admittedly I have more experience with OpenBSD than FreeBSD for this. Another option could be to bring in a refreshed version of FreeBSD's VGL:

https://www.freebsd.org/cgi/man.cgi?vgl

(This post became more like a ramble / dump of ideas, so apologies if it is quite jumbled!)


----------



## ProphetOfDoom (Oct 3, 2022)

Hi kpederson,
Apologies for my rudeness in not replying. I’m struggling with anxiety and depression - it’s not unusual for me to spend a week (or more) in bed.
I did read your message but felt I have nothing to add yet as I’ve yet to experiment with your original suggestion  (SDL_VIDEODRIVER). I will probably reply at some stage...


----------



## kpedersen (Oct 3, 2022)

AlexanderProphet said:


> Apologies for my rudeness in not replying


Hiya. Absolutely no problem. Not rude at all! Happy to discuss further once you have experimented.


----------



## sidetone (Oct 3, 2022)

I know Wayland and a basic compositor aren't what you're looking for, but it's the closet thing available in theory to what you asked on Unix-like. Some compositors aren't about a traditional desktop, some are a menu-screen and a direct choice to the game. x11-wm/gamescope is one for Steam games. So much can be done like that. SDL is supposed to be able to run on Wayland. Despite this, so much on Wayland still requires XWayland and X dependencies.

Maybe an SDL compositor on Wayland is lacking (at least on FreeBSD), which most of any program still depends on dependencies from an older standard.

Another way that resembles what you asked for, is to use the windowmanager of x11-wm/antiwm, which you'll run a command and the game runs on X. Using AntiWM isn't what you asked for, but it will give the same impression of what you asked for.





That's an example of AntiWM in low resolution with a graphical desktop animation played on it. The background is the actual terminal with output of the `ls` command displayed. desktop/hot-babe is in the foreground, run from the command line (which the command to run it may be obscured), which is typically a graphical desktop widget: that was run as an example to show a graphic run on a terminal. It only allows one video/graphical application to play at a time. AntiWM requires less dependencies than a traditional Window Manager, and this can be up and running quickly. You could get the functionality of running graphical games from DOS with this, yet with X behind the scenes.

Others have said that a Window Manager like that can be used to have separate text consoles for each screen for multi monitor setups, as normally that can't be done.

The other case of using images on the terminal is of applications that use Lua, which has been used for bootup screens on FreeBSD. That hasn't been used for video or animations.


----------

