SFML community forums

Help => Graphics => Topic started by: Jalfor on November 24, 2012, 08:36:24 am

Title: SFML 2 Vertex Miscalibration?
Post by: Jalfor on November 24, 2012, 08:36:24 am
The x values with sf::Vertex seem to be one off what they are meant to be.

This shows nothing:

#include <SFML/Graphics.hpp>

int main()
{
        //The Window
        sf::RenderWindow window(sf::VideoMode(600, 400), "SFML works!");
        sf::Vertex line[2];

        while (window.isOpen())
        {
                line[0].position.x = 0;
                line[0].position.y = 0;

                line[1].position.x = 0;
                line[1].position.y = 100;

                window.clear();
                window.draw(line, 2, sf::Lines);
                window.display();
        }

        return 0;
}

while this shows a line going across the top of the window

#include <SFML/Graphics.hpp>

int main()
{
        //The Window
        sf::RenderWindow window(sf::VideoMode(600, 400), "SFML works!");
        sf::Vertex line[2];

        while (window.isOpen())
        {
                line[0].position.x = 0;
                line[0].position.y = 0;

                line[1].position.x = 100;
                line[1].position.y = 0;

                window.clear();
                window.draw(line, 2, sf::Lines);
                window.display();
        }

        return 0;
}
Title: Re: SFML 2 Vertex Miscalibration?
Post by: Laurent on November 24, 2012, 08:44:55 am
If your line is on the edge of pixel 0, and is 1 pixel wide, then it will expand from -0.5 to 0.5. This is a border case for the rasterizer and with floating point rounding errors it may end up rasterizing the line on pixel -1 rather than 0.

If you want your line to cover exactly and completely the pixel 0, it must be defined in 0.5.
Title: Re: SFML 2 Vertex Miscalibration?
Post by: Jalfor on November 24, 2012, 08:59:02 am
Oh, I thought they were pixel co ordinates. Thanks.