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

Implement MSDF font rendering #203

Merged
merged 1 commit into from
Dec 21, 2024
Merged

Conversation

hasenbanck
Copy link
Collaborator

No description provided.

@hasenbanck hasenbanck force-pushed the ingame_text branch 13 times, most recently from 44110c6 to e2050f4 Compare December 20, 2024 10:39
@hasenbanck hasenbanck marked this pull request as ready for review December 20, 2024 10:39
@hasenbanck hasenbanck force-pushed the ingame_text branch 3 times, most recently from 7563f73 to fa182de Compare December 20, 2024 11:54
@kokosha
Copy link
Contributor

kokosha commented Dec 20, 2024

Screenshot 2024-12-20 184505
The chat message offset seems not correct in the above image. When you @warp and later say anything, the offset seems wrong. It may be caused by the missing character space in the warp message and this change the offset of the message, because it doesn't contain the character space , making the offset wrong.

@eleriaqueen
Copy link
Contributor

eleriaqueen commented Dec 21, 2024

There's also an issue with wrapped text, this issue is not present in main branch.
Screenshot_20241221_082736
Screenshot_20241221_082754

@hasenbanck
Copy link
Collaborator Author

It seems the text_height is not calculated correctly. This is slightly confusing:

let x = physical_glyph.x as f32 + glyph_coordinate.offset_left;
let y = run.line_y + physical_glyph.y as f32 - glyph_coordinate.offset_top;
let width = glyph_coordinate.width;
let height = glyph_coordinate.height;

text_height = text_height.max(y + height);

let position = Rectangle::new(Point2::new(x, y), Point2::new(x + width, y + height));
let color = layout_glyph.color_opt.map(|color| color.into()).unwrap_or(default_color);

glyphs.push(GlyphInstruction {
    position,
    texture_coordinate: glyph_coordinate.texture_coordinate,
    color,
});

We use the x/y/width/height also for the glyph position. Since the glyphs are layed out correct, I wonder why the text height is incorrect. Maybe the glyph stores now offets in a different "direction"? I have to debug this more to understand the true cause for this (we didn't change the layout rendering itself in a fundamental way, only the "gylph storage").

@hasenbanck
Copy link
Collaborator Author

@eleriaqueen @kokosha I think I fixed the issue. I took out the glyphs out of the equation and use the line height directly. This should fix the wrapping issues you have encountered. Would be happy if you could test again.

We now use Noto Sans, since it has the broadest Unicode support of the open source fonts. I added a README.md in the font folder, so that people can change the font if the need should arise to do so.

With this change, we unified our text rendering to use MSDF rendering. For this we have to generate the whole font map offline in advance.
@kokosha
Copy link
Contributor

kokosha commented Dec 21, 2024

It is working now!

@eleriaqueen
Copy link
Contributor

Yep looks like you fixed the issue.

@hasenbanck hasenbanck merged commit 507675e into vE5li:main Dec 21, 2024
3 checks passed
@hasenbanck hasenbanck deleted the ingame_text branch December 21, 2024 11:35
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.

3 participants