Hello all,
I work with/for the user
slotdev and I've only been using SFML and C++ for about a year now, so I'll apologize in advance for any silly mistakes, but here's my problem...
As we make games which need to be run at multiple different resolutions, depending on the hardware, we've previously had plenty of issues with artifacts appearing around sprites due to scaling. I came up for a fix for this by using an sf::RenderTexture as a sort of buffer which would essentially 'flatten' all the sprites at native resolution before scaling the RenderTexture and drawing it to the window. This worked perfectly in terms of removing the artifacts, but has causes some issues with sf::shapes...
We use sf::TriangleStrip to draw lines between winning symbol combinations, which could be at several positions in the window. Initially any section of the line which wasn't horizontal/vertical would look jagged, so we set antialiasing on in the window's contextsettings which solved that problem, however, now the shapes are getting drawn to the RenderTexture (which is set smooth, i might add), they are not smoothed by the window antialiasing so look jagged again.
does anyone know of a possible solution for this?
Here is some sample code which reproduces the problem:
#include <SFML\Graphics.hpp>
int main()
{
//create the window
sf::RenderWindow window(sf::VideoMode(500, 500), "Shape",sf::Style::Default,sf::ContextSettings(0,0,4));
//create the shape
sf::RectangleShape shape(sf::Vector2f(200,200));
shape.setFillColor(sf::Color::Green);
shape.setRotation(0);
shape.setOrigin(100,100);
shape.setPosition(250,250);
//rendertexture stuff
sf::RenderTexture windowTexture;
windowTexture.create(500,500);
windowTexture.setSmooth(true);
sf::Sprite windowSprite;
windowSprite.setTexture(windowTexture.getTexture());
bool useRenderTexture=true;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
if (event.type == sf::Event::KeyPressed)
{
switch (event.key.code)
{
//rotate left
case sf::Keyboard::Left:
shape.rotate(-5);
break;
//rotate right
case sf::Keyboard::Right:
shape.rotate(5);
break;
//set window antialiasing OFF
case sf::Keyboard::Num1:
window.create(sf::VideoMode(500, 500), "Shape",sf::Style::Default,sf::ContextSettings(0,0,0));
break;
//set window antialiasing ON
case sf::Keyboard::Num2:
window.create(sf::VideoMode(500, 500), "Shape",sf::Style::Default,sf::ContextSettings(0,0,4));
break;
//toggle the use of the rendertexture
case sf::Keyboard::R:
useRenderTexture=!useRenderTexture;
break;
}
}
}
if(useRenderTexture)
{
windowTexture.clear(sf::Color::Black);
windowTexture.draw(shape);
windowTexture.display();
}
window.clear(sf::Color::Black);
if(useRenderTexture)
window.draw(windowSprite);
else
window.draw(shape);
window.display();
}
return 0;
}
to reproduce the problem, just push left/right to rotate the square slightly, then use 'R' to toggle the rendertexture on/off, and '1' or '2' to set the window antialiasing off/on.
Thanks in advance