- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我一直在研究 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/
我在通过 SDL_ttf 在 OpenGL 中显示文本时遇到问题。我编写了 LoadFont() 函数,它加载字体并制作 OpenGL 纹理。 int LoadFont( char *name, GL
如何在代码块中设置 sdl_ttf?我已经阅读了lazyfoo关于向sdl添加新库的教程,并已成功向其中添加了sdl_image。然而,ttf 拒绝工作。我已经下载了文件,将头文件放入 sdl 文件夹
我发布了我认为相关的部分代码。我正在尝试通过 SDL_TTF 为我的菜单绘制一些文本。每次单击按钮时,我都会从服务器获取一串字符。类似于“I1P1I2P1I3P1I4P1I5P1I6P1I7P1I8P
我是编程初学者,我在使用 SDL_TTF 调用的函数时遇到了麻烦: SDL_Surface *TTF_RenderText_Solid(TTF_Font *字体,const char *text,SD
我正在尝试使用 OpenGL 和 SDL,使用 SDL_ttf 将文本渲染到纹理,但代码渲染垃圾。 我的“渲染到纹理代码”: GLuint textToTexture(std::string & te
我遇到了 SDL_ttf 的问题,无论我用 TTF_RenderText_Solid 函数做什么,它都拒绝呈现任何文本。我的源代码在这个问题中有点重(大约 150 行之类)所以我将它们的链接放在 Pa
我正在使用 SDL_ttf,但在 mingw32 中,我下载所有内容并尝试以下程序 #include #include "SDL_ttf.h" #include using namespace s
我使用 SDL 进行开发已有一段时间了,但我认为我需要另一个挑战。所以我决定使用 SDL_TTF 在屏幕上绘制一些文本。 我尝试在 0,0 处渲染文本,但它有点低于屏幕边框。所以这意味着它没有在 0,
我正在尝试用 C++ 制作一个 openGL 游戏,并且我正在尝试实现一个文本系统,为此,我正在尝试使用 SDL_ttf。 我已经在另一个项目中使用了 SDL_ttf,但使用了另一个 api,所以我编
我正在使用 codeblocks 并且我已经安装了 librares 并且那里没有错误...当我构建项目时,编译器说它没有错误,当我运行它时,它只是弹出一个窗口,里面只有黑色,它应该会出现“Hola
所以,我正在开发一个命令提示符游戏,现在我从小处着手。我已经掌握了打印速度较慢的文本系统的基础知识,但我遇到了一个我不确定如何解决的问题。 基本上;文本会拉伸(stretch)以适合预定义的框: 预定
有没有办法在 SDL_TFF 中使用默认系统字体,而无需编写特定于平台的代码?目前我只使用 GNU FreeFont's 之一, 但我希望能够使用默认的系统字体。 最佳答案 那么,什么是“默认系统字体
当一串文本的长度超过 300 时,我希望它换行并继续。我读到这就是您的做法,但它不起作用 - 它只是延长了文本。 如何实现? const char* message = "example text t
前几天我问了一个问题,关于使用 SDL 渲染 TTF 字体,并被指向 SDL_TTFL 我已经尝试使用 SDL_TTF 库,但我得到的只是屏幕上的垃圾 我已经包含了我的着色器,这对于这个程序来说非常简
在我的游戏中,当“时间”处于事件状态时,它总是会在 5 个“小时”后崩溃。当它运行时,它工作正常,直到它开始显示不正确的时间(原因不明)并且它会在 5 个“小时”后由于段错误而崩溃。这很奇怪,因为以前
在病毒迫使我重置为出厂状态后,我一直试图在我的计算机上设置 SDL。让 SDL 在我的 IDE CodeBlocks 上运行很容易,但设置扩展库就没那么容易了。 CodeBlocks 识别库的存在,但
我是 OpenGL 的初学者,我创建了一个使用 SDL_TTF 在 OpenGL 中写入文本的函数。这是我的函数的代码: #define WINDOW_WIDTH 832 #define WINDOW
我一直在研究 SDL 和 OpenGL(在 C++ 中),并决定在我的游戏中添加一些文本。 我已经学习了一些教程,但我总是得到同样的错误:“找不到 .ttf”我确定之前有人问过它,但是你应该把字体放在
这是一个例子: 下面是相应的代码: TTF_Font *Sans = TTF_OpenFont("resources/fonts/lato/Lato-Semibold.ttf", 36); i
我有C语言代码,可以使用Linux中的SDL_ttf库在屏幕上显示文本。 TTF_Font *font; font = TTF_OpenFont("FreeSans.ttf", 20);
我是一名优秀的程序员,十分优秀!