• Advertisement
Sign in to follow this  

[SDL] Surface Width

This topic is 4383 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

SDL_Surface* temp; temp = TTF_RenderText_Solid( GameFont, text, colour); SDL_Rect desrc = {x,y,temp->w,temp->h}; Trying to get the width or height surface temp seems to crash the program. Anyone have any idea as to why?

Share this post


Link to post
Share on other sites
Advertisement
Aha. Right. It is NULL. Any idea why? The font variable was opened using

GameFont = TTF_OpenFont( "C:\\WINDOWS\\Fonts\\framd.ttf", 12 );

colour is passed as an SDL_Color structure, test

SDL_Color test = {255,255,255};

PutText is called as the following.

PutText(screen,100,100,"Testing",test);

[Edited by - Erondial on January 21, 2006 2:31:38 AM]

Share this post


Link to post
Share on other sites
First check that the file does exist in that location on your system, stupid question maybe but it's those solutions sometimes seem "too obvious" which actually fix it. You can also call SDL_GetError() which returns a char* string describing the last error to occur, if you check this directly after your call to TTF_OpenFont you should find out what went wrong.

Share this post


Link to post
Share on other sites
Also - are you initializing SDL_ttf?

I tried doing without one time and it worked, but didn't draw. The next time it didn't even initialize the surface.

Make sure that you are calling:

if (TTF_Init() == (-1))
// Handle Error
return 1;


Good luck!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement