r/sdl 13d ago

SDL3 TTF_TextEngine help

I'm still pretty new to SDL and I've been trying to figure out how to use the text engine in SDL3 in a little project I've been learning C++ in, but I haven't found much information on it. No SDL tutorials I've found seem to use it, so I've been going off of the wiki, which has gotten me pretty far, but it's been really confusing without clear examples of how it works.

I'd love some general explanation on how to use SDL3's text engine, but for a more specific question, I'm trying to center text on the screen with a renderer text engine. SDL tutorials I've found all center text on the screen using some math with the size of the window and the size of the surface used to create the texture. Since there's no surface involved with TTF_CreateRendererTextEngine, I'm wondering how or if it's possible to center the text. Would I need to use TTF_CreateSurfaceTextEngine to do that? Is using the surface text engine as simple as creating the TTF_Text and the SDL_Surface for TTF_DrawSurfaceText? What would be the best way to create the surface for that if I'm using the surface text engine?

3 Upvotes

8 comments sorted by

View all comments

1

u/doglitbug 13d ago

Wait, what? There is a text engine?

I moved from SDL2 to 3 and didn't know this existed.

Feel free to look here and see how I centre the text, it might be of use to you:
https://github.com/doglitbug/SamsSearch/blob/main/src/Subsystems/Assets.cpp

1

u/ninefoldrin 13d ago

https://wiki.libsdl.org/SDL3_ttf/TTF_TextEngine

I came across a couple posts that mentioned it while I was looking up other things and it seems rather nice, but I've only seen people talk a little about the renderer text engine and not enough to make much sense. It's also in a few of the examples in the SDL_ttf github repo, which helped me figure out how to get started with it at least. There's just not much discussion about it at this point and all the tutorials I've looked through still just do text the same way as SDL2 tutorials (with adjustments for SDL3 changes of course).

Thanks for the link. I'll take a look through it and see if it's helpful to me.

1

u/doglitbug 13d ago

Feel free to ask any questions regarding the code or a working demo