Jump to content
  • Advertisement
Sign in to follow this  
HawkAgent

SDL and text output

This topic is 4113 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

If I'm is using SDL api's to show output on the screen, is it possible to render text on screen with methods other then
TTF_Font *TTF_OpenFont(const char *file, int ptsize)
SDL_Surface *TTF_RenderText_Solid(TTF_Font *font, const char *text, SDL_Color fg)
It seems with these methods I can only load fonts that are in the same directory as the .exe file, ie.:
TTF_Font *font = NULL;
font = TTF_OpenFont( "myfont.ttf", 28 ); //this works, "myfont.tff" is in same directory as the .exe

TTF_Font *font2 = NULL;
font2 = TTF_OpenFont( "C:\Windows\Fonts\myfont.ttf", 28 ); //same "myfont.tff", now in the default windows font folder, doesn't work...
I want to able to load fonts from other directories, any help?

Share this post


Link to post
Share on other sites
Advertisement
It's because the path is invalid. As it is now, "\W", "\f" and "\m" in "C:\Windows\Fonts\myfont.ttf" are interpreted as escape sequences. You should use either "C:\\Windows\\..." or "C:/Windows/...".

Share this post


Link to post
Share on other sites
I think you need to use 2 slashes, like c:\\windows\\fonts\\myfont.ttf. Or something along the lines of that.

Share this post


Link to post
Share on other sites
Oh I see, thanks!
Is it possible to do something like "%SYSTEMROOT%\\Fonts\\myfont.TTF" (I tried this, but didn't work) ?

Share this post


Link to post
Share on other sites
Quote:
Original post by HawkAgent
Oh I see, thanks!
Is it possible to do something like "%SYSTEMROOT%\\Fonts\\myfont.TTF" (I tried this, but didn't work) ?


No. You'll have to do the substitution by yourself. I'm pretty sure there is an API to get strings out of symbolic path names. Because explorer is the Windows shell, I'd bet it's in the Windows explorer API. Not being a Windows user though, I can't help you with that. Sorry.

Share this post


Link to post
Share on other sites
Just as a suggestion, you might want to put #ifdef statements around your system-specific code if you're trying to make it work on multiple platforms.

Like this:
[source="c"]
#ifdef WIN32
font=TTF_OpenFont("c:/windows/fonts/myfont.ttf",28);
#else
font=TTF_OpenFont("myfont.ttf",28);
#endif



When and if you start trying to port to Linux or MacOSX or others you'll be glad you did.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!