本文介绍了SDL_ttf - 字体目录/字体在哪里去?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在使用SDL和OpenGL(在C ++中),并决定向我的游戏中添加一些文本。

I've been noodling around with SDL and OpenGL (in C++), and decided to get some text into my game.

我已经遵循了几个教程,但我总是得到相同的错误:找不到.ttf我确定它以前被问过,但你应该放置的字体,你应该在TTF_OpenFont的第一个参数写什么?这是到目前为止的TTF部分。

I've followed a few tutorials, but I always get the same error: "Couldn't find .ttf" I'm sure it's been asked before, but where should you place the font, and what should you write in the TTF_OpenFont's first parameter? Here's the TTF part so far.

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("FreeSans.ttf", 24);

你说的FreeSans.ttf文件在。




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

You are saying the FreeSans.ttf file is in the working directory of the program.


If you want you can put the file anywhere.For example:

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

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

这篇关于SDL_ttf - 字体目录/字体在哪里去?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 12:18
查看更多