Discussion:
SDL_ttf
Coleman Nitroy
2004-04-16 04:08:26 UTC
Permalink
Documentation for SDL_ttf seems a it lacking so I am stabbing the the
dark here, and from the demo and documentation I was able to scrap
together this for initializing SDL_ttf, but it crashes and burns
every-time:

[Code]

TTF_Font *font
char *filename

// This works
if( TTF_Init() == -1 ) {
fprintf(stderr, "Unable to initialize SDL_TTF: %s\n", TTF_GetError());
return 1;
}

// This is where it burns
filename = FreeMono.ttf";
font = TTF_OpenFont(filename, 9);
if( font == NULL ) {
fprintf(stderr, "Unable to open default TTF font: %s\n",
TTF_GetError());
return 1;
}

[/Code]

---
Coleman Nitroy
nitroy.com/cole
Mike Frysinger
2004-04-16 06:23:52 UTC
Permalink
Post by Coleman Nitroy
// This is where it burns
filename = FreeMono.ttf";
i assume the lack of leading " is a typo in the e-mail ...
Post by Coleman Nitroy
font = TTF_OpenFont(filename, 9);
is the ttf in the same directory you ran the test app from ?
-mike
Vandoorine Aurelien
2004-04-16 06:41:16 UTC
Permalink
I think you got the good point.

I've disvoered some month ago, that TTF_Font did not return NULL or do a
godd work if the file did not exist.

Example from my debug log, when I have specified in my configuration file a
font file that did not exist :

--- 2150 [DEBUG]ADDING FONT data/fonts/nadiéa.TTF (52) to the List
--- Fatal signal: Segmentation Fault (SDL Parachute Deployed)

The thing is to add a personal check for font existance by default because
TTF_OpenFont seems to not do it.

Oh and if you're planning a linux version, do not use TTF_RenderText_Solid,
because this function did not work on linux so I'm using
SDL_RenderText_Shaded and then set the colorkey of the surface. This is not
perfect but this is a work around.

Wedge

-----Message d'origine-----
De : sdl-***@libsdl.org [mailto:sdl-***@libsdl.org] De la part de Mike
Frysinger
Envoyé : vendredi 16 avril 2004 08:24
À : ***@libsdl.org
Objet : Re: [SDL] SDL_ttf
Post by Coleman Nitroy
// This is where it burns
filename = FreeMono.ttf";
i assume the lack of leading " is a typo in the e-mail ...
Post by Coleman Nitroy
font = TTF_OpenFont(filename, 9);
is the ttf in the same directory you ran the test app from ?
-mike
Coleman Nitroy
2004-04-16 11:47:48 UTC
Permalink
Post by Mike Frysinger
is the ttf in the same directory you ran the test app from ?
I am Developing in MacOSX, which can be a bit annoying when it comes
to which directory the app is actually run from. I will check for the
files existence before trying to open it then. Is this going to get
fixed in a new version of SDL_ttf?

---
Coleman Nitroy
nitroy.com/cole
Coleman Nitroy
2004-04-16 12:22:30 UTC
Permalink
Post by Mike Frysinger
is the ttf in the same directory you ran the test app from ?
I tested for the files existence with PHYSFS and I am 100% sure that
the file exists, I even tried giving it an explicit path
(/home/me/project/file.ttf) and it still crashes and burns, could this
be a OSX issue? I do not have access to my linux box because I am in
the middle of a move right now. Could it also be a font issue, would it
crash if I try to open a font at a size it could not handle? I have
tried two different fonts, and will try more, but it seems futile.

---
Coleman Nitroy
nitroy.com/cole
Mike Frysinger
2004-04-16 16:59:46 UTC
Permalink
Post by Coleman Nitroy
Post by Mike Frysinger
is the ttf in the same directory you ran the test app from ?
I tested for the files existence with PHYSFS and I am 100% sure that
the file exists, I even tried giving it an explicit path
(/home/me/project/file.ttf) and it still crashes and burns, could this
be a OSX issue? I do not have access to my linux box because I am in
the middle of a move right now. Could it also be a font issue, would it
crash if I try to open a font at a size it could not handle? I have
tried two different fonts, and will try more, but it seems futile.
when you say 'crashes and burns' i assume you mean like 'segfault' ?

what does `gdb` have to say about the whole thing ?
-mike
Coleman Nitroy
2004-04-16 18:06:43 UTC
Permalink
Post by Mike Frysinger
when you say 'crashes and burns' i assume you mean like 'segfault' ?
Yes, segfault, i've given up the idea of using SDL_ttf and gone with
the much smaller and simpler SFont.

---
Coleman Nitroy
nitroy.com/cole
David Bishop
2004-04-19 14:22:28 UTC
Permalink
It's been a while, but the last time I tried to use SDL_ttf on my OSX machine,
I had the same problem. That was with 10.2 (and probably >6 months ago), so
things may have changed, but basically it didn't work.
Post by Coleman Nitroy
Post by Mike Frysinger
when you say 'crashes and burns' i assume you mean like 'segfault' ?
Yes, segfault, i've given up the idea of using SDL_ttf and gone with
the much smaller and simpler SFont.
---
Coleman Nitroy
nitroy.com/cole
_______________________________________________
SDL mailing list
http://www.libsdl.org/mailman/listinfo/sdl
Bob Pendleton
2004-04-19 15:18:10 UTC
Permalink
Post by David Bishop
It's been a while, but the last time I tried to use SDL_ttf on my OSX machine,
I had the same problem. That was with 10.2 (and probably >6 months ago), so
things may have changed, but basically it didn't work.
Post by Coleman Nitroy
Post by Mike Frysinger
when you say 'crashes and burns' i assume you mean like 'segfault' ?
Yes, segfault, i've given up the idea of using SDL_ttf and gone with
the much smaller and simpler SFont.
I used SDL_ttf extensively on Redhat 7, 8, and 9 and now use it on
Debian. My students have used it on Mac OS 10+ and Windows 2k & XP. I've
never seen an SDL_ttf failure that wasn't due to a coding error on the
part of the programmer. OTOH, the version of FreeType that ships with RH
has all the patented parts turned off (for obvious reasons) so you can
get some really bad looking text from fonts that depend on those
features.

SDL_ttf just works and it works well.

Bob Pendleton
Post by David Bishop
Post by Coleman Nitroy
---
Coleman Nitroy
nitroy.com/cole
_______________________________________________
SDL mailing list
http://www.libsdl.org/mailman/listinfo/sdl
_______________________________________________
SDL mailing list
http://www.libsdl.org/mailman/listinfo/sdl
--
+---------------------------------------+
+ Bob Pendleton: writer and programmer. +
+ email: ***@Pendleton.com +
+ web: www.GameProgrammer.com +
+---------------------------------------+
David Bishop
2004-04-19 16:36:24 UTC
Permalink
Post by Bob Pendleton
Post by David Bishop
It's been a while, but the last time I tried to use SDL_ttf on my OSX
machine, I had the same problem. That was with 10.2 (and probably >6
months ago), so things may have changed, but basically it didn't work.
Post by Coleman Nitroy
Post by Mike Frysinger
when you say 'crashes and burns' i assume you mean like 'segfault' ?
Yes, segfault, i've given up the idea of using SDL_ttf and gone with
the much smaller and simpler SFont.
I used SDL_ttf extensively on Redhat 7, 8, and 9 and now use it on
Debian. My students have used it on Mac OS 10+ and Windows 2k & XP. I've
never seen an SDL_ttf failure that wasn't due to a coding error on the
part of the programmer. OTOH, the version of FreeType that ships with RH
has all the patented parts turned off (for obvious reasons) so you can
get some really bad looking text from fonts that depend on those
features.
SDL_ttf just works and it works well.
To be clear, SDL_ttf works perfectly on every linux machine I've used it. I
just was unable to get it working on OSX. Admittedly it may have been
(probably was?) my fault, due to misconfiguring something, like using the sdl
package vs. installing from source into /usr/[lib|include], or something.
But it definetly didn't work. Maybe I'll try again tonight, see if it's
gotten better with 10.3 and the newest sdl.

D.A.Bishop
Coleman Nitroy
2004-04-20 04:22:12 UTC
Permalink
Post by Bob Pendleton
I used SDL_ttf extensively on Redhat 7, 8, and 9 and now use it on
Debian. My students have used it on Mac OS 10+ and Windows 2k & XP. I've
never seen an SDL_ttf failure that wasn't due to a coding error on the
part of the programmer. OTOH, the version of FreeType that ships with RH
has all the patented parts turned off (for obvious reasons) so you can
get some really bad looking text from fonts that depend on those
features.
Well, with 10.3 and the latest version of SDL_ttf, it does not work, my
code works perfect in linux (tested just recently) and I even tried a
example program, something is weird with SDL_ttf on osx, SDL_ttf does
have some bugs that relate to indirectly, like the problem of when an
error occurs loading a font it does not return null it just crashes
your program, which seems a little fishy to be honest.
Post by Bob Pendleton
SDL_ttf just works and it works well.
Not on OSX with the current version, something is b0rked or f0rked.

---
Coleman Nitroy
nitroy.com/cole

Matt Wilson
2004-04-16 07:04:01 UTC
Permalink
Post by Coleman Nitroy
Documentation for SDL_ttf seems a it lacking so I am stabbing the the
dark here, and from the demo and documentation I was able to scrap
together this for initializing SDL_ttf, but it crashes and burns
[Code]
TTF_Font *font
char *filename
// This works
if( TTF_Init() == -1 ) {
fprintf(stderr, "Unable to initialize SDL_TTF: %s\n", TTF_GetError());
return 1;
}
// This is where it burns
filename = FreeMono.ttf";
font = TTF_OpenFont(filename, 9);
if( font == NULL ) {
fprintf(stderr, "Unable to open default TTF font: %s\n",
TTF_GetError());
return 1;
}
[/Code]
Really? The following code works absolutely fine on my machine;

----- 8< -----
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>

int
main ( void )
{
TTF_Font *font;
char *filename;

// This works
if ( TTF_Init() == -1 )
{
fprintf ( stderr, "Unable to initialize SDL_TTF: %s\n",
TTF_GetError () );
return 1;
}

// This is where it burns
filename = "timesi.ttf";
font = TTF_OpenFont ( filename, 9 );

if ( font == NULL )
{
fprintf ( stderr, "Unable to open default TTF font: %s\n",
TTF_GetError () );
return 1;
}

TTF_CloseFont ( font );
TTF_Quit ();

return 0;
}
----- 8< -----

Compiled with;

gcc -O2 -Wall -lSDL -lSDL_ttf -o test test.c

I'm using SDL 1.2.7, ttf version 2.0.6 and gcc version 3.3.3 on Gentoo.
The timesi.ttf font I used is from the corefonts package available from
http://corefonts.sourceforge.net/

HTH,

Matt

--
http://www.mattsscripts.co.uk/
- A great source for free CGI and stuff

It is one of the superstitions of the human mind to have imagined that
virginity could be a virtue.
-- Voltaire
Loading...