【发布时间】:2015-09-17 22:14:28
【问题描述】:
sf::RenderWindow window(sf::VideoMode(800, 600), "CALENDAR");
sf::Font font;
if (!font.loadFromFile("arial.ttf"))
std::cout << "no\n";
sf::Text text1;
text1.setFont(font);
text1.setCharacterSize(30);
text1.setColor(sf::Color::Black);
text1.setStyle(sf::Text::Regular);
text1.setString("ttestst");
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type){
case sf::Event::Closed:
window.close();
}
}
window.clear(sf::Color::White);
window.draw(text1);
window.display();
}
此代码没有在屏幕上显示文本,也没有加载字体,我不知道该怎么做,感谢任何帮助。
【问题讨论】:
-
会不会是你使用的字体路径不对?尝试使用绝对路径 - 从 Windows 上的 C:/ 或 osx/linux 上的 /
-
不走运,“C:\Coding\Fonts\Arial.ttf”什么也没做 :(
-
字体文件加载成功了吗?
-
你在使用任何 IDE 吗?即在 Code::Blocks 中,当您从 IDE 执行字体文件时,您必须将字体文件放在根项目目录中,而不是放在它所在的 bin 中。