SDL_TTF Problems (Can't display text)

pb2ya
Unregistered
 
Post: #1
I've been trying to get this to work for a couple hours now, I'm following a number of SDL tutorials at the moment and can't seem to get past the simple hurdle of displaying a block of text. The weird thing is, I get no compiler warnings or errors when trying to compile the following code, but the screen ends up blank with no text displayed. I've tried adding a colored background to see if I'm just printing black text on a black screen, and I've also tried this with a couple different fonts.

So, I start a new SDL application in XCode (this is written in C), include SDL_ttf.h, link the SDL_ttf framework to the compiler, and proceed to add the following code:

Code:
SDL_Surface *message = NULL;

TTF_Font *font;
SDL_Color color = { 255, 255, 255 };
font = TTF_OpenFont( "lazy.ttf", 28 );

message = TTF_RenderText_Solid( font, "blah blah blah", color );

SDL_BlitSurface( message, NULL, screen, NULL );
SDL_Flip(screen);

Normally, this compiles and runs without trouble, but when I test each one of the statements individually, the line that renders the text is the one that ends up returning. What am I doing wrong? I'm completely stumped as of what's not working here, so tell me if I'm just shooting vague questions.
Quote this message in a reply
Member
Posts: 111
Joined: 2002.06
Post: #2
I would guess SDL_ttf isn't finding the font file lazy.ttf. I haven't used SDL_ttf, but I know SDL sets the working directory to the directory above the application bundle. If you have the lazy.ttf file in the Resources folder of your application bundle, you must call TTF_OpenFont() with the following code to open the file:

Code:
font = TTF_OpenFont("AppTitle.app/Contents/Resources/lazy.ttf", 28 );

Mark Szymczyk
http://www.meandmark.com
Quote this message in a reply
pb2ya
Unregistered
 
Post: #3
That doesn't seem to be working either... I'm using an older version of XCode (being on 10.3), and all of the resources I need work fine just being the in the "build" directory.
Quote this message in a reply
AaronA
Unregistered
 
Post: #4
Quote:font = TTF_OpenFont("AppTitle.app/Contents/Resources/lazy.ttf", 28 );
Make sure lazy.ttf is beeing accessed localy and its infact, lazy.ttf.

Quote:SDL_Surface *message = NULL;

TTF_Font *font;
SDL_Color color = { 255, 255, 255 };
font = TTF_OpenFont( "lazy.ttf", 28 );

message = TTF_RenderText_Solid( font, "blah blah blah", color );

SDL_BlitSurface( message, NULL, screen, NULL );
SDL_Flip(screen);

Try...

Code:
SDL_Surface *message = NULL;

TTF_Font *font;
SDL_Color color = { 255, 255, 255 };
font = TTF_OpenFont( "lazy.ttf", 28 );
message = TTF_RenderText_Solid( font, "blah blah blah", color );

SDL_Rect dest;
dest.x = 10;
dest.y = 10;
SDL_BlitSurface(message, NULL, screen, &dest);

SDL_Flip(screen);
Quote this message in a reply
Nibbie
Posts: 2
Joined: 2008.09
Post: #5
Sorry for resurrecting this thread from the dead, but it seemed unresolved and there's another possible solution.

I was having this same problem, and I solved it by including this in my graphics initialization:
TTF_Init();

With SDL_ttf properly initialized, my "couldn't open font.ttf" errors went away.

(I'm sure the OP has already solved their issue, but hopefully this will help others in the same situation.)
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Display Lists and Obj. File Loader Problems merrill541 0 2,003 Oct 17, 2008 06:42 PM
Last Post: merrill541
  SDL_ttf Jonas 3 2,834 Jun 5, 2008 06:43 AM
Last Post: Jonas
  Another way to display Unicode text thanh thuy 0 2,068 Feb 16, 2006 07:24 PM
Last Post: thanh thuy
  SDL_ttf Legie 6 5,043 Jul 26, 2005 01:17 PM
Last Post: scriabin
  Added SDL_ttf framework to project - can't include headers matticus 3 4,387 Oct 15, 2004 01:14 PM
Last Post: OneSadCookie