How to draw solid text using sdl_ttf?

1.3k Views Asked by At

Here's an example:

SDL_Color textcol = {255, 255, 255};
SDL_Color backtextcol = {0, 0, 0};
SDL_Surface *mes = TTF_RenderText_Shaded(font, "The game has begun", textcol, backtextcol);
apply_surface(40, 40, mes, screen);
SDL_Flip(screen);

Thanks to that example, we draw a black rectangle with white letters. Is it possible to draw just white letters with black inside without the whole black rectangle?

1

There are 1 best solutions below

2
On

Yes it is possible. There are 3 main text-drawing functions in SDL_TTF:

TTF_RenderText_Solid - this one renders basic text(whitout background) and its fast, but its low-quality, and will look pixellated.

TTF_RenderText_Shaded - this one draws nice blended characters, but to a pre-defined background color

TTF_RenderText_Blended - this one draws a nice blended text, but it uses alpha-blending and its slow, but gives very nice results