我实际上面临着一个我自己无法解决的问题,使用 SFML 我有一个单一的形状,并且我在每一帧 移动它,然后我画它。问题是,SFML 使用两个缓冲区,每个缓冲区(帧)上的轨迹都不相同,并且会产生奇怪的闪烁效果。
我需要你的知识,我是否应该找到另一种方法来做到这一点,比如我将扩展的形状数组。或者有没有办法跳过第二个缓冲区?将此缓冲区制作成一张纸,然后我塑造画笔。
sf::CircleShape circle;
//Init the circle (radius etc)
sf::Vector2f pos(0, 500);
while(!done)
{
pos.x += 1;
circle.setPosition(pos);
window.draw(circle);
window.display();
}
祝你度过愉快的一天。
最佳答案
你可以通过使用 sf::RenderTexture
来实现这一点,它充当后台缓冲区(单个缓冲区)来制作你的绘图,然后通过 sf::RenderWindow` 在屏幕上绘制它
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML art");
window.setVerticalSyncEnabled(true);
sf::RenderTexture target;
if (!target.create(window.getSize().x, window.getSize().y))
return -1;
target.clear(sf::Color::White);
target.display();
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
sf::CircleShape circle(5.f, 32u);
circle.setPosition(sf::Vector2f(sf::Mouse::getPosition(window)));
circle.setFillColor(sf::Color::Red);
target.draw(circle, sf::BlendNone);
target.display();
}
window.clear();
window.draw(sf::Sprite(target.getTexture()));
window.display();
}
}
关于c++ - 如何为生成艺术目的在单个缓冲区上绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33336272/