[SDL] TTF_Font ( ¿forward declaration?)

Alvin alvinbeach at gmail.com
Tue Jun 19 07:42:44 PDT 2007


On Tuesday 19 June 2007 11:35:59 Zaka E-Lab wrote:
> TTF_Font *fuente = NULL;
> ...........
> fuente = TTF_RenderText_Blended(.........);
> ...........
> delete fuente;(

TTF_RenderText_Blended() returns a SDL_Surface* not a TTF_Font*.

You need to use (code snipped from SDL_ttf docs):

// load font.ttf at size 16 into font
TTF_Font *fuente;
fuente=TTF_OpenFont("font.ttf", 16);
if(!fuente) 
{
    printf("TTF_OpenFont: %s\n", TTF_GetError());
    // handle error
}

Then to render some text (again, snipped from SDL_ttf docs):

// Render some text in blended black to a new surface
// then blit to the upper left of the screen
// then free the text surface
//SDL_Surface *screen;
SDL_Color color={0,0,0};
SDL_Surface *text_surface = NULL;
....
text_surface=TTF_RenderText_Blended(fuente, "Hello World!",color);
if(!text_surface)
{
    //handle error here, perhaps print TTF_GetError at least
}
else
{
    SDL_BlitSurface(text_surface,NULL,screen,NULL);
    //perhaps we can reuse it, but I assume not for simplicity.
    SDL_FreeSurface(text_surface);
}

Alvin


More information about the SDL mailing list