There are still lots of great programs that only work with SDL 1.2.x and haven't been ported to SDL 2.x yet. There are also some operating systems that have not yet added a port of SDL 2.x and are still using SDL 1.2.x. SDL 1.2.x has support for Linux framebuffer which SDL 2.x does not offer. So, I've been finding myself supporting both SDL 1.2.x and SDL 2.x development environments. I am porting SDL 1.2.x programs that I commonly use so that they'll work with SDL 2.x as well. I have more than a half dozen converted but have a long way to go. A list of the SDL applications I use most frequently is here: https://lmemsm.dreamwidth.org/1855.html If you know of other ports of these programs to SDL 2.x, please share the information. A list of some of what I've already added SDL 2.x support to is available from here: http://www.distasis.com/cpp/lmports.htm

There are several helper libraries, I consistently use when working with SDL. I've been trying to pare it down to a minimum, but there are some I can't do without. These include sdl_ttf/sdl2_ttf, sdl_gfx/sdl2_gfx, sdl_image/sdl2_image and sdl_mixer/sdl2_mixer. I've been able to replace sdl_draw (which I did port to SDL 2 at one point) with sdl2_gfx in all the applications that used it as a dependency. I don't really use sdl_net. I tend to prefer to use programs offline and not be connected to the Internet just to have a program work. I haven't found a real need for sdl_audio. sdl_mixer seems to be good enough for most programs that provide audio.

Still, four libraries for SDL 1.2.15 and four for SDL 2.x can be a lot to keep up with. Also, the SDL 2 versions of these libraries have added some nice features like better Unicode/UTF-8 support for sdl2_ttf and support for newer image formats like svg in sdl2_image. They'd be nice to have in SDL 1.2.x.

When I was porting unicodeview to SDL 2.x, I needed to make some patches to sdl2_ttf similar to the ones needed for sdl_ttf just to get the unicodeview program to work. Neither sdl_ttf or sdl2_ttf has great support for UTF-32. sdl2_ttf does have better support for UTF-8 than sdl_ttf. So, I wanted to use the UTF-8 improvements in sdl2_ttf to improve Unicode and UTF-32 support in sdl_ttf. When I looked at the sdl2_ttf code and compared it to sdl_ttf, I realized they were similar enough one could still use sdl2_ttf with SDL 1.2.x. So, I decided to start using sdl2_ttf for both SDL 2.x and SDL 1.2.x builds.

sdl_gfx is an interesting case. sdl2_gfx only works with SDL 2.x. However, the developer has patches for sdl_gfx to get it work with SDL 2.x as well. I actually found one of my SDL 2.x programs worked faster using sdl_gfx instead of sdl2_gfx. So, I have versions of sdl_gfx for both SDL 1.2.15 and 2.x along with the option to use sdl2_gfx with SDL 2.x applications. The programs I've been patching that require one or the other or that used to need sdl_draw can now use any of those 3 options.

Since I've added support for both versions of SDL to other libraries, I decided it was time to look at the code of all the support libraries I use for SDL and see if I could combine the rest of them. I just completed patching SDL2_image so it will still work with SDL 1.2.x. I tried it with a build of picaxo and I can now view svg in the SDL 1.2.x build of picaxo not just the SDL 2.x build. Will also be looking at sdl_mixer.

I could just patch the programs to make these changes, but I find it easier to use my own build tools when trying to make modifications. So, I've ported all the libraries I'm working on to build with CDetect, GNU make, pkgconf and a shell (usually bash) build script. I no longer need the entire GNU autotools toolchain to build them. I don't need cmake either. I find it really easy using my own build system to switch between the SDL 1.x and SDL 2.x builds. I just need to change one define and generate the appropriate build script. I also find it easier to build these libraries for more unusual systems like Android using my own build tools.

I know there are still some systems out there that are using SDL 1.x in place of SDL 2.x especially those that do not have a SDL 2.x library port readily available. Most of the SDL 1.x helper libraries haven't been updated or had features added since development switched to a newer version of SDL. Would think updated versions of these libraries would be nice for systems still using SDL 1.x. If you're working on a system like that or are interested in porting software so that it works with different versions of SDL, contact me. It would be nice to combine efforts on a project like this.

If anyone wants to try some of these changes out, I will be uploading my patches and build scripts to:
http://www.distasis.com/cpp/lmports.htm
Along the lines of investigating portable C GUI libraries, I started looking at cross-platform library options for font rendering in C. This area is particularly useful if you're investigating creating your own GUI library or game library. I was most interested in the TrueType font rendering libraries and techniques. It was rather surprising to read just how difficult it is to get simple internationalized text to the screen especially using graphics libraries like OpenGL.

Here's what I've located. If you have other recommendations for C font rendering libraries, please let me know.


GUI library options like nuklear and nanovg use stb_truetype.h:
https://github.com/nothings/stb
They also use some kind of font stash, such as this one used with nanovg:
https://github.com/memononen/fontstash


Other GUI libraries use FreeType2.
https://www.freetype.org/

For instance, SDL2_ttf uses FreeType2.
https://www.libsdl.org/projects/SDL_ttf/

Allegro also has font libraries available that are based on FreeType2.
http://opensnc.sourceforge.net/alfont/mirror/

Here's one that works with Allegro or SDL:
http://kirill-kryukov.com/glyph-keeper/files.shtml


There are several font libraries for OpenGL, but there aren't many options written in C. Some are for older versions of OpenGL and some only work with later versions. Here's what I found so far:

https://github.com/rougier/freetype-gl
https://github.com/jtsiomb/libdrawtext
http://quesoglc.sourceforge.net/


Here's another C option that works with FreeType2 and embeds fonts in C programs:
https://github.com/chrisy/fontem


The most recommended technique used by OpenGL developers seems to be texture mapping. A texture can be used like a hash table to store various characters and other pixmaps that need to be rendered. An OpenGL function can draw a piece of the texture or update/change parts of it in memory without affecting performance too much. While software renderers have no real trouble copying or blending a bitmap graphic or pixmap, the newer OpenGL versions send the textures to the GPU for rendering. So utilizing a texture instead of bitmaps/pixmaps and minimizing the number of textures one is working with can improve performance.

I personally find it easier to render text with SDL. It handles copying and blending bitmaps (as an SDL_Surface) and offers a useful library (SDL_ttf) to do most of the work. SDL 2.x does use OpenGL underneath on some platforms, so some of the texture concepts used by OpenGL programmers might improve font rendering performance on some versions of SDL as well.

Freetype seems to be the library for working with TrueType fonts. SDL_ttf uses freetype to interpret the Truetype font format and create bitmaps/pixmaps to represent characters (converting them from vector format to bitmap/pixmap format). I found working with SDL_ttf a lot more user-friendly than trying to use Freetype directly.

Another viable option is stb_truetype.h. The license for this software is definitely an advantage. However, from what I've read the rendering still isn't quite as good as Freetype. I look forward to testing this out on my own at some point.

At this point, I'm still investigating SDL_ttf, stb_truetype.h and OpenGL texture mapping. A combination of these might be just what's needed in a font rendering design for a cross-platform GUI library.

Know of some other font rendering options that work well for Truetype fonts or have a better way to get fonts to the screen, I'd love to hear about it?

July 2025

S M T W T F S
  12345
67891011 12
13141516171819
20212223242526
2728293031  

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 15th, 2025 11:09 pm
Powered by Dreamwidth Studios