memononen / nanovg

Antialiased 2D vector drawing library on top of OpenGL for UI and visualizations.
zlib License
5.06k stars 767 forks source link

Fix text jitter for animated (moving) text #646

Open rgb2hsv opened 1 year ago

rgb2hsv commented 1 year ago

Font stash returns glyph positions in integer pixels. When rendering text at floating point positions, glyph positions get rounded to the nearest pixel. This is particularly noticeable with animated moving text, giving the appearance of jitter relative to other animated graphics. To circumvent this problem, this PR renders text at the origin (0,0) and then translates it afterwards to the proper floating point pixel location. This is possible because text rendering is shift invariant. In addition to updating the draw text call, all the methods for getting text bounds and positions have been updated as well.

dump

mulle-nat commented 1 year ago

Sounds interesting, I will try this out sometime. Thanks for making these changes public.

Skytrias commented 1 year ago

good change :+1: looks like the demo scaling doesnt work with this change though

alpheratz0 commented 9 months ago

Nice work! but sadly scaling is broken

rgb2hsv commented 9 months ago

Nice work! but sadly scaling is broken

Thanks for calling this out. I've added a fix for scaling and amended the test case to exercise it. Please let me know if it works for you.

alpheratz0 commented 9 months ago

Thanks for calling this out. I've added a fix for scaling and amended the test case to exercise it. Please let me know if it works for you.

Thank you so much for the fast response and fix, now it works perfectly!!!!