gpt4 book ai didi

c++ - SFML 不会画任何东西?

转载 作者:行者123 更新时间:2023-11-28 06:11:53 25 4
gpt4 key购买 nike

我习惯于将 SDL 用于 C++,但我听说 SFML 更好,所以我尝试了一下。我试图渲染一个基本的 Sprite ,但没有成功。然后我试图将窗口清除为不同的颜色,但没有用。这是简单的代码,所以发生了什么? (由于某些原因间距有点偏差,抱歉)

#include <iostream>
#include "SFML/Graphics.hpp"


int main(){

sf::RenderWindow window(sf::VideoMode(640, 480), "It worked");

sf::Texture boxTexture;
boxTexture.loadFromFile("box.png");



while (window.isOpen()){

window.clear(sf::Color::Blue);

sf::CircleShape circle;
circle.setRadius(10);
circle.setPosition(1, 1);
circle.setFillColor(sf::Color::Blue);

window.draw(circle);

window.display();

}


return 0;
}

所有这一切只是显示一个白色屏幕...它不会将背景更改为蓝色。有谁知道我做错了什么?

最佳答案

就算不需要,也得把事件处理循环放上去。来自 SFML 教程页面:

A mistake that people often make is to forget the event loop, simply because they don't yet care about handling events (they use real-time inputs instead). Without an event loop, the window will become unresponsive. It is important to note that the event loop has two roles: in addition to providing events to the user, it gives the window a chance to process its internal events too, which is required so that it can react to move or resize user actions.

您可以了解更多关于 here 的信息

希望对你有帮助

关于c++ - SFML 不会画任何东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31105825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com