add fix eye -Nan, add font color

This commit is contained in:
fnicon 2026-03-22 09:39:11 +09:00
parent 7899b1444c
commit 0a40f6554e
7 changed files with 37 additions and 6 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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),

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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;