1
Graphics / Issue with sf::View and pixel perfect texCoords
« on: May 11, 2018, 01:19:57 am »
Hello there.
After introducing scrolling via sf::View to a tile based scene, I discovered sporadic occurence of artifacts. It took me a while to find the source via experimenting a lot but now I have come to the conclusion that occasionally, my View is set in such an unfortunate way that some transformations cause additional pixels to be drawn.
A bit more detailed:
I've got a bunch of Tiles using Quads with texCoords which are a multiple of some integer tile size referring to a tilemap texture. I made sure that the float values actually are integers. Something like [0, 0], [0, 16], [16, 0], [16,16] and the likes.
Now, I set the View every frame before drawing and occasionally tiles are drawn with pixels that belong to the next tile on the texture (like [17, 16] instead of [16, 16] for the bottom right pixel). Generally, those additional pixels are completely unrelated thus leading to artifacts.
Do you have any ideas from preventing this to happen?
I think the problem does not occur if I set the View's top left corner as an integer. However, this causes other problems because my View follows some Sprite with float (actually double) position (resulting in serious jittering). Or I might convert all the positions to integer for drawing (but this might also be a problem because of rounding issues).
Or shall I try setting the tex coords to the center of the pixels (like [0.5, 15.5])? Sounds off to me.
After introducing scrolling via sf::View to a tile based scene, I discovered sporadic occurence of artifacts. It took me a while to find the source via experimenting a lot but now I have come to the conclusion that occasionally, my View is set in such an unfortunate way that some transformations cause additional pixels to be drawn.
A bit more detailed:
I've got a bunch of Tiles using Quads with texCoords which are a multiple of some integer tile size referring to a tilemap texture. I made sure that the float values actually are integers. Something like [0, 0], [0, 16], [16, 0], [16,16] and the likes.
Now, I set the View every frame before drawing and occasionally tiles are drawn with pixels that belong to the next tile on the texture (like [17, 16] instead of [16, 16] for the bottom right pixel). Generally, those additional pixels are completely unrelated thus leading to artifacts.
Do you have any ideas from preventing this to happen?
I think the problem does not occur if I set the View's top left corner as an integer. However, this causes other problems because my View follows some Sprite with float (actually double) position (resulting in serious jittering). Or I might convert all the positions to integer for drawing (but this might also be a problem because of rounding issues).
Or shall I try setting the tex coords to the center of the pixels (like [0.5, 15.5])? Sounds off to me.