c++ - SFML 图形在窗口中绘制纹理 - 黑屏

标签 c++ sfml

我刚刚尝试编写一个国际象棋引擎,对我来说重要的是我获得了游戏的漂亮视觉表示。我试图在 Visual Studio 项目中实现代码 - 问题是程序只显示黑屏而不是我加载的纹理。

我的代码如下:

#include <SFML/Graphics.hpp>
#include <time.h>
using namespace sf;

int main(){

    RenderWindow window(VideoMode(1000, 1000), "MattseChess!");

    Texture t1;
    t1.loadFromFile("images/board.png");
    Sprite s(t1);

    while (window.isOpen())
    {
        Event e;

        while (window.pollEvent(e)) {

            if (e.type == Event::Closed)
                window.close();
    //Draw
            window.clear();
            window.draw(s);
            window.display();
        }
    }

    return 0;
}

你知道我做错了什么吗?

最佳答案

确保将您的绘图代码放在外部您的事件循环中。否则,您只会在发生某些事件(例如光标移动)时进行绘制。

关于c++ - SFML 图形在窗口中绘制纹理 - 黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47711797/

相关文章:

c++ - 多个内部分配 - 它是如何工作的?

c++ - 有什么办法可以找出哪个线程收到了最后的输入?

c++ - 为什么在sfml中加载字体时出错

c++ - 用 sfml 计算 FPS

c++ - 对 vtable SFML Android 的 undefined reference

c++ - 自定义对象的 vector

c++ - 消息处理函数中的 afx_msg 术语

c++ - 并行 for 比顺序 for 慢

c++ - 在 Visual Studio 2010 中使用 SFML

c++ - 检查共享行、列、对角线的最有效方法?