From 3c441d5a5d03338cbe8ef13cfe4f49a3dadc26ed Mon Sep 17 00:00:00 2001 From: falsycat Date: Mon, 14 Oct 2019 00:00:00 +0000 Subject: [PATCH] [update] Improved the text rendering engine. --- src/sj/ResultScene.d | 6 +++--- src/sj/SelectScene.d | 12 +++--------- src/sj/Text.d | 30 ++++++++++++++++++------------ 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/sj/ResultScene.d b/src/sj/ResultScene.d index d856e67..28e090f 100644 --- a/src/sj/ResultScene.d +++ b/src/sj/ResultScene.d @@ -41,17 +41,17 @@ class ResultScene : SceneInterface { enum CubeInterval = 0.005; /// - enum DescTextScale = vec3(-0.002, 0.002, 0.002); + enum DescTextScale = vec3(-0.1, 0.1, 0.1); /// enum DescTextTranslation = vec3(0, -0.3, 0); /// enum DescTextColor = vec4(0.2, 0.2, 0.2, 1); /// - enum RankTextScale = vec3(-0.002, 0.002, 0.002); + enum RankTextScale = vec3(-0.1, 0.1, 0.1); /// enum RankTextTranslation = vec3(0, -0.5, 0); /// - enum ScoreTextScale = vec3(-0.002, 0.002, 0.002); + enum ScoreTextScale = vec3(-0.1, 0.1, 0.1); /// enum ScoreTextTranslation = vec3(0, -0.55, 0); diff --git a/src/sj/SelectScene.d b/src/sj/SelectScene.d index 6a1ec19..fafa1b4 100644 --- a/src/sj/SelectScene.d +++ b/src/sj/SelectScene.d @@ -28,11 +28,11 @@ import sj.FontSet, class SelectScene : SceneInterface { public: /// - enum DescTextScale = vec3(-0.002, 0.002, 0.002); + enum DescTextScale = vec3(-0.1, 0.1, 0.1); /// enum DescTextTranslation = vec3(0, -0.3, 0); /// - enum DescTextColor = vec4(0.02, 0.02, 0.02, 1); + enum DescTextColor = vec4(0.2, 0.2, 0.2, 1); /// this(LobbyWorld lobby, ProgramSet program, FontSet fonts, Music[] music_list) { @@ -140,7 +140,7 @@ private abstract class AbstractSceneState { enum LoadingCubeInterval = 0.06; enum TitleTextSize = 40; - enum TitleTextScale = vec3(-0.002, 0.002, 0.002); + enum TitleTextScale = vec3(-0.1, 0.1, 0.1); enum TitleTextTranslation = vec3(0, -0.4, 0); enum TitleTextRandomTranslationRange = 0.02; @@ -293,12 +293,6 @@ private class MusicWaitState : AbstractSceneState { void Initialize(size_t music_index) { music_index_ = music_index; music.PlayForPreview(); - - with (owner.title_text_) { - matrix.scale = TitleTextScale; - matrix.translation = - TitleTextTranslation + vec3(-modelWidth/2*matrix.scale.x, 0, 0); - } } override UpdateResult Update(KeyInput input) { owner.lobby_.cube_matrix.rotation += CubeRotationSpeed; diff --git a/src/sj/Text.d b/src/sj/Text.d index 15fc004..59f03bd 100644 --- a/src/sj/Text.d +++ b/src/sj/Text.d @@ -47,31 +47,37 @@ class Text { int bmp_width; size_t glyph_count; foreach (c; text) { - if (c == ' ') continue; - with (gloader) { character = c; Load(face).enforce; } + + const m = &face.glyph.metrics; + const mwidth = m.width *1f / face.max_advance_width; + const mheight = m.height *1f / face.max_advance_width; + const advance = m.horiAdvance *1f / face.max_advance_width; + const bear_x = m.horiBearingX*1f / face.max_advance_width; + const bear_y = m.horiBearingY*1f / face.max_advance_width; + + if (mwidth == 0 || mheight == 0) { + model_width_ += advance; + continue; + } + const bitmap = face.EnforceGlyphBitmap(); const srcsz = vec2i(bitmap.width, bitmap.rows); CopyRawPixels(bitmap.buffer, srcsz, pixels.ptr, texsz, vec2i(bmp_width, 0)); - const m = &face.glyph.metrics; - const bearing_x = m.horiBearingX*1f / m.width * srcsz.x; - const bearing_y = m.horiBearingY*1f / m.height * srcsz.y; - const advance = m.horiAdvance *1f / m.width * srcsz.x; - - const posleft = model_width_ + bearing_x; - const posright = posleft + srcsz.x; - const postop = bearing_y; - const posbottom = postop - srcsz.y; - const uvleft = bmp_width*1f / texsz.x; const uvright = (bmp_width + srcsz.x)*1f / texsz.x; const uvtop = 0f; const uvbottom = srcsz.y*1f / texsz.y; + const posleft = model_width_ + bear_x; + const posright = posleft + mwidth; + const postop = bear_y; + const posbottom = postop - mheight; + *vertices_ptr++ = posleft; *vertices_ptr++ = postop; *vertices_ptr++ = 0;