SFML community forums

Help => Graphics => Topic started by: Lyosha12 on April 28, 2018, 09:27:01 pm

Title: Why the coordinate system in sf::RenderTarget begins with (1, 0)?
Post by: Lyosha12 on April 28, 2018, 09:27:01 pm
While I has been generate an texture I noticed to strange implementation:
the coordinate system has been moved on one pixel to right.
It is from here I can draw and see what I draw. Why?
I don't understand, explain me this aspect, please.

(click to show/hide)
(click to show/hide)
Title: Re: Why the coordinate system in sf::RenderTarget begins with (1, 0)?
Post by: Hapax on April 28, 2018, 09:59:33 pm
It doesn't; it starts at (0, 0).

However, it's important to note that this co-ordinate is the corner of a pixel (top-left corner of the top-left pixel) and (1, 1) is also a corner (bottom-right corner of the top-left pixel).
To draw a pixel, you can draw a square/rectangle that covers that area (from 0,0 to 1,1).

Using points, though, is a bit more odd.
It basically fills the entire pixel that is at the co-ordinate that you give it. Unfortunately, due to floating point accuracy and rounding etc., specifying the co-ordinate of an edge or corner means that you can't really tell which pixel it will 'choose'. For a corner, it could any of the four pixels that it touches.

The solution, then (when working with sf::Points and sf::Lines), is to add (0.5, 0.5) to any pixel co-ordinate so that its location is smack in the centre of the pixel and there is no doubt which pixel you actually want.
Try it ;)


Please use more minimal code in the future for examples. There is a lot of code here that is unnecessary for this question.



EDIT: added the fact that it also applies to sf::Lines
Title: Re: Why the coordinate system in sf::RenderTarget begins with (1, 0)?
Post by: Lyosha12 on April 28, 2018, 10:12:39 pm
Thanks, it works. Now I understood and will refers to this topic in my comments :)