Text rendering

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-10-07 02:25:02 +03:00
parent 596f24becd
commit c377baf3c9
2 changed files with 18 additions and 13 deletions

View File

@@ -130,7 +130,8 @@ auto TextRenderer::generate_glyph(FontRuntime &rt, FontData &fd,
msdfgen::FONT_SCALING_EM_NORMALIZED, &advance_em)) msdfgen::FONT_SCALING_EM_NORMALIZED, &advance_em))
return std::nullopt; return std::nullopt;
shape.normalize(); shape.normalize();
msdfgen::edgeColoringInkTrap(shape, 3.0); // FIXME: Figure out shader
// msdfgen::edgeColoringInkTrap(shape, 3.0);
auto bounds = shape.getBounds(); auto bounds = shape.getBounds();
float const width_em = static_cast<float>(bounds.r - bounds.l); float const width_em = static_cast<float>(bounds.r - bounds.l);
float const height_em = static_cast<float>(bounds.t - bounds.b); float const height_em = static_cast<float>(bounds.t - bounds.b);
@@ -173,10 +174,13 @@ auto TextRenderer::generate_glyph(FontRuntime &rt, FontData &fd,
for (int x = 0; x < bmp_w; ++x) { for (int x = 0; x < bmp_w; ++x) {
float const *px = msdf_bitmap(x, y); float const *px = msdf_bitmap(x, y);
auto const r = msdfgen::pixelFloatToByte(px[0]); auto const r = msdfgen::pixelFloatToByte(px[0]);
auto const g = msdfgen::pixelFloatToByte(px[1]); // FIXME: Figure out shader
auto const b = msdfgen::pixelFloatToByte(px[2]); // auto const g = msdfgen::pixelFloatToByte(px[1]);
// auto const b = msdfgen::pixelFloatToByte(px[2]);
// buffer[static_cast<size_t>(dst_y) * bmp_w + x]
// = Color { r, g, b, 255 };
buffer[static_cast<size_t>(dst_y) * bmp_w + x] buffer[static_cast<size_t>(dst_y) * bmp_w + x]
= Color { r, g, b, 255 }; = Color { 255, 255, 255, r };
} }
} }
@@ -348,12 +352,13 @@ auto TextRenderer::draw_text(FontHandle const font, std::string_view const text,
float pen_y_em = 0.0f; float pen_y_em = 0.0f;
rt.frame_stamp++; rt.frame_stamp++;
BeginShaderMode(m_msdf_shader); // FIXME: Figure out shader
if (m_px_range_uniform >= 0) { // BeginShaderMode(m_msdf_shader);
float shader_px_range = rt.px_range; // if (m_px_range_uniform >= 0) {
SetShaderValue(m_msdf_shader, m_px_range_uniform, &shader_px_range, // float shader_px_range = rt.px_range;
SHADER_UNIFORM_FLOAT); // SetShaderValue(m_msdf_shader, m_px_range_uniform, &shader_px_range,
} // SHADER_UNIFORM_FLOAT);
// }
for (unsigned i = 0; i < length; ++i) { for (unsigned i = 0; i < length; ++i) {
u32 glyph_index = infos[i].codepoint; u32 glyph_index = infos[i].codepoint;
@@ -395,7 +400,7 @@ auto TextRenderer::draw_text(FontHandle const font, std::string_view const text,
pen_y_em += hb_to_em(positions[i].y_advance, rt.units_per_em); pen_y_em += hb_to_em(positions[i].y_advance, rt.units_per_em);
} }
EndShaderMode(); // EndShaderMode();
hb_buffer_destroy(buffer); hb_buffer_destroy(buffer);
auto const draw_end = std::chrono::steady_clock::now(); auto const draw_end = std::chrono::steady_clock::now();

View File

@@ -36,8 +36,8 @@ auto App::tick() -> void
if (m_tr) { if (m_tr) {
Color const fg = theme().foreground; Color const fg = theme().foreground;
Vector2 const pos { 40.0f, 60.0f }; Vector2 const pos { 40.0f, 60.0f };
auto text = std::string_view("Hello from Waylight"); auto text = std::string_view("Hello from Waylight! 日本人ですか?");
auto size = 48; auto size = sin(GetTime()) * 12 + 32;
m_tr->draw_text(m_font, text, pos, size, fg); m_tr->draw_text(m_font, text, pos, size, fg);
} }