Rendering of subscript/superscript with SDL TTF?


Is there a way to render subscript/superscript text using SDL / SDLTTF?

Not that I am aware of.
SDL_TTF tends to maintain the KISS principle. The entire API is about 82 functions, and most of those are duplications for different types of strings.
I would say there’s maybe 20 functions that you might find interesting as a game dev. It’s up to you to make something interesting out of them.

These are the ones I tend to use, in alphabetical order:
β†’ SDL2_ttf/TTF_CloseFont - SDL Wiki
β†’ SDL2_ttf/TTF_FontHeight - SDL Wiki
β†’ SDL2_ttf/TTF_FontLineSkip - SDL Wiki
β†’ SDL2_ttf/TTF_GetFontStyle - SDL Wiki
β†’ SDL2_ttf/TTF_Init - SDL Wiki
β†’ SDL2_ttf/TTF_OpenFont - SDL Wiki
β†’ SDL2_ttf/TTF_Quit - SDL Wiki
β†’ SDL2_ttf/TTF_RenderUTF8_Blended - SDL Wiki
β†’ SDL2_ttf/TTF_RenderUTF8_Blended_Wrapped - SDL Wiki
β†’ SDL2_ttf/TTF_SetFontOutline - SDL Wiki
β†’ SDL2_ttf/TTF_SetFontSize - SDL Wiki
β†’ SDL2_ttf/TTF_SetFontStyle - SDL Wiki
β†’ SDL2_ttf/TTF_SetFontWrappedAlign - SDL Wiki
β†’ SDL2_ttf/TTF_SizeText - SDL Wiki

If you learn/remember how to use these, you can make a very interesting text engine.

Unicode supports some subscript and superscript characters so it should be possible to render them with SDL_ttf as long as the font file that you’re using supports them.

As GuildedDoughnut said, SDL_ttf is quite simple. It only contains the bare bone functionality so that you can implement more complex features yourself. Things like multi-line text and texts containing specific words that should be coloured or styled differently are not supported out of the box so you would have to implement it yourself with the basic functionality that SDL_ttf provides.

To support subscript and superscript for any character you would have to render that portion with a smaller font size and make sure to align it correctly. This also gives you more control over the exact size and alignment that you want for the subscripts and superscripts.

1 Like

Thank you all for the useful feedback! It makes sense that SDL TTF focuses on the basic functionality.

I found a solution for what I need using LaTeX for font/equation rendering instead. I don’t need real-time performance so this kluge will work for me.

1 Like