Peter's SDL question

Peter's SDL question

Postby bzt » 31 Aug 2021, 18:29

Hi Peter,

I've seen your question here, but for some reasons I can't log in (I've turned JS on). Anyway, here's my answer:

PeterX {l Wrote}:I have narrowed down my options to (a) framebuffer device, (b) SDL1.2 and (c) SDL2.
(a) I can't find thorough information on how to use the FB. Do I need to read the linux kernel sources for this?
You have to open the framebuffer device /dev/fb* and using mmap you can map it into your application's address space. I wouldn't recommend this though, because not all drivers provide the same device interface unfortunately, and it can also conflict with X and Wayland drivers.
http://linux-fbdev.sourceforge.net/
https://tldp.org/HOWTO/Framebuffer-HOWTO/

PeterX {l Wrote}:(b) and (c) Is SDL without X possible?
Yes, absolutely. SDL is designed in a way to hide the lower layer from your app, it could use Wayland too for example without your app knowing (or caring about). Furthermore SDL is cross-platform, meaning it also works with Win GDI or Mac Cocoa for example, your source will be the same, no modifications needed. It is also possible to use SDL in a way that you open a full screen window which will return an SDL surface directly mapped to the hardware's framebuffer.

PeterX {l Wrote}:What are the differences between 1.2 and 2?
SDL1.2 isn't maintained really any more (the library is, but you'll have trouble with some distro's packages). I'd recommend SDL2. You can use an SDL1.2 like surface with SDL2, but it can also provide you a hardware accelerated renderer (which is a 2D renderer by default, but SDL also supports 3D rendering if you want).

PeterX {l Wrote}:Do I need to buy a book to learn coding for SDL?
I don't think so. There are very good tutorials on the net, and the SDL documentation is pretty good.
https://wiki.libsdl.org/Tutorials
https://wiki.libsdl.org/CategoryAPI

On a function reference example, take a look at SDL_CreateWindowAndRenderer. Explains all the arguments, and there's example code on how to use it. SDL is one of the best documented libraries I've encountered.

Cheers,
bzt
User avatar
bzt
 
Posts: 106
Joined: 23 May 2021, 21:46

Re: Peter's SDL question

Postby PeterX » 31 Aug 2021, 18:34

Cool! Thanks for the infos.

Greetings
Peter
User avatar
PeterX
 
Posts: 147
Joined: 01 Oct 2020, 21:44

Re: Peter's SDL question

Postby bzt » 01 Sep 2021, 14:40

PeterX {l Wrote}:According to the documentation I've read, it seemed that I should open the framebuffer device with fopen(). But from the source of that nice, small library it should be open() instead.
It doesn't matter, fopen() and open() both works (the former is just a portability wrapper around the latter). The difference is, fopen() returns a pointer to a struct (FILE*), while open() returns an integer (file descriptor). If you want to use mapping for fast access using mmap(), you'll need the file descriptor, but you can get that from the FILE struct as well with "fileno(f)".

Cheers,
bzt

ps: I'm terribly sorry that I answer here and not on the new forum.
User avatar
bzt
 
Posts: 106
Joined: 23 May 2021, 21:46

Re: Peter's SDL question

Postby PeterX » 01 Sep 2021, 15:37

Thanks again. That was very helpful again.

Greetings
Peter
User avatar
PeterX
 
Posts: 147
Joined: 01 Oct 2020, 21:44

Re: Peter's SDL question

Postby Julius » 01 Sep 2021, 16:19

I am totally at a loss what might cause your login problems in the new forum. Seems to work without problems for everyone else.
“Reality is that which, when you stop believing in it, doesn’t go away.” - Philip K. Dick
User avatar
Julius
Community Moderator
 
Posts: 3147
Joined: 06 Dec 2009, 14:02

Re: Peter's SDL question

Postby freem » 01 Sep 2021, 17:28

Since I'm logged in... (linux) Framebuffers are not portable and have terrible performance (I know this by experience, I wrote a X-less application for last job), it's probably better to go with DRM/KMS, which have been adopted by e.g. the *BSDs.
You will also need a way to get input, I'd advise using libinput, which is rather easy.
As for text, the easier is probably to use PSF1 and PSF2 formats, freetype is not really what I'd call a clean library. Might also use the BDF format, but since it's text, it's harder to parse.
For png files, I found that libapng is cleaner than libpng.

Now, the most important is probably to share some links, so here we are:

http://betteros.org/tut/graphics1.php is the website I used to get a rough idea of how to code with framebuffers. It also contains stuff to write DRM/KMS code, but I have not tried it yet.
https://www.win.tue.nl/~aeb/linux/kbd/f ... ats-1.html is the reference for the PSF1 and PSF2 formats.

I'll let you do your homework for other links, I don't have much useful stuff for them.
freem
BN Moderator
 
Posts: 73
Joined: 18 May 2015, 19:38

Re: Peter's SDL question

Postby PeterX » 01 Sep 2021, 17:40

freem {l Wrote}:Since I'm logged in... (linux) Framebuffers are not portable and have terrible performance (I know this by experience, I wrote a X-less application for last job), it's probably better to go with DRM/KMS, which have been adopted by e.g. the *BSDs.
You will also need a way to get input, I'd advise using libinput, which is rather easy.
As for text, the easier is probably to use PSF1 and PSF2 formats, freetype is not really what I'd call a clean library. Might also use the BDF format, but since it's text, it's harder to parse.
For png files, I found that libapng is cleaner than libpng.

Now, the most important is probably to share some links, so here we are:

http://betteros.org/tut/graphics1.php is the website I used to get a rough idea of how to code with framebuffers. It also contains stuff to write DRM/KMS code, but I have not tried it yet.
https://www.win.tue.nl/~aeb/linux/kbd/f ... ats-1.html is the reference for the PSF1 and PSF2 formats.

I'll let you do your homework for other links, I don't have much useful stuff for them.

Thx, that contains several interesting advices and infos.
The most useful info for me is the first link (betteros.org/...).

I am not sure whether DRM uses X. Maybe I confuse that with DRI...

Greetings
Peter
User avatar
PeterX
 
Posts: 147
Joined: 01 Oct 2020, 21:44

Re: Peter's SDL question

Postby bzt » 01 Sep 2021, 18:51

Julius {l Wrote}:I am totally at a loss what might cause your login problems in the new forum. Seems to work without problems for everyone else.
Please don't make a big deal of this, it is more than likely this is an issue on my part and not an issue with the server / forum software (probably some overprotective firewall or adblocker rule or something like that.)

freem {l Wrote}:Since I'm logged in... (linux) Framebuffers are not portable and have terrible performance (I know this by experience, I wrote a X-less application for last job), it's probably better to go with DRM/KMS, which have been adopted by e.g. the *BSDs.
You will also need a way to get input, I'd advise using libinput, which is rather easy.
Agreed and agreed! Good advice!

freem {l Wrote}:As for text, the easier is probably to use PSF1 and PSF2 formats, freetype is not really what I'd call a clean library. Might also use the BDF format, but since it's text, it's harder to parse.
For PSF2, here's an extremely minimal implementation (less than 20 SLoC, link leads to C code, but also available in other languages like Go, Rust, Pascal, Ada etc.).

Otherwise you can use the dependency-free Scalable Screen Font (has a converter for both PSF and BDF formats). Besides bitmap fonts, supports vector and pixel fonts too. It is an stb-style, single C/C++ header implementation, very easy to integrate (works with Linux fb, SDL etc.)

freem {l Wrote}:For png files, I found that libapng is cleaner than libpng.
There's also LodePNG which is easier to use than libpng, but my favourite is stb_image.h (smaller and faster than the others, with simple API, single header library).

Cheers,
bzt
User avatar
bzt
 
Posts: 106
Joined: 23 May 2021, 21:46

Re: Peter's SDL question

Postby freem » 09 Sep 2021, 21:46

Nice links! I'll keep those (or rather, this post) in mind next time I start hacking a project. UI & text are really a pain in my ... . Those things are surprisingly hard to get done correctly with "simplicity".
freem
BN Moderator
 
Posts: 73
Joined: 18 May 2015, 19:38

Who is online

Users browsing this forum: No registered users and 1 guest