[Обновление]
Я обнаружил, что мне нужно установить ссылку на подходящую библиотеку SFML, в частности на отладочную/выпускную версию SFML. Этого не было сделано в моем коде, моя вина.
например,
Используйте sfml-system-3.dll для режима выпуска и используйте sfml-system-d-3.dll для отладки
[Оригинал]
Я пытаюсь загрузить шрифт TTF в приложение SFML:
#include
#include
int main()
{
// Create the main window
float i;
i = -100;
sf::RenderWindow window(sf::VideoMode({ 600, 600 }),
"My Test",
sf::Style::Titlebar | sf::Style::Close,
sf::State::Windowed,
sf::ContextSettings{ 0 /* depthBits */, 8 /* stencilBits */ });
// Create a circle shape
sf::CircleShape circle(50.f); // Radius of 50 pixels
circle.setFillColor(sf::Color(255, 0, 0, 150)); // Set the fill color to green
sf::Font font;
system("dir");
if (!font.openFromFile("c:/work/My/cpp_study/TEST_SFML/Project1/x64/Debug/Tuffy.ttf")) {
exit(0);
}
// Main game loop
while (window.isOpen())
{
// Process events
while (const std::optional event = window.pollEvent())
{
// Window closed: exit
if (event->is())
{
window.close();
break;
}
}
// Clear screen
window.clear();
circle.setPosition({ i, 250.f }); // Position the circle
if (i < 600)
{
i += 0.1;
}
else
{
i = -100;
}
// Draw the circle
window.draw(circle);
// Update the window
window.display();
}
return 0;
}
... и что бы я ни делал, у меня ничего не получается:
[Обновление] Я обнаружил, что мне нужно установить ссылку на подходящую библиотеку SFML, в частности на отладочную/выпускную версию SFML. Этого не было сделано в моем коде, моя вина. например, Используйте sfml-system-3.dll для режима выпуска и используйте sfml-system-d-3.dll для отладки [Оригинал] Я пытаюсь загрузить шрифт TTF в приложение SFML: [code]#include #include
int main() { // Create the main window float i; i = -100; sf::RenderWindow window(sf::VideoMode({ 600, 600 }), "My Test", sf::Style::Titlebar | sf::Style::Close, sf::State::Windowed, sf::ContextSettings{ 0 /* depthBits */, 8 /* stencilBits */ });
// Create a circle shape sf::CircleShape circle(50.f); // Radius of 50 pixels circle.setFillColor(sf::Color(255, 0, 0, 150)); // Set the fill color to green
sf::Font font; system("dir"); if (!font.openFromFile("c:/work/My/cpp_study/TEST_SFML/Project1/x64/Debug/Tuffy.ttf")) { exit(0); }
// Main game loop while (window.isOpen()) { // Process events
while (const std::optional event = window.pollEvent()) { // Window closed: exit if (event->is()) { window.close(); break; } } // Clear screen window.clear(); circle.setPosition({ i, 250.f }); // Position the circle if (i < 600) { i += 0.1; } else { i = -100; } // Draw the circle window.draw(circle);
// Update the window window.display(); }
return 0; } [/code] ... и что бы я ни делал, у меня ничего не получается: [code]c:\work\My\cpp_study\TEST_SFML\Project1\x64\Debug>Project1.exe Volume in drive C has no label. Volume Serial Number is 5C05-A155
Directory of c:\work\My\cpp_study\TEST_SFML\Project1\x64\Debug
c:\work\My\cpp_study\TEST_SFML\Project1\x64\Debug> [/code] Я даже пытался указать абсолютный путь, проверяя, что путь правильный (см. system("dir")), но это не помогло. Как загрузить шрифт? Версии: [list] [*]Microsoft Visual Studio Community 2022 (64-разрядная версия) — текущая версия 14.17.15 (сентябрь 2025 г.) [*]SFML 3.0.2 [/list]