C++ SFML 库代码不适用于绘制文本

C++ SFML library code not working for drawing a text

我对 draw() 在我的 SFML 项目中不起作用感到非常沮丧。我的编译器没有给出任何错误,我的眼睛没有发现任何错误(作为参考,我使用的是官方教程)。问题是当 window 加载时它不绘制任何东西。它只是保持白色 window,其中没有任何文本。 可能是哪里出了问题?

#include <SFML/Graphics.hpp>

int main() {

sf::RenderWindow window(sf::VideoMode(800,600), "Trying to make a game");
sf::Font font;
if (!font.loadFromFile("arial.ttf"))
{
    //error
}

sf::Text text;
text.setFont(font);
text.setString("Hello, World!");
text.setCharacterSize(50);
text.setColor(sf::Color::Red);
text.setPosition(10, 50);

while (window.isOpen())
{
    sf::Event event;
    while (window.pollEvent(event))
    {
        if (event.type == sf::Event::Closed)
            window.close();
    }
}

window.clear();
window.draw(text);
window.display();
return 0;
}

您正在关闭 window before 绘制文本...