This is a sample library which allows you to use TrueType fonts in your SDL applications. It comes with an example program "showfont" which displays an example string for a given TrueType font file.
Questions tagged [sdl-ttf]
208 questions
29
votes
2 answers
How to render fonts and text with SDL2 efficiently?
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…

introiboad
- 997
- 1
- 11
- 18
19
votes
2 answers
Using SDL_ttf with OpenGL
I'm using OpenGL and SDL to create a window in my program.
How do I use SDL_ttf with an OpenGL window?
For example I want to load a font and render some text. I want to draw the text using an SDL OpenGL surface.

Khedesh
- 207
- 1
- 2
- 4
9
votes
2 answers
How to do line-breaks and line-wrapping with SDL-TTF?
I just started using SDL2_ttf. I've figured out how to get some text on the screen with TTF_RenderText_Blended, but how do can I get it to do line-breaks and automatic wrapping?
It doesn't seem to support \n; it just creates a space instead of…

mpen
- 272,448
- 266
- 850
- 1,236
7
votes
1 answer
Displaying text with SDL TTF with SDL2 and OpenGL
I'm trying to display text using SDL2 TTF and OpenGL. A weird texture appears in the window, it's got the right size and the right position but you can't see any letters.
I've tried using the SDL_CreateRGBSurface() thinking that it might be a…

Monica
- 91
- 1
- 6
7
votes
2 answers
sdl ttf_rendertext_blended fails randomly
EDIT: Even that the problem still exists, I haven't been able to reproduce this frequently enough to examine it closer. See more info at the end of the question.
I started to develop a game, and I am currently writing basic library for it. I'm…

MaKo
- 746
- 3
- 11
7
votes
3 answers
TTF_OpenFont() returns NULL
Here are the facts: I am using codeblocks on Ubuntu. I have installed SDL and SDL_ttf and have included and linked them successfully. I want to render text to the screen of the font, FreeSerif.
Here is the problem: When the program gets to the…

biscuit
- 85
- 1
- 1
- 6
6
votes
1 answer
SDL2_TTF on Ubuntu: /usr/bin/ld: cannot find -lSDL2_ttf
I've looked at several possible solutions to try to fix this, but I'm still having the following issue with drawing text with SDL_ttf and SDL2.
julian@julian-linux:~/Documents/SDL/Font Demo/pt2$ make
g++ texttest.cpp -w -lSDL2 -lSDL2_ttf…

Julian Goddard
- 431
- 1
- 4
- 10
6
votes
2 answers
Is SDL2_ttf incapable of rendering characters that are longer than two bytes?
I'm switching from SFML to SDL2 in my program, and I started using SDL2_ttf to render text in UTF-8 format. I use the function TTF_RenderUTF8_Solid. I noticed that some characters are not rendered correctly anymore. One example is '' (U+1F70D). I…

Michał Brzozowski
- 419
- 5
- 11
6
votes
1 answer
SDL not rendering truetype font
I'm not entirely sure this is the best place for this, but I can't think of anywhere better
I've "made" a low resolution font. (bonus points if you know where it's actually from)
The font works fine in gedit:
However, when trying to render the font…

LordAro
- 1,269
- 3
- 18
- 35
5
votes
2 answers
Status of NPOT textures in OpenGL today
I'm currently writing a game that uses 2D OpenGL output under sdl, and I'm trying to load text using SDL_ttf. However I have to pad the text with blank pixels as it appears that plain OpenGL doesn't support non-power of two textures. I've heard that…

Sudarshan S
- 1,235
- 2
- 16
- 25
5
votes
1 answer
How do find out the width and height of the text without using surface in SDL2?
I wanted to create a separate function where I could just send a string and it will render the text appropriately so that I didn't need to copy-paste same stuff. The function I came up with is in the following.
void renderText(SDL_Renderer*…

3N4N
- 570
- 5
- 21
5
votes
2 answers
SDL_TTF draws garbage
I asked a question the other day, about rendering TTF fonts using SDL, and was pointed towards SDL_TTFL I've tried using the SDL_TTF library, but All I'm getting is garbage on screen
I have included my shaders, which are very simple for this…

Will P
- 192
- 1
- 9
4
votes
1 answer
How do I render high quality monochrome text with SDL2_TTF?
I'm writing a game with old school low resolution graphics. I'm using SDL2_TTF to render monochrome text but it doesn't seem to be hinted properly. I set the hinting with TTF_SetFontHinting(font, TTF_HINTING_MONO) and rendered the text with all…

Indiana Kernick
- 5,041
- 2
- 20
- 50
4
votes
1 answer
SDL TTF - Line wrapping & changing height of wrapped lines?
I've been programming a small text adventure game using SDL2 recently and have come across an issue with line wrapping. I am using TTF_RenderText_Blended_Wrapped() to render my strings, and this gives me some nicely wrapped lines. But The line…

Jacob H
- 864
- 1
- 10
- 25
4
votes
2 answers
TTF_OpenFont returning NULL
TTF_OpenFont() returns NULL
I have the same problem, TTF_OpenFont returns NULL and with an error.
TTF_OpenFont("/absolute/path/to/SourceSansPro-Black.ttf", 25);
std::cout << TTF_GetError() << std::endl;
And I get the "Couldn't load font…

Florius
- 125
- 1
- 7