Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix text jitter for animated (moving) text #646

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

rgb2hsv
Copy link

@rgb2hsv rgb2hsv commented Aug 14, 2022

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

@@ -2487,7 +2493,7 @@ float nvgText(NVGcontext* ctx, float x, float y, const char* string, const char*
verts = nvg__allocTempVerts(ctx, cverts);
if (verts == NULL) return x;

fonsTextIterInit(ctx->fs, &iter, x*scale, y*scale, string, end, FONS_GLYPH_BITMAP_REQUIRED);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rendering at the origin means we don't have to care about the scale of the translation.

@mulle-nat
Copy link
Contributor

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

@Skytrias
Copy link

Skytrias commented Nov 15, 2022

good change 👍
looks like the demo scaling doesnt work with this change though

@alpheratz0
Copy link

Nice work! but sadly scaling is broken

@rgb2hsv
Copy link
Author

rgb2hsv commented Oct 3, 2023

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
Copy link

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!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants