Page 1 of 1
Rendering issue
Posted: Sat May 12, 2018 6:16 pm
by mr_happy
Why does one edge of my, er, 'player' sprite (the green cube) sometimes display a white line alone one diagonal, whereas at other times is doesn't. There's only one place in the program where the image is drawn so it's not something I'm doing in code.
- Screenshot at 2018-05-12 18-40-05.png (207.71 KiB) Viewed 2637 times
- Screenshot at 2018-05-12 18-40-59.png (103.02 KiB) Viewed 2637 times
Re: Rendering issue
Posted: Sat May 12, 2018 7:53 pm
by grump
Drawing the sprite at non-integer coords?
Re: Rendering issue
Posted: Sun May 13, 2018 7:04 am
by mr_happy
grump wrote: ↑Sat May 12, 2018 7:53 pm
Drawing the sprite at non-integer coords?
Yes indeed; if I use ints everything is fine. I just read this [1], which sort of explains it - the fix is certainly easy enough. I think my understanding of how/where images are drawn is flawed - I was expecting draw() to place the image at the nearest integer position by default so x,y of 100.3, 100.1 would draw at 100,100 whereas 100.7, 100.1 would draw at 101, 100. Thanks for the clue anyway
[1]
viewtopic.php?t=79661
Re: Rendering issue
Posted: Sun May 13, 2018 8:29 am
by pgimeno
mr_happy wrote: ↑Sun May 13, 2018 7:04 am
I think my understanding of how/where images are drawn is flawed - I was expecting draw() to place the image at the nearest integer position by default so x,y of 100.3, 100.1 would draw at 100,100 whereas 100.7, 100.1 would draw at 101, 100. Thanks for the clue anyway
I don't think it was flawed, assuming you used the nearest filter. The problem typically shows up around n + 0.5 (e.g. 100.5), because due to rounding errors and floating point precision, some numbers are rounded up and some others are rounded down, and that discrepancy causes the visual artifacts.
Re: Rendering issue
Posted: Sun May 13, 2018 9:16 am
by mr_happy
Thanks pgimeno, it just seems odd that the artefact is a 'white' line... I'd expect some sort of dithering of the black edge. No matter, easy enough to fix