How to render fonts and text with SDL2 efficiently?

前端 未结 2 867
旧巷少年郎
旧巷少年郎 2020-12-14 02:13

Saw this post here about using SDL_ttf to render text in a game. However that approach requires calling SDL_CreateTextureFromSurface(), along with the SDL_FreeSurface() and

2条回答
  •  时光取名叫无心
    2020-12-14 02:29

    Yes, creating textures every frame can affect performance. Also, rasterizing TrueType fonts to SDL_Surfaces (as SDL_ttf does) every frame can affect performance.

    I recommend SDL_FontCache (full disclosure: I'm the author). It uses SDL_ttf and caches the resulting glyphs in textures so you don't have to do it all yourself:
    https://github.com/grimfang4/SDL_FontCache

提交回复
热议问题