Cannot dynamically add new fonts #224

Closed
opened 2015-05-12 13:05:45 +00:00 by petrihakkinen · 4 comments
petrihakkinen commented 2015-05-12 13:05:45 +00:00 (Migrated from github.com)

When I add a new font at runtime (after init) and rebuild the texture, the new font appears ok but existing fonts get corrupted. I think this happens because the glyphs move around in the font atlas but the texture coordinates of old fonts are not updated. Is it possible to somehow fix this without needing to readd all previously added fonts to the atlas?

When I add a new font at runtime (after init) and rebuild the texture, the new font appears ok but existing fonts get corrupted. I think this happens because the glyphs move around in the font atlas but the texture coordinates of old fonts are not updated. Is it possible to somehow fix this without needing to readd all previously added fonts to the atlas?
ocornut commented 2015-05-12 13:31:10 +00:00 (Migrated from github.com)

Looks like a bug, after building the font atlas we call ImFontAtlas::ClearTexData().
When adding new fonts the old font isn't in the InputData yet so after the second atlas build the older fonts in the Fonts[] array aren't updated. Not sure what's the righter way to fix it yet.

Right now the workaround is to call Fonts->Clear() and re-add everything.
Note that even if I fix that it won't be faster. I need to compute the atlas size and rasterize everything anyway, it doesn't incrementally rasterize. That would require more work (for later).

Knowing this, would you still want a fix soon?

Looks like a bug, after building the font atlas we call ImFontAtlas::ClearTexData(). When adding new fonts the old font isn't in the InputData yet so after the second atlas build the older fonts in the Fonts[] array aren't updated. Not sure what's the righter way to fix it yet. Right now the workaround is to call Fonts->Clear() and re-add everything. Note that even if I fix that it won't be faster. I need to compute the atlas size and rasterize everything anyway, it doesn't incrementally rasterize. That would require more work (for later). Knowing this, would you still want a fix soon?
petrihakkinen commented 2015-05-12 14:04:46 +00:00 (Migrated from github.com)

Rerasterizing everything is acceptable for me. It just felt buggy that adding a new font corrupts the old fonts. I would be happy if adding a new font would "just work". (I'm doing lots of live coding, so I'm used to adding new resources on the fly. Speed is not critical in this case.).

No need to rush this fix, take your time.

Rerasterizing everything is acceptable for me. It just felt buggy that adding a new font corrupts the old fonts. I would be happy if adding a new font would "just work". (I'm doing lots of live coding, so I'm used to adding new resources on the fly. Speed is not critical in this case.). No need to rush this fix, take your time.
ocornut commented 2015-05-12 14:18:42 +00:00 (Migrated from github.com)

That last commit ocornut/imgui@5df542c3c0 allows to append new font.

I moved the ClearInputData() from imgui to application side, so it is in the example applications but anyone integrating with their own engine can see more clearly what is being done.
Connects to #220 only when calling ClearInputData() you'll notice that ImFontAtlas has taken ownership of the TTF blob.

That last commit https://github.com/ocornut/imgui/commit/5df542c3c09f09676c6f54e539736351219b8bf4 allows to append new font. I moved the ClearInputData() from imgui to application side, so it is in the example applications but anyone integrating with their own engine can see more clearly what is being done. Connects to #220 only when calling ClearInputData() you'll notice that ImFontAtlas has taken ownership of the TTF blob.
petrihakkinen commented 2015-05-15 08:31:01 +00:00 (Migrated from github.com)

Thanks, it fixed the issue!

Thanks, it fixed the issue!
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#224
No description provided.