gpt4 book ai didi

c++ - SDL_ttf - 字体目录/字体去哪儿了?

转载 作者:搜寻专家 更新时间:2023-10-31 00:16:47 27 4
gpt4 key购买 nike

我一直在研究 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);

最佳答案

您可以将文件放在任何您想要的地方。但是你得告诉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);

关于c++ - SDL_ttf - 字体目录/字体去哪儿了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15145683/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com