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

Author Topic: float / int difference in texture coordinates  (Read 2041 times)

0 Members and 2 Guests are viewing this topic.

NGM88

  • Full Member
  • ***
  • Posts: 162
    • View Profile
float / int difference in texture coordinates
« on: July 14, 2018, 07:07:43 pm »
This is something I wonder when I use both sf::VertexArray and sf::Sprite in a project. Why is it that sprites take integers to set their texture rect but vertex texcoords are in floats?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: float / int difference in texture coordinates
« Reply #1 on: July 14, 2018, 08:48:33 pm »
At the time I added sf::Vertex to SFML, some families of graphics cards had buggy behaviour with integer texture coordinates. Given that it is not the usual way to do it (texture coordinates are always floats), I just gave up.

sf::Sprite uses integer coordinates because it's not what is sent to the graphics card, they are internally transformed to float coordinates.
Laurent Gomila - SFML developer

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: float / int difference in texture coordinates
« Reply #2 on: July 14, 2018, 09:17:46 pm »
Since texture rectangles are generally static, integer co-ordinates make sense from a user point of view; they also determine the size of the sf::Sprite so, again, they make sense to be integer for most normal cases.

However, float co-ordinates for texture rectangles are necessary for smoothly animating texture rectangles; if you need this, you will need to create your own version of sf::Sprite, which isn't that difficult to do.

Selba Ward's objects all take float texture co-ordinates now for this very reason. ;)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything