Я обнаружил, что мне нужно установить ссылку на подходящую библиотеку 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;
}
Код: Выделить всё
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
2025-09-18 04:19 PM .
2025-09-18 02:59 PM ..
2025-09-18 04:24 PM 136,192 Project1.exe
2025-09-18 04:24 PM 3,641,344 Project1.pdb
2025-09-17 05:30 PM 1,437,696 sfml-audio-3.dll
2025-09-17 05:21 PM 3,455,488 sfml-audio-d-3.dll
2025-09-17 05:30 PM 1,077,248 sfml-graphics-3.dll
2025-09-17 05:21 PM 3,340,288 sfml-graphics-d-3.dll
2025-09-17 05:30 PM 155,136 sfml-network-3.dll
2025-09-17 05:21 PM 884,736 sfml-network-d-3.dll
2025-09-17 05:30 PM 72,704 sfml-system-3.dll
2025-09-17 05:21 PM 318,464 sfml-system-d-3.dll
2025-09-17 05:30 PM 155,136 sfml-window-3.dll
2025-09-17 05:21 PM 595,456 sfml-window-d-3.dll
2025-09-17 05:31 PM 18,444 Tuffy.ttf
13 File(s) 15,288,332 bytes
2 Dir(s) 276,891,336,704 bytes free
Failed to load font (failed to open file): No such file or directory
Provided path:
Absolute path:
c:\work\My\cpp_study\TEST_SFML\Project1\x64\Debug>
Как загрузить шрифт?
Версии:
- Microsoft Visual Studio Community 2022 (64-разрядная версия) — текущая версия 14.17.15 (сентябрь 2025 г.)
- SFML 3.0.2
Подробнее здесь: https://stackoverflow.com/questions/797 ... -load-font