site  contact  subhomenews

Started learning SDL v1.2 came to a stop

January 16, 2023 — BarryK

As posted yesterday, I'm a glutton for punishment sometimes. gui_engine looks good:

https://bkhome.org/news/202301/guiengine-runs-in-initrd.html

...it is just using a console font, but to make it really useful, want a font with full UTF-8 support. So, would be good to bring in the 'libsdl-ttf' package. So, with this in mind, started going through some SDL v1.2 tutorials. Here are my notes:

lesson01
--------
https://lazyfoo.net/SDL_tutorials/lesson01/index2.php
creates a window with a bmp image filling it, waits 2 secs then quits.
# gcc -o lesson01 lesson01.cpp -lSDL

lesson02
--------
https://lazyfoo.net/SDL_tutorials/lesson02/index.php
multiple images in window.
# g++ -o lesson02 lesson02.cpp -lSDL
# ./lesson02

lesson03
--------
https://lazyfoo.net/SDL_tutorials/lesson03/linux/cli/index.php
# g++ -o lesson03 lesson03.cpp -lSDL -lSDL_image
# ./lesson03

lesson04
--------
https://lazyfoo.net/SDL_tutorials/lesson04/index.php
event loop: click close-box top-right of window, correctly exits.
# g++ -o lesson04 lesson04.cpp -lSDL -lSDL_image
# ./lesson04

lesson05
--------
https://lazyfoo.net/SDL_tutorials/lesson05/index.php
overlay two images, with a transparent colour in top image.
# g++ -o lesson05 lesson05.cpp -lSDL -lSDL_image

lesson06
--------
https://lazyfoo.net/SDL_tutorials/lesson06/index.php
sprite sheets
# g++ -o lesson06 lesson06.cpp -lSDL -lSDL_image
# ./lesson06

lesson07
--------
https://lazyfoo.net/SDL_tutorials/lesson07/index.php
truetype fonts
link to official SDL_ttf documentation tarball:
https://osdn.net/projects/sfnet_libsdl/downloads/SDL%20documentation/1.2/SDL_ttf_html.tar.gz/
# g++ -o lesson07 lesson07.cpp -lSDL -lSDL_image -lSDL_ttf -lfreetype
# ./lesson07
ERROR loading font
modified the code:

//Open the font
//font = TTF_OpenFont( "lazy.ttf", 28 );
font = TTF_OpenFont( "/usr/share/fonts/TTF/DejaVuSans.ttf", 28 );

//If there was an error in loading the font
if( font == NULL )
{
printf("ERROR loading font\n");
return false;
}

downloaded SDL_ttf-2.0.11, applied some patches from debian, compiled:
# ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --build=x86_64-pc-linux-gnu
# make
# new2dir make install
...nup, same error

...I put that "printf()" to confirm the "TTF_OpenFont()" is failing. Tried a different font, with full path, no go. Recompiled SDL_ff-2.0.11 package, with latest patches from Debian, still no go. Huh, what to do next?

Very frustrating. In the last couple of days, I mentioned checking out other GUI toolkits that will work with the Linux framebuffer, either directly of via SDL v1.2. Recollecting, I think there was only one that could talk directly to the framebuffer; LVGL.

I like LVGL, and have looked at it in 2018:

https://bkhome.org/news/201808/littlevgl-evaluation-part-3.html

Yes, the mouse works, unfortunately not the keyboard. Like many of these GUI toolkits targeting embedded systems, they are touch-oriented, or for keypads on specific devices. I raised the issue of the keyboard in a PC:

https://github.com/lvgl/lvgl/issues/377

...tentatively posted some code showing how the keyboard and mice can be detected. But I lacked the knowledge how to integrate this into LVGL, so hoped someone would pick it up. But here we are in 2023 and no one has.

Yesterday I looked around the LVGL source code, no, it is very obscure, cannot see how to bring in PC keyboard support. It would take considerable time, to study how it all hangs together. So, unfortunately, that's another GUI toolkit that has to be abandoned.

Back on the subject of SDL, early versions of LVGL have a method of using fonts, such as DejaVuSans, converted to bitmaps. That code could be ported to gui_engine, to avoid SDL_ttf.

2023-01-17:
SDL_ttf fixed!!! See later blog post:

https://bkhome.org/news/202301/back-in-business-with-sdlttf.html

Next stop, Lesson 08!    

Tags: easy