TTF_Font (?forward declaration?)

Hello all!!

I’m doing some stuff in SDL, and now I’ve started with SDL_ttf.

The thing is that I have these (is a lot of code to reproduce it as a
whole):
TTF_Font *fuente = NULL;

fuente = TTF_RenderText_Blended(…);

delete fuente;(

When a compile a got the next messages:(that one are in Spanish, so i’ll
try to translate it)

(SP)—>Dibujante.cpp:202: aviso: se detect? un posible problema en la
invocaci?n del operador delete:
(EN)—>Dibujante.cpp:202: warning: possible trouble detected in the use
of delete operator:

(SP)—>Dibujante.cpp:162: aviso: ?fuente? tiene un tipo de dato incompleto
(EN)—>Dibujante.cpp:162: warning: ‘fuente’ has an incomplete type data.

(EN)—>/usr/include/SDL/SDL_ttf.h:42: aviso: forward declaration of
?struct _TTF_Font?

(SP)—>Dibujante.cpp:202: nota: no se llamar? ni al destructor ni al
operador delete espec?fico de la clase, a?n si se declaran cuando se
defina la clase.
(EN)—>Dibujante.cpp:202: note: It will be called neither to the
destructor nor the specific delete operator of the class, even if they
are declared when the class is defined.

I’dont understand that messages cause i think that the use that I’m
doing of the type TTF_Font and the operator “delete” is “legal”. If
somebody can help me with that, I’ll appreciate it.

(Sorry for my English)

Thanks for advance.

Zaka.

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);
}

AlvinOn Tuesday 19 June 2007 11:35:59 Zaka E-Lab wrote:

TTF_Font *fuente = NULL;

fuente = TTF_RenderText_Blended(…);

delete fuente;(

Hello

OK, two things:

  1. TTF_RenderText_Blended returns a type SDL_Surface, not TTF_Font

  2. When finished with the surface, use SDL_FreeSurface to release the memory

TTF_Font *font;
SDL_Surface *text_surface;

if(TTF_Init()==-1) 
{
    printf_s("TTF_Init: %s\n", TTF_GetError());
}
font=TTF_OpenFont("images\\segoepr.ttf",52);
if(!font) 
{
    printf_s("TTF_OpenFont: %s\n", TTF_GetError());
// handle error
}


if(!(text_surface=TTF_RenderText_Blended(font,buffer,color))) 
{
    // ERROR!!
}
else
{
    SDL_BlitSurface(text_surface, NULL, dest, &rect);
    SDL_UpdateRect(dest,rect.x,rect.y,rect.w,rect.h);
    SDL_FreeSurface(text_surface);
}

TTF_CloseFont(font);

Hope this helps
Ed> ----- Original Message -----

From: shanatorio@gmail.com (Zakariae El-Abdelouarti Alouaret)
To: Lista SDL.
Sent: Tuesday, 19 June, 2007 3:35:59 PM
Subject: [SDL] TTF_Font (?forward declaration?)

Hello all!!

I’m doing some stuff in SDL, and now I’ve started with SDL_ttf.

The thing is that I have these (is a lot of code to reproduce it as a
whole):
TTF_Font *fuente = NULL;

fuente = TTF_RenderText_Blended(…);

delete fuente;(

When a compile a got the next messages:(that one are in Spanish, so i’ll
try to translate it)

(SP)—>Dibujante.cpp:202: aviso: se detect? un posible problema en la
invocaci?n del operador delete:
(EN)—>Dibujante.cpp:202: warning: possible trouble detected in the use
of delete operator:

(SP)—>Dibujante.cpp:162: aviso: ?fuente? tiene un tipo de dato incompleto
(EN)—>Dibujante.cpp:162: warning: ‘fuente’ has an incomplete type data.

(EN)—>/usr/include/SDL/SDL_ttf.h:42: aviso: forward declaration of
?struct _TTF_Font?

(SP)—>Dibujante.cpp:202: nota: no se llamar? ni al destructor ni al
operador delete espec?fico de la clase, a?n si se declaran cuando se
defina la clase.
(EN)—>Dibujante.cpp:202: note: It will be called neither to the
destructor nor the specific delete operator of the class, even if they
are declared when the class is defined.

I’dont understand that messages cause i think that the use that I’m
doing of the type TTF_Font and the operator “delete” is “legal”. If
somebody can help me with that, I’ll appreciate it.

(Sorry for my English)

Thanks for advance.

Zaka.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


New Yahoo! Mail is the ultimate force in competitive emailing. Find out more at the Yahoo! Mail Championships. Plus: play games and win prizes.
http://uk.rd.yahoo.com/evt=44106/*http://mail.yahoo.net/uk

Sorry!!!

I wanted to put that

TTF_Font *fuente = NULL;

SDL_Surface *superficie;

superficie = TTF_RenderText_Blended(…);

delete fuente;

Thanks again and sorry for the typesetter error!!!

Zaka.

Do not use delete. Instead, use SDL_FreeSurface() as in:
SDL_FreeSurface(superficie);

Also, I assume you use TTF_OpenFont() [or variant] to create fuente. If so, do
not use delete on fuente, use TTF_CloseFont() as in:
TTF_CloseFont(fuente);

AlvinOn Tuesday 19 June 2007 12:26:09 Zaka E-Lab wrote:

Sorry!!!

I wanted to put that

TTF_Font *fuente = NULL;

SDL_Surface *superficie;

superficie = TTF_RenderText_Blended(…);

delete fuente;

OK, I’ll be trying it.

Thanks.

Zaka.