Creating effects with SDL_TTF

There has been this cool SFML example I love to look at and add to my projects for intros.
(For some reason I can’t post the link, so, on GitHub, the project is called “SfmlLogoAnimation” by Hapaxia. I’d run it if you have never seen it before! I just wanted to link to it to have someone get an idea of what it is doing.

It’s well done. Of course, it is possible, but does SDL_TTF have enough functionality to emulate this? It has been a while, but I think it just requires rotation, scaling, and moving. Using fonts in SDL has always been a bit weird. I’m wondering if it’s better to use a bitmap.

With all that said, does anyone know of a library that has some “font effects” for SDL2? I’m sure you could imagine cool font effects without me explaining.

Thanks, and have a nice weekend.

… The short answer is no, SDL_TTF is mainly only used to select color, font, font-size, and then render the text into a SDL_Surface that you usually convert into a SDL_Texture to benefit from the renderer API and the GPU. Besides a couple of other useful utility functions in TTF, it’s API is otherwise very spartan

We could help you implement those effects as needed, they’re pretty straight-foreward. Would you prefer to use SDL2 or SDL3?

The key to most of the effects (scale and motion) is to update the SDL_Rect that controls position and scale each frame. I find SDL3 even smoother to use here since it started to use floating point rectangles (SDL_FRect) as it’s base rendering rectangle.

Rotation is even simpler, just use this function SDL2/SDL_RenderCopyEx - SDL Wiki to draw, and modify the angle every update cycle. Note: it has been renamed to SDL_RenderTextureRotated in SDL3.

You’ll probably also want to do pathing (walk to position x,y over time). I like to calculate the number of steps and direction in my setDestination(x, y) function. The update function just has to add those steps each frame until the number of steps is reached.

If you insist on using SDL_TTF, rasterize the text at the final size, use it as an SDL_Texture, and get the same scaling effect by changing the destination rect’s size when drawing.

edit: Looking at the project here, they aren’t using a font library or any kind of actual font rendering at run-time. They’ve created the stylized “SFML” text as a graphic in Photoshop or whatever. The program loads that image and then just draws it one letter at a time. (check out SfmlLogoAnimation/sfml-logo-big.png)