Weird things happening with SDL_ttf

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*.

By the looks of it, you don’t populate the allocated buffer with
anything but zeros. That could explain why you don’t get anything…

Kevin Fields wrote:> // 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);

Well, by gum, you’re right. Don’t I just feel like a moron now.
Hehe…
ThanksFrom: advantis@gmx.net (Uplink)
Reply-To: “A list for developers using the SDL library.
(includesSDL-announce)”
To: "A list for developers using the SDL library. (includes
SDL-announce)"
Subject: Re: [SDL] Weird things happening with SDL_ttf
Date: Sun, 03 Oct 2004 02:57:06 +0300

By the looks of it, you don’t populate the allocated buffer with anything
but zeros. That could explain why you don’t get anything…

Kevin Fields wrote:

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


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Take charge with a pop-up guard built on patented Microsoft? SmartScreen
Technology.
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*.

Well, putting the following after the memset still gives me garbage
characters.
vsprintf(buffer, szStr, args);

I even tried putting a literal string in the TTF_RenderText_Blended/Solid
function and it just spits out garbage.

I’m wondering whether I have a bad copy of SDL_ttf, or whether it’s
something going on with FreeType, or just my machine (this wouldn’t surprise
me in the least).

KevinFrom: @Kevin_Fields (Kevin Fields)
Reply-To: “A list for developers using the SDL library.
(includesSDL-announce)”
To: sdl at libsdl.org
Subject: Re: [SDL] Weird things happening with SDL_ttf
Date: Sun, 03 Oct 2004 00:45:03 -0300

Well, by gum, you’re right. Don’t I just feel like a moron now.
Hehe…
Thanks

From: advantis@gmx.net (Uplink)
Reply-To: “A list for developers using the SDL library.
(includesSDL-announce)”
To: "A list for developers using the SDL library. (includes
SDL-announce)"
Subject: Re: [SDL] Weird things happening with SDL_ttf
Date: Sun, 03 Oct 2004 02:57:06 +0300

By the looks of it, you don’t populate the allocated buffer with anything
but zeros. That could explain why you don’t get anything…

Kevin Fields wrote:

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


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Take charge with a pop-up guard built on patented Microsoft? SmartScreen
Technology.
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*.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


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*.

So, then, what’s “szStr” and what’s “args”? :slight_smile:

-bill!
bill at newbreedsoftware.com New Breed Software
http://www.newbreedsoftware.com/ Tux Paint 0.9.14 – Coming soon!On Sun, Oct 03, 2004 at 12:51:17AM -0300, Kevin Fields wrote:

Well, putting the following after the memset still gives me garbage
characters.
vsprintf(buffer, szStr, args);

Wow, 3 posts in a row… pats himself on the back
I figured out what I did wrong… geez, I really feel like a dolt today.

I had the va_start(szStr, args) backwards… it’s supposed to be
va_start(args, szStr).
Silly me… this hasn’t been such a good day. sigh

KevinFrom: @Kevin_Fields (Kevin Fields)
Reply-To: “A list for developers using the SDL library.
(includesSDL-announce)”
To: sdl at libsdl.org
Subject: Re: [SDL] Weird things happening with SDL_ttf
Date: Sun, 03 Oct 2004 00:51:17 -0300

Well, putting the following after the memset still gives me garbage
characters.
vsprintf(buffer, szStr, args);

I even tried putting a literal string in the TTF_RenderText_Blended/Solid
function and it just spits out garbage.

I’m wondering whether I have a bad copy of SDL_ttf, or whether it’s
something going on with FreeType, or just my machine (this wouldn’t surprise
me in the least).

Kevin

From: @Kevin_Fields (Kevin Fields)
Reply-To: “A list for developers using the SDL library.
(includesSDL-announce)”
To: sdl at libsdl.org
Subject: Re: [SDL] Weird things happening with SDL_ttf
Date: Sun, 03 Oct 2004 00:45:03 -0300

Well, by gum, you’re right. Don’t I just feel like a moron now.
Hehe…
Thanks

From: advantis@gmx.net (Uplink)
Reply-To: “A list for developers using the SDL library.
(includesSDL-announce)”
To: "A list for developers using the SDL library. (includes
SDL-announce)"
Subject: Re: [SDL] Weird things happening with SDL_ttf
Date: Sun, 03 Oct 2004 02:57:06 +0300

By the looks of it, you don’t populate the allocated buffer with anything
but zeros. That could explain why you don’t get anything…

Kevin Fields wrote:

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


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Take charge with a pop-up guard built on patented Microsoft? SmartScreen
Technology.
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*.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


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*.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


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*.

szStr is the string with the format specifiers in it, and the args is the
arguments that get inserted into the string. I grew rather fond of writing
my print functions that way, but I haven’t done any programming in the past
few months that required me to use that functionality, so I kinda forgot the
order in which things go. hehe…

See what C# is doing to me? ;)From: nbs@sonic.net (Bill Kendrick)
Reply-To: “A list for developers using the SDL library.
(includesSDL-announce)”
To: "A list for developers using the SDL library. (includes
SDL-announce)"
Subject: Re: [SDL] Weird things happening with SDL_ttf
Date: Sat, 2 Oct 2004 20:55:48 -0700

On Sun, Oct 03, 2004 at 12:51:17AM -0300, Kevin Fields wrote:

Well, putting the following after the memset still gives me garbage
characters.
vsprintf(buffer, szStr, args);

So, then, what’s “szStr” and what’s “args”? :slight_smile:

-bill!
bill at newbreedsoftware.com New Breed Software
http://www.newbreedsoftware.com/ Tux Paint 0.9.14 – Coming soon!


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Scan and help eliminate destructive viruses from your inbound and outbound
e-mail and attachments.
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*.