Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML 2 Vertex Miscalibration?  (Read 1598 times)

0 Members and 1 Guest are viewing this topic.

Jalfor

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
SFML 2 Vertex Miscalibration?
« 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;
}
If a picture tells 1000 words, then a YouTube video clearly tells 1000000 making a YouTube video obviously a larger work than the Lord Of The Rings, or some other massive novel. Thus are the laws of YouTube videos.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML 2 Vertex Miscalibration?
« Reply #1 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.
Laurent Gomila - SFML developer

Jalfor

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Re: SFML 2 Vertex Miscalibration?
« Reply #2 on: November 24, 2012, 08:59:02 am »
Oh, I thought they were pixel co ordinates. Thanks.
If a picture tells 1000 words, then a YouTube video clearly tells 1000000 making a YouTube video obviously a larger work than the Lord Of The Rings, or some other massive novel. Thus are the laws of YouTube videos.