Advertisement

TTF_SizeText [solved]

Started by December 21, 2004 12:07 PM
7 comments, last by Gaiiden 20 years, 2 months ago
I was under the impression that this returned the size of the text without you having to render it yourself. In other words it rendered the text for you and then told you the dimensions of the rendered surface. I was using it thus:

int iWidth, iHeight;
TTF_SizeText(pFont, "T", &iWidth, &iHeight);
This was to get the height of the font. Except if I call this function before I render the text to a surface myself, I get some huge number like 738426. I've also tried TTF_FontHieght but that returns the same largish number. I tried looking at the docs but TTF_SizeText isn't even listed and from the description of TTF_FontHeight I shouldn't have to have rendered the text already or something. I'm going to keep looking at it but if anyone has any ideas...

Drew Sikora
Executive Producer
GameDev.net

I had pretty much the same problem, after tearing my hair out through lack of decent documentation I rolled my own which used TTF_Glyph metrics and added the widths of each character in the string.
Advertisement
Funny, it seems to work fine for me. FreeType 2.1.9 + SDL_ttf 2.0.6 (+ mods necessary to get SDL_ttf to compile with FreeType 2.1.9).
My first question is are you making a call to: TTF_Init() before you use the function? I was able to get crazy numbers when I did not call it, but when I did, everything was normal. Make sure to call TTF_Quit() at the end.

Second question would be, did you update all your SDL stuff since the 1.2.8 came out. If you use multiple IDEs, like 6 and 7, did you make sure to update both set of files? I ask because I forgot to do my VC7 and had probs till I remembered.

Other than that I would have no idea. Good luck.

Seems SDL_TTF has been updated along with SDL itself, I just checked the news page yesterday. I'll have to update and see what happens.

Drew Sikora
Executive Producer
GameDev.net

Quote:
Original post by Gaiiden
Seems SDL_TTF has been updated along with SDL itself, I just checked the news page yesterday. I'll have to update and see what happens.

Those updates just creep up on ya! [wink]
Advertisement
Dude I just realized that I've never linked to any FreeFont libs while using SDL_TTF. How weird is that? It says on the SDL_TTF page that I need FreeFont in order to use the library, so how was I able to render text and such when I wasn't linking to any FreeFont libraries?

Anyways, I downloaded FreeFont 2.1.9 and compiled the freetype219MT.lib - I assume I need the multithreaded lib for SDL. We'll see if this makes any difference

Drew Sikora
Executive Producer
GameDev.net

Quote:
Original post by Gaiiden
Dude I just realized that I've never linked to any FreeFont libs while using SDL_TTF. How weird is that? It says on the SDL_TTF page that I need FreeFont in order to use the library, so how was I able to render text and such when I wasn't linking to any FreeFont libraries?

Anyways, I downloaded FreeFont 2.1.9 and compiled the freetype219MT.lib - I assume I need the multithreaded lib for SDL. We'll see if this makes any difference



Hmmmm. I don't think that is correct? I have had to compile FreeFont and mine works fine. Can you post your code if possible, I'm sure the problem lies in there somewhere. I just used the FreeType here.

Are you doing Win32 development? If you are not - please disregard my post.
Aiighty, this code works:
if (TTF_WasInit()){	TTF_Font* pFont;	pFont = TTF_OpenFont("fonts/arial.ttf", 10);	int iWidth = 0, iHeight = 0;	TTF_SizeText(pFont, "T", &iWidth, &iHeight);	TTF_CloseFont(pFont);}

It returns a width of 6 and a height of 15. Yey.

I guess it's something screwy going on with my font pointer for my text object. When I use the object's font pointer (instead of loading the new one right then and there for test purposes) I get results that are completely off the chart.

My object manager can copy objects to create more than one instance, and when it does so the copied object uses some of the same pointers as the parent object (I use the Boost smart pointer lib to keep track of this). I'm guessing a text object's font pointer is getting messed up somehow when the object is copied. I'll have to investigate further, but at least it's good to know it works.

Drew Sikora
Executive Producer
GameDev.net

This topic is closed to new replies.

Advertisement