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

Author Topic: Why the coordinate system in sf::RenderTarget begins with (1, 0)?  (Read 1894 times)

0 Members and 1 Guest are viewing this topic.

Lyosha12

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
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)

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Why the coordinate system in sf::RenderTarget begins with (1, 0)?
« Reply #1 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
« Last Edit: April 28, 2018, 10:09:44 pm by Hapax »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Lyosha12

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: Why the coordinate system in sf::RenderTarget begins with (1, 0)?
« Reply #2 on: April 28, 2018, 10:12:39 pm »
Thanks, it works. Now I understood and will refers to this topic in my comments :)

 

anything