Thanks for explaining your decision, it sounds reasonable. The only place where a switch functionality could appear in the public API would be sf::Drawable anyway, wouldn't it? But I agree it were more a desperate attempt than a proper solution. Let's try to pick the advantages of both approaches.
I did some experiments again. Since the flickering artifact I mentioned in this thread seems to appear mostly at translations, it might be more effective to consider only them for the moment. I don't know whether there are many use cases where rounded translation coordinates are inappropriate, but for my code I assumed this is not the case. I modified Drawable.cpp of the current revision (1570) slightly:
Additional code before the begin of namespace sf:
// Flag to set in test program
extern bool DrawableRound = true;
// Rounds the coordinates of a vector
sf::Vector2f RoundVector(sf::Vector2f vector)
{
return DrawableRound ? sf::Vector2f(std::floor(vector.x + .5f), std::floor(vector.y + .5f)) : vector;
}
Modified code in Drawable::GetMatrix():
// myMatrix = Matrix3::Transformation(myOrigin, myPosition, myRotation, myScale); // replaced with
myMatrix = Matrix3::Transformation(myOrigin, RoundVector(myPosition), myRotation, myScale);
Of course, this is just a quick hack for testing purposes.
I used Spidyy's code and added a moving and a rotating sf::Text:
#include <SFML/Graphics.hpp>
extern bool DrawableRound;
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600, 32), "Rounding is ON");
sf::Image image;
if(!image.LoadFromFile("image.png"))
return 1;
sf::Sprite sprite(image);
sf::Text text("A simple text to test");
text.SetCharacterSize(12u);
for (;;)
{
sf::Event Event;
while(window.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
{
return 0;
}
// Mouse click: Switch between rounded/continuous implementation
else if (Event.Type == sf::Event::MouseButtonPressed)
{
DrawableRound = !DrawableRound;
if (DrawableRound)
window.SetTitle("Rounding is ON");
else
window.SetTitle("Rounding is OFF");
}
}
float X = 0.2f * (window.GetInput().GetMouseX() / static_cast<float>(window.GetWidth()));
window.Clear();
sprite.SetScale(0.8f + X, 0.8f + X);
window.Draw(sprite);
text.SetRotation(0.f);
text.SetPosition(window.GetInput().GetMouseX() / 2.43f + 350.f, 30.f);
window.Draw(text);
text.SetRotation(text.GetPosition().x / 2.f);
text.SetPosition(500.f, 200.f);
window.Draw(text);
window.Display();
}
}
You can switch between the rounded and normal mode with any mouse button. The moving text shows a significant difference, while the scaling image is still smooth – in contrast to the approach of revision 1389. For the moment, I didn't take the view into account, because I am not too familiar with the SFML source code. I'm pretty sure I've overlooked several other factors, but... Maybe this helps you, or inspires you to another idea.
Btw: Nice, you're having 11111 posts now