4

TTF_OpenFont() returns NULL

I have the same problem, TTF_OpenFont returns NULL and with an error.

    TTF_OpenFont("/absolute/path/to/SourceSansPro-Black.ttf", 25);
    std::cout << TTF_GetError() << std::endl;

And I get the "Couldn't load font file"

  • The .ttf chmod is 777
  • I tried running the program with root

I run out of ideas.

Community
  • 1
  • 1
Florius
  • 125
  • 1
  • 7

2 Answers2

5

Yes, I had initialized TTF.

The problem was that I (don't know how) was using the older SDL_TTF with the SDL 2.0

I downloaded the 2.0 TTF, compiled and linked it and now it works.

Florius
  • 125
  • 1
  • 7
  • For SDL 2.0 the TTF lib should be at least SDL2_ttf 2.0.12 as noted [here](http://stackoverflow.com/questions/20847668/sdl-ttf-cannot-find-sdl-h-but-main-cpp-can/20847799#20847799) – Michal Przybylowicz Jan 23 '14 at 14:08
  • Thank you! For me on Fedora 20, this meant rebuilding from an SRPM found in [this Bugzilla thread](https://bugzilla.redhat.com/show_bug.cgi?id=1034413) to get the `SDL2_ttf` and `SDL2_ttf-devel` RPMs. – Asherah Apr 13 '14 at 07:38
  • Just in case this helps anyone else - ***check your linker settings*** - I battled for an hour before I noticed `-lSDL_ttf` instead of `-lSDL2_ttf`. – SteJ Apr 12 '16 at 02:27
1

You can install SDL_TTF for SDL2 in Ubuntu using this: sudo apt-get install libsdl2-ttf-dev