高效地使用SDL2渲染字体和文本 [英] Rendering fonts and text with SDL2 efficiently
问题描述
创建纹理(可能随后不得不将它们发送到GPU)每一帧都会对我的表现产生重大影响?
如果用SDL_ttf只用我的整个渲染字符集来创建一个纹理,然后从这里自己逐个字符地更新呢?
$ b
编辑:我正在寻找仅用美英(简单的ASCII)渲染简单的等宽字体。
https://github.com/grimfang4/SDL_FontCache
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 SDL_DestroyTexture() every single frame.
Is creating textures (and probably subsequently having to send them to the GPU) every frame something that can significally impact my performance?
would it be wiser to use SDL_ttf only to create a texture with my whole rendered charset and then to blit from there myself, character by character?
Edit: I'm looking to render simple monospace fonts in US-English (basic ASCII) only.
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
这篇关于高效地使用SDL2渲染字体和文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!