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

font and rasterization improvements for ImGui #76529

Merged
merged 6 commits into from
Oct 24, 2024

Conversation

db48x
Copy link
Contributor

@db48x db48x commented Sep 18, 2024

Summary

Interface "use Freetype to render fonts for ImGui, and use multiple fonts in the ImGui interface"

Purpose of change

Make ImGui use Roboto by default, and the Freetype rasterizer. Load both the configured gui font and the normal monospaced font for use by ImGui. Make item descriptions use the mono font for drawing ASCII artwork. Configure hinting so that Terminus and unifont don’t look awful.

Fixes #76420

Testing

Check out the artwork for a pistol or something.

Additional context

This is a draft for a reason: I need someone who builds on Windows and/or Mac to give me the right CFLAGS/LDFLAGS for linking against Freetype2

Make ImGui use Roboto by default, and the Freetype rasterizer. Load
both the configured gui font and the normal monospaced font for use by
ImGui. Make item descriptions use the mono font for drawing ASCII artwork.

Fixes CleverRaven#76420
@github-actions github-actions bot added Info / User Interface Game - player communication, menus, etc. Code: Build Issues regarding different builds and build environments [JSON] Changes (can be) made in JSON [C++] Changes (can be) made in C++. Previously named `Code` Monsters Monsters both friendly and unfriendly. ImGui Anything related to the new ImGui UI for SDL/tiles or ImTui for curses builds <Bugfix> This is a fix for a bug (or closes open issue) astyled astyled PR, label is assigned by github actions json-styled JSON lint passed, label assigned by github actions labels Sep 18, 2024
@harakka
Copy link
Member

harakka commented Sep 19, 2024

Is there a particular reason for adding a new font to the mix, and are there any issues with including Apache licensed material in a cc-by-sa 3.0 project?

@db48x
Copy link
Contributor Author

db48x commented Sep 19, 2024

Good questions. Yes, the reason for adding Roboto is that it is a proportional font. We could pick from quite a selection, but Roboto was ready to hand, appropriately licensed, inoffensively styled (not deliberately weird or thematic, or deliberately bad like Comic Sans, etc), and has relatively thick strokes even at small font sizes (which makes it render well even if we stick to the default STB rasterizer which cannot do any hinting). And of course the user can override the choice if they prefer something else.

Apache 2.0 is completely compatible with the Creative Commons license, and it meets the definition of an Open Source license.

@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Sep 19, 2024
@db48x
Copy link
Contributor Author

db48x commented Sep 20, 2024

I guess it builds fine on OSX. Anyone want to give it a try and make sure it works?

@db48x db48x changed the title WIP font stuff for ImGui font and rasterization improvements for ImGui Oct 6, 2024
@db48x db48x marked this pull request as ready for review October 6, 2024 16:45
@db48x
Copy link
Contributor Author

db48x commented Oct 6, 2024

Weird. It compiled just fine on Windows while it was a draft…

@Maleclypse
Copy link
Member

It's broken at the macOS build referencing imgui so I'm assuming this isn't a random failure?

@db48x
Copy link
Contributor Author

db48x commented Oct 15, 2024

I wish it were. It's been more than 15 years since I did any development on OSX, and I never had to dig too deep into the build system on that project. I don’t have a Windows machine either. I’d appreciate some help getting this patch to work on those platforms from anyone who has the time.

I spent a little time last weekend trying to find documentation on the subject, but didn’t make much headway. I didn’t really want to spam the CI system with guesses, but on the other hand the only guess I have is to add -lfreetype to the LDFLAGS and hope for the best.

@katemonster33
Copy link
Contributor

katemonster33 commented Oct 16, 2024

@db48x I took a look. does not compile on VS2022. VS2022 does not like your usage of '__attribute__((unused))'. Instead it prefers the C++17 '[[maybe_unused]]'. If we can't use C++17 across the board, maybe consider a preprocessor definition?

@db48x
Copy link
Contributor Author

db48x commented Oct 17, 2024

Oops, sorry about that. It looks like I fixed that last week and then just never pushed it. Must have gotten distracted.

You’ll need to pick a font that actually has the appropriate
characters for your chosen language. It should also have glyphs for
ASCII characters, or we’ll be forced to use the fallback path for them.
@db48x
Copy link
Contributor Author

db48x commented Oct 19, 2024

A little improvement:
Screenshot from 2024-10-19 01-40-13
Screenshot from 2024-10-19 01-49-23

@github-actions github-actions bot added Translation I18n [Python] Code made in Python labels Oct 19, 2024
db48x added 2 commits October 19, 2024 15:09
Nobody could say with a straight face that this is better. Especially
the two blank lines between every function.
@db48x db48x force-pushed the imgui-font-rasterization branch from 686bde5 to fe9d67a Compare October 20, 2024 11:25
@Maleclypse Maleclypse merged commit 96d0a8c into CleverRaven:master Oct 24, 2024
20 of 28 checks passed
@Maleclypse
Copy link
Member

Crap I misread this and thought it was no longer breaking Mac builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Code: Build Issues regarding different builds and build environments ImGui Anything related to the new ImGui UI for SDL/tiles or ImTui for curses builds Info / User Interface Game - player communication, menus, etc. [JSON] Changes (can be) made in JSON json-styled JSON lint passed, label assigned by github actions Monsters Monsters both friendly and unfriendly. [Python] Code made in Python Translation I18n
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Properly hint text and improve font rendering.
4 participants