From 85d424f6e54d01e54524cc24e04659b58a18749b Mon Sep 17 00:00:00 2001 From: fnicon Date: Sun, 22 Mar 2026 09:39:11 +0900 Subject: [PATCH] add fix eye -Nan, add font color --- game/include/font/bitmap.h | 1 + game/include/lua_api.h | 3 +++ .../world/top_down_race/system/velocity.lua | 6 ++++- game/main.lua | 1 + game/shader/font.frag | 3 ++- game/src/font/bitmap.cpp | 7 ++++++ game/src/lua_api.cpp | 22 +++++++++++++++---- 7 files changed, 37 insertions(+), 6 deletions(-) diff --git a/game/include/font/bitmap.h b/game/include/font/bitmap.h index c7dc9fc..1921fad 100644 --- a/game/include/font/bitmap.h +++ b/game/include/font/bitmap.h @@ -64,4 +64,5 @@ namespace font::bitmap { int best_font(font_desc const * const descs, int length); void draw_start(font const& font, unsigned int vertex_array_object, unsigned int index_buffer); int draw_string(font const& font, char const * const s, int x, int y); + void set_base_color(float r, float g, float b); } diff --git a/game/include/lua_api.h b/game/include/lua_api.h index 52fbfea..78b2aee 100644 --- a/game/include/lua_api.h +++ b/game/include/lua_api.h @@ -7,6 +7,9 @@ extern "C" { int draw_font_start(); int draw_font(int font_ix, char const * text, int x, int y); + int draw_font(int font_ix, char const * text, int x, int y); + void draw_font_set_base_color(float r, float g, float b); + void draw_line_quad_start(); void draw_line(int x1, int y1, int x2, int y2); void draw_set_color(float r, float g, float b); diff --git a/game/love_src/src/world/top_down_race/system/velocity.lua b/game/love_src/src/world/top_down_race/system/velocity.lua index c182029..ab945ed 100644 --- a/game/love_src/src/world/top_down_race/system/velocity.lua +++ b/game/love_src/src/world/top_down_race/system/velocity.lua @@ -260,7 +260,7 @@ end local function draw_debug(x, y, r, g, b, texts) local font_ix = test.draw_font_start() - test.draw_set_color(r, g, b) + test.draw_font_set_base_color(r, g, b) for _, t in ipairs(texts) do y = y + test.draw_font(font_ix, t, x, y) end @@ -278,6 +278,10 @@ end function system:ui_draw() for _, e in ipairs(self.pool) do local max_speed, min_speed, velocity, accel, brake, grip, steer, inertia, mass, streamline = get(e) + test.draw_line_quad_start() + test.draw_set_color(1.0, 0.0, 0.0) -- r, g, b (0.0 to 1.0) + test.draw_line(100, 100, velocity[1] * 100, velocity[2]* 100) -- x1, y1, x2, y2 + draw_debug(640, 0, 1.0, 0.0, 1.0, { string.format("%s max_speed : %s", (debug_current == 1 and ">") or "", max_speed), string.format("%s max_speed : %s", (debug_current == 21 and ">") or "", min_speed), diff --git a/game/main.lua b/game/main.lua index a880e74..c4beeb1 100644 --- a/game/main.lua +++ b/game/main.lua @@ -26,6 +26,7 @@ void update(float time); int draw_font_start(); int draw_font(int font_ix, char const * text, int x, int y); + void draw_font_set_base_color(float r, float g, float b); void draw_line_quad_start(); void draw_line(int x1, int y1, int x2, int y2); diff --git a/game/shader/font.frag b/game/shader/font.frag index af8d1db..71f2d72 100644 --- a/game/shader/font.frag +++ b/game/shader/font.frag @@ -4,6 +4,7 @@ uniform sampler2D TextureSampler; uniform vec2 Cell; uniform vec2 Glyph; +uniform vec3 BaseColor; out vec4 g_color; @@ -14,5 +15,5 @@ void main() vec4 sample = texture(TextureSampler, PixelTexture.xy * Cell + Cell * Glyph); float px = sample.x == 0.0 ? 0.0 : 1.0; - g_color = vec4(vec3(px), 1.0); + g_color = vec4(vec3(px) * BaseColor, 1.0); } diff --git a/game/src/font/bitmap.cpp b/game/src/font/bitmap.cpp index 541f2dc..d30e699 100644 --- a/game/src/font/bitmap.cpp +++ b/game/src/font/bitmap.cpp @@ -18,6 +18,7 @@ namespace font::bitmap { unsigned int texture_sampler; unsigned int cell; unsigned int glyph; + unsigned int base_color; } uniform; }; @@ -35,6 +36,7 @@ namespace font::bitmap { location.uniform.texture_sampler = glGetUniformLocation(program, "TextureSampler"); location.uniform.cell = glGetUniformLocation(program, "Cell"); location.uniform.glyph = glGetUniformLocation(program, "Glyph"); + location.uniform.base_color = glGetUniformLocation(program, "BaseColor"); printf("font program:\n"); printf(" uniforms:\n transform %u\n texture_sampler %u\n cell %u\n glyph %u\n", location.uniform.transform, @@ -166,4 +168,9 @@ namespace font::bitmap { } return x; } + + void set_base_color(float r, float g, float b) + { + glUniform3f(location.uniform.base_color, r, g, b); + } } diff --git a/game/src/lua_api.cpp b/game/src/lua_api.cpp index 36bf311..efb3554 100644 --- a/game/src/lua_api.cpp +++ b/game/src/lua_api.cpp @@ -23,6 +23,11 @@ int draw_font(int font_ix, char const * text, int x, int y) return ter_best.desc->glyph_height; } +void draw_font_set_base_color(float r, float g, float b) +{ + font::bitmap::set_base_color(r, g, b); +} + void draw_line_quad_start() { pixel_line_art::draw_line_quad_start(); @@ -45,12 +50,21 @@ void draw_quad(int x1, int y1, int x2, int y2, x3, y3, x4, y4); } +inline constexpr bool vector_equal(XMVECTOR V1, XMVECTOR V2) +{ + uint32_t CR; + XMVectorEqualR(&CR, V1, V2); + return XMComparisonAllTrue(CR); +} + void set_sphere(float x, float y, float vx, float vy) { - XMVECTOR unit = XMVectorSet(1, 0, 0, 0); // the angle==0 unit vector - view::state.forward = XMVector3Normalize(XMVectorSet(vx, vy, 0, 0)); - view::state.normal = view::get_normal(); - view::state.direction = view::get_direction(); + if (!vector_equal(XMVectorSet(vx, vy, 0, 0), XMVectorZero())) { + XMVECTOR unit = XMVectorSet(1, 0, 0, 0); // the angle==0 unit vector + view::state.forward = XMVector3Normalize(XMVectorSet(vx, vy, 0, 0)); + view::state.normal = view::get_normal(); + view::state.direction = view::get_direction(); + } view::state.at = XMVectorSet(x, y, 52, 0); view::state.eye = view::state.at - view::state.direction * view::at_distance;