Contents
Can you render text directly with SDL _ TTF?
Don’t render text directly with SDL_TTF. It’s not efficient, at all. Use SDL_TTF to generate a glyph atlas, or use a tool like AngelCode BMFont. You can get glyph metrics (Width, Height, x advance, etc.) using TTF_LineSkip to find the vertical distance, and TTF_GlyphMetrics. At this point, you can render text yourself.
Can a texture affect the performance of SDL?
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).
Are there any new functions in SDL2 TTF?
SDL2_TTF has new functions including TTF_RenderText_Blended_Wrapped, where you can specify a wraplength parameter, which specifies in pixels the maximal width ( the surface width also gets padded to this value ). It also supports newline characters, and will break the line at characters.
Do you need to copy lines into temporary SDL buffers?
There’s no need to copy whole lines into temporary SDL buffers which are copied to your real output. It’s harder, but worth it. Easy toy render APIs are just that: toys.
How does the blended mode work in SDL?
The color to render the text in. Pixels are blended between transparent and this color to draw the antialiased glyphs. Render the LATIN1 encoded text using font with fg color onto a new surface, using the Blended mode (see section Blended ). The caller (you!) is responsible for freeing any returned surface.
How to render simple monospace fonts in SDL?
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).