Skip to content

Make font atlas padding between packed glyphs configurable #1282

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

Merged
merged 2 commits into from
Aug 16, 2017

Conversation

jadwallis
Copy link
Contributor

Adds a TexGlyphPadding member to ImFontAtlas, which allows the user to configure the size of the padding between pixels when the font atlas texture is built (similar to how TexDesiredWidth allows a desired width of this texture to be specified).

We've found ImGui really useful in our project, but had a need to make some tweaks to the generated font atlas texture in our code after ImGui builds it. Writing a custom font rasterizer for this (like #618) seems like it would be a bit overkill, since we otherwise closely mirror what ImGui does. The texture change we make needs the glyphs in the texture to be spaced out a bit more than the hard-coded default of 1 pixel, which isn't something that the user is currently able to configure. Admittedly it's a bit of a weird and niche use case, but being able to configure this would be quite handy.

Thanks for taking a look!

@ocornut
Copy link
Owner

ocornut commented Aug 15, 2017

Thanks James. The patch looks good. Interestingly it could also be useful for very low-spec system to use this with a value of 0 and bilinear filtering filtered (will give it a try).

We currently have mouse cursor bitmap (see RenderCustomTexData) that are manually packed with 1 pixel spacing, would that be a problem? I think this part will be replaced down the line as we support submitting user data/icons to the packer, and probably the cursors will be packed normally them.

@jadwallis
Copy link
Contributor Author

For our particular use case we only modify the font glyphs and leave the cursors alone, so the manual packing there isn't a problem. Given how the cursors are currently implemented, I imagine adjusting those to use a configurable padding amount would probably be a bit more awkward!

@ocornut
Copy link
Owner

ocornut commented Aug 15, 2017

By the way could you clarify the your use with 2+ spacing? Is it related to mip-mapping, or are you altering the rasterized data, e.g. adding an outline to it?

@jadwallis
Copy link
Contributor Author

Yeah, we're altering the rasterized data to add an outline*. It's admittedly a little bit of a hack, but it does mean we don't have to maintain our own font rasterizer as mentioned earlier. If text outlining were available in ImGui that would be neat, though from #745 it's understandable why it isn't. :)

*We want an outline because we want our window backgrounds to be fairly translucent, to avoid obscuring the scene underneath (i.e. using some windows as overlays to display data, with only a few interactive widgets). Depending on what's in the scene, this can make text of a single colour hard to read, so an outline is desirable.

@ocornut ocornut merged commit f827c84 into ocornut:master Aug 16, 2017
@ocornut
Copy link
Owner

ocornut commented Aug 16, 2017

Merged.

@ocornut
Copy link
Owner

ocornut commented Aug 16, 2017

@jadwallis: Your approach will actually break once I add more data into the texture atlas (e.g. rounded shapes), as you won't be able to distinguish easily font vs other graphic data. So you may need to consider another approach. If that happen pretty soon I'd probably remove TexGlyphPadding then.

@jadwallis
Copy link
Contributor Author

Thanks for the heads up. Hopefully the current approach will tide us over for the moment at least, and I can consider alternative, less hacky implementations later when I have a bit more time.

Cheers for your help. :)

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

Successfully merging this pull request may close these issues.

2 participants