SDL_ttf

SDL_ttf > Functions > Render

TTF_RenderText_Shaded

SDL_Surface *TTF_RenderText_Shaded(TTF_Font *font, const char *text, SDL_Color fg, SDL_Color bg)
SDL_Surface *TTF_RenderUTF8_Shaded(TTF_Font *font, const char *text, SDL_Color fg, SDL_Color bg)
SDL_Surface *TTF_RenderUNICODE_Shaded(TTF_Font *font, const Uint16 *text, SDL_Color fg, SDL_Color bg);

font

text

fg

bg

This family of functions will render the given text with the given font with fg color onto a new surface with background color bg. The Shaded mode is used and this is the fastest.

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_Color white = {1,1,1};
    SDL_Surface *text_surface;
    
    text_surface = TTF_RenderText_Shaded(font, text, black, white); 
    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.

See Also

SDL_ttf_copy/Functions/Render/TTF_RenderText_Shaded (last edited 2009-02-25 23:12:18 by sign-4d0949c8)