A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix: Improve font rendering quality
esengine68682eaf3ca8
diff --git a/src/esengine/editor/EditorApplication.cpp b/src/esengine/editor/EditorApplication.cppindex 0ea9f8895..a35d82f51 100644--- a/src/esengine/editor/EditorApplication.cpp+++ b/src/esengine/editor/EditorApplication.cpp@@ -59,20 +59,35 @@ void EditorApplication::onInit() {uiContext_->setViewport(getWidth(), getHeight());uiContext_->setDevicePixelRatio(getPlatform().getDevicePixelRatio());- // Load default font (try Windows system fonts)const char* fontPaths[] = {+#ifdef ES_PLATFORM_WINDOWS"C:/Windows/Fonts/segoeui.ttf","C:/Windows/Fonts/arial.ttf","C:/Windows/Fonts/tahoma.ttf",+#elif defined(ES_PLATFORM_MACOS)+ "/System/Library/Fonts/SFNS.ttf",+ "/System/Library/Fonts/Helvetica.ttc",+ "/Library/Fonts/Arial.ttf",+#else+ "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",+ "/usr/share/fonts/TTF/DejaVuSans.ttf",+ "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf",+#endif+ "assets/fonts/default.ttf",nullptr};+ bool fontLoaded = false;for (const char** path = fontPaths; *path != nullptr; ++path) {- if (uiContext_->loadFont("default", *path, 16.0f)) {+ if (uiContext_->loadFont("default", *path, 24.0f)) {ES_LOG_INFO("Loaded font: {}", *path);+ fontLoaded = true;break;}}+ if (!fontLoaded) {+ ES_LOG_WARN("No font loaded, text will not render");+ }// Wire up scroll events to UI systemgetPlatform().setScrollCallback([this](f32 deltaX, f32 deltaY, f32 x, f32 y) {diff --git a/src/esengine/ui/core/Theme.hpp b/src/esengine/ui/core/Theme.hppindex 2028c6114..053d19e8a 100644--- a/src/esengine/ui/core/Theme.hpp+++ b/src/esengine/ui/core/Theme.hpp@@ -153,12 +153,12 @@ struct ThemeSpacing {struct ThemeTypography {std::string defaultFont = "default";- f32 fontSizeSmall = 12.0f;- f32 fontSizeNormal = 14.0f;- f32 fontSizeMedium = 16.0f;- f32 fontSizeLarge = 18.0f;- f32 fontSizeTitle = 24.0f;- f32 fontSizeHeader = 32.0f;+ f32 fontSizeSmall = 14.0f;+ f32 fontSizeNormal = 16.0f;+ f32 fontSizeMedium = 20.0f;+ f32 fontSizeLarge = 24.0f;+ f32 fontSizeTitle = 28.0f;+ f32 fontSizeHeader = 36.0f;f32 lineHeight = 1.4f;f32 letterSpacing = 0.0f;diff --git a/src/esengine/ui/docking/DockTabBar.cpp b/src/esengine/ui/docking/DockTabBar.cppindex 5f2501165..1085a428e 100644--- a/src/esengine/ui/docking/DockTabBar.cpp+++ b/src/esengine/ui/docking/DockTabBar.cpp@@ -168,7 +168,8 @@ void DockTabBar::renderTab(UIBatchRenderer& renderer, const DockTabInfo& tab, ustab.bounds.height};- renderer.drawTextInBounds(tab.title, textBounds, *font, 12.0f, textColor,+ renderer.drawTextInBounds(tab.title, textBounds, *font,+ theme.typography.fontSizeNormal, textColor,HAlign::Left, VAlign::Center);}diff --git a/src/esengine/ui/rendering/UIBatchRenderer.cpp b/src/esengine/ui/rendering/UIBatchRenderer.cppindex 09d45719e..3de65ba72 100644--- a/src/esengine/ui/rendering/UIBatchRenderer.cpp+++ b/src/esengine/ui/rendering/UIBatchRenderer.cpp@@ -19,6 +19,7 @@#include "../layout/SizeValue.hpp"#include <array>+#include <cmath>#include <vector>#ifdef ES_PLATFORM_WEB@@ -130,7 +131,12 @@ static const char* UI_FRAGMENT_SHADER = R"(else if (index == 6) texColor = texture2D(u_textures[6], v_texCoord);else if (index == 7) texColor = texture2D(u_textures[7], v_texCoord);- vec4 color = texColor * v_color;+ vec4 color;+ if (texColor.g == 0.0 && texColor.b == 0.0 && texColor.a == 1.0) {+ color = vec4(v_color.rgb, texColor.r * v_color.a);+ } else {+ color = texColor * v_color;+ }if (v_cornerRadii.x > 0.0 || v_cornerRadii.y > 0.0 ||v_cornerRadii.z > 0.0 || v_cornerRadii.w > 0.0) {@@ -215,7 +221,12 @@ static const char* UI_FRAGMENT_SHADER = R"(void main() {vec4 texColor = texture(u_textures[v_texIndex], v_texCoord);- vec4 color = texColor * v_color;+ vec4 color;+ if (texColor.g == 0.0 && texColor.b == 0.0 && texColor.a == 1.0) {+ color = vec4(v_color.rgb, texColor.r * v_color.a);+ } else {+ color = texColor * v_color;+ }if (v_cornerRadii.x > 0.0 || v_cornerRadii.y > 0.0 ||v_cornerRadii.z > 0.0 || v_cornerRadii.w > 0.0) {@@ -670,8 +681,8 @@ void UIBatchRenderer::drawText(const std::string& text, const glm::vec2& positioconst auto* glyph = font.getGlyph(static_cast<u32>(c));if (!glyph) continue;- f32 xPos = x + glyph->bearingX * scale;- f32 yPos = y + (font.getAscent() - glyph->bearingY) * scale;+ f32 xPos = std::round(x + glyph->bearingX * scale);+ f32 yPos = std::round(y + (font.getAscent() - glyph->bearingY) * scale);f32 w = glyph->width * scale;f32 h = glyph->height * scale;@@ -722,6 +733,8 @@ void UIBatchRenderer::drawTextInBounds(const std::string& text, const Rect& bounbreak;}+ x = std::round(x);+ y = std::round(y);drawText(text, {x, y}, font, fontSize, color);}