SDL_ttf
TTF_RenderText_Blended
SDL_Surface *TTF_RenderText_Blended(TTF_Font *font, const char *text, SDL_Color fg) SDL_Surface *TTF_RenderUTF8_Blended(TTF_Font *font, const char *text, SDL_Color fg) SDL_Surface *TTF_RenderUNICODE_Blended(TTF_Font *font, const Uint16 *text, SDL_Color fg);
font
Font to render the text with. Must be non-NULL.
text
- A NULL-terminated string in corresponding encoding.
fg
- The color to render the text in. This becomes colormap index 1.
This family of functions will render the given text with the given font with fg color onto a new surface with transparent background. The Blended mode. This is the slowest but most beautiful.
Returns: a pointer to a new SDL_Surface. NULL is returned on errors.
int DrawText(SDL_Surface* screen, TTF_Font* font, const char* text)
{
SDL_Color black = {0,0,0};
SDL_Surface *text_surface;
text_surface = TTF_RenderText_Blended(font, text, black);
if (text_surface != NULL)
{
SDL_BlitSurface(text_surface, NULL, screen, NULL);
SDL_FreeSurface(text_surface);
return 1;
}
else
{
// report error
return 0;
}
}This example draws the text in the upper let corner of the given surface.
