是否可能将绘制的Drawable作为Texture(位图)获取?请问我该如何做?
我的尝试
我的尝试
我修改了绿色圆形示例。现在它真的被绘制成位图了...
但是它只是这样绘制:
我想要抗锯齿。
使用RenderWindow
类时,我能够通过传递ContextSettings
来设置抗锯齿。根据@Mario的建议,我需要RenderTexture
,但不幸的是我无法控制它的ContextSettings
。
@AlexG的建议
我创建了一个Context
,但我的编译器报错:my_test.cc:9:57: error: use of deleted function 'sf::Context::Context(const sf::Context&)'
。有什么替代方案吗?
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
int main()
{
sf::ContextSettings settings =
sf::ContextSettings(0, 0, 6);
sf::Context context = sf::Context(settings, 200, 200);
context.setActive(true);
sf::RenderWindow window(
sf::VideoMode(200, 200), "sfml test", sf::Style::Default,
settings
);
sf::RenderTexture cacheTexture;
if (!cacheTexture.create(200, 200)) return 0;
cacheTexture.setSmooth(true);
sf::CircleShape shape(100.f, 75);
shape.setFillColor(sf::Color::Green);
cacheTexture.setActive(true);
cacheTexture.draw(shape);
cacheTexture.setActive(false);
context.setActive(false);
sf::Sprite sprite = sf::Sprite(cacheTexture.getTexture());
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(sprite);
window.display();
}
return 0;
}
setActive()
之后获取上下文,然后调用getSettings()
以获取对该上下文设置的引用,并在那里进行修改。 - Alex GContextSettings
对象并进行交换?如果它是一个引用,您可能可以在指针处交换数据。 - Alex G