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: 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:

creates a window with a bmp image filling it, waits 2 secs then quits.
# gcc -o lesson01 lesson01.cpp -lSDL

multiple images in window.
# g++ -o lesson02 lesson02.cpp -lSDL
# ./lesson02

# g++ -o lesson03 lesson03.cpp -lSDL -lSDL_image
# ./lesson03

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

overlay two images, with a transparent colour in top image.
# g++ -o lesson05 lesson05.cpp -lSDL -lSDL_image

sprite sheets
# g++ -o lesson06 lesson06.cpp -lSDL -lSDL_image
# ./lesson06

truetype fonts
link to official SDL_ttf documentation tarball:
# 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:

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:

...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.

SDL_ttf fixed!!! See later blog post:

Next stop, Lesson 08!    

Tags: easy