Well hello again.
It’s been quite a while since I’ve been on the mailing list, and since I’ve
used SDL.
I started back into both a few days ago, and was trying to write a font
class using SDL_ttf.
Now, from what I remember, in order to use SDL_ttf, I need to have FreeType
2.0 or later (which I’m using). I’ve downloaded the source code for 2.1.9 (I
believe that’s the version I got), and included the .lib into my project.
TTF_Init() doesn’t crap out on me when I call it, so that’s fine. But, when
I print out a string of text, it either displays garbage characters, or
nothing at all. Here’s the function from the font class:
void cFont::Print(SDL_Surface *pDest, int x, int y, SDL_Color FgColor, char
*szStr, …)
{
if (this->m_pFont)
{
SDL_Surface *pTextSurf = 0;
va_list args;
int length;
char *buffer;
// specify where to start searching for the arguments in the string
va_start(szStr, args);
// get the length of the string being displayed
// this won't actually parse the argument list
length = _vscprintf(szStr, args) + 1;
// allocate the buffer to store the correct amount of characters
buffer = (char*)malloc(length * sizeof(char));
memset(buffer, 0, sizeof(char) * length);
// render out the text
pTextSurf = TTF_RenderText_Blended(this->m_pFont, buffer, FgColor);
// now copy the text to the specified location on the pDest surface
SDL_Rect rc = { x, y, 500, 500 };
SDL_BlitSurface(pTextSurf, 0, pDest, &rc);
SDL_FreeSurface(pTextSurf);
free(buffer);
}
}
The font I’m using is the standard Arial.ttf from the Windows/Fonts folder
at 14pt… It’s quite perplexing, as I was able to get SDL_ttf to work the
last time I wrote an SDL app…
Kevin_________________________________________________________________
Powerful Parental Controls Let your child discover the best the Internet has
to offer.
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines
Start enjoying all the benefits of MSN? Premium right now and get the
first two months FREE*.