SDL_ttf - 字体目录/字体在哪里?

时间:2013-02-28 21:09:35

标签: c++ opengl sdl true-type-fonts sdl-ttf

我一直在用SDL和OpenGL(用C ++编写),并决定在我的游戏中加入一些文字。

我已经遵循了一些教程,但我总是得到同样的错误:“找不到.ttf”我确定之前已经问过,但是你应该把字体放在哪里,你应该写些什么TTF_OpenFont的第一个参数?这是迄今为止的TTF部分。

if (TTF_Init() != 0)
{
    cerr << "TTF_Init() Failed: " << TTF_GetError() << endl;
    SDL_Quit();
    exit(1);
}

TTF_Font *font;
font = TTF_OpenFont("FreeSans.ttf", 24);
if (font == NULL)
{
    cerr << "TTF_OpenFont() Failed: " << TTF_GetError() << endl; // <-- This the error report
    TTF_Quit();
    SDL_Quit();
    exit(1);
}


SDL_Surface *text;
SDL_Color text_color = {255, 255, 255};
text = TTF_RenderText_Solid(font, "BLAH, BLAH, BLAH!", text_color);

1 个答案:

答案 0 :(得分:5)

您可以将文件放在任何您想要的位置。但你必须告诉TTF_OpenFont()它在哪里。

使用

 TTF_OpenFont("FreeSans.ttf", 24);

您说FreeSans.ttf文件位于程序的working directory中。


如果您愿意,可以将文件放在任何地方。 例如:

 TTF_OpenFont("D:\\My Folder\\FreeSans.ttf", 24);

TTF_OpenFont("D:/My Folder/FreeSans.ttf", 24);
相关问题