【发布时间】:2018-02-12 16:53:54
【问题描述】:
是否可以将绘制的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;
}
【问题讨论】: