SFML community forums

Help => Graphics => Topic started by: NGM88 on July 14, 2018, 07:07:43 pm

Title: float / int difference in texture coordinates
Post by: NGM88 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?
Title: Re: float / int difference in texture coordinates
Post by: Laurent 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.
Title: Re: float / int difference in texture coordinates
Post by: Hapax 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 (https://github.com/Hapaxia/SelbaWard/wiki)'s objects all take float texture co-ordinates now for this very reason. ;)