From 297f56885c413ae6d4a9d7f8386bb37fafe56ceb Mon Sep 17 00:00:00 2001 From: Vicente Ferrari Smith Date: Fri, 16 Jan 2026 14:43:51 +0100 Subject: [PATCH] better! --- assets/test.frag | 2 +- src/client/font.zig | 23 +++++++++++++---------- src/client/main.zig | 12 ++++++------ 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/assets/test.frag b/assets/test.frag index dafce02..b73c8b8 100644 --- a/assets/test.frag +++ b/assets/test.frag @@ -23,5 +23,5 @@ void main() // float x = fract(fragTexCoord.s); // float final = smoothstep(divider - 0.1, divider + 0.1, x); - finalColor = vec4(fragTexCoord, 0.0, 1.0); + finalColor = vec4(1, 1, 0.0, 1.0); } diff --git a/src/client/font.zig b/src/client/font.zig index dde6412..8bfbc01 100644 --- a/src/client/font.zig +++ b/src/client/font.zig @@ -50,6 +50,7 @@ pub const Font = struct { var face = try ft_lib.createFaceMemory(font_data, 0); var glyphs = std.AutoHashMap(u32, Glyph).init(allocator); try face.setCharSize(0, size * 64, 0, 96); + try face.selectCharmap(.unicode); var rects = try std.ArrayList(rp.stbrp_rect).initCapacity(allocator, 1024); defer rects.deinit(allocator); @@ -71,12 +72,16 @@ pub const Font = struct { .format = .uncompressed_grayscale }; - for (0..face.numGlyphs()) |i| { + var iter = face.iterateCharmap(); + while (iter.next()) |char| { + const i = iter.index; + + // for (0..face.numGlyphs()) |i| { try face.loadGlyph(@intCast(i), .{}); const bmp = face.glyph().bitmap(); try rects.append(allocator, .{ - .id = @intCast(face.glyph().glyphIndex()), + .id = @intCast(char),//@intCast(face.glyph().glyphIndex()), .w = @intCast(bmp.width()), .h = @intCast(bmp.rows()), .x = 0, @@ -89,9 +94,9 @@ pub const Font = struct { for (rects.items) |rect| { if (rect.was_packed == 0) continue; - const i : u32 = @intCast(rect.id); - //index := FT_Get_Char_Index(face, xx it); - try face.loadGlyph(i, .{ .render = true }); + const char : u32 = @intCast(rect.id); + const index = face.getCharIndex(char) orelse return error.NoGlyph;// FT_Get_Char_Index(face, xx it); + try face.loadGlyph(index, .{ .render = true }); const bmp = face.glyph().bitmap(); const buf = bmp.buffer() orelse continue; @@ -130,8 +135,8 @@ pub const Font = struct { const glyph = Glyph{ .x = x, .y = y, - .utf32 = @intCast(i), - .index = face.glyph().glyphIndex(), + .utf32 = char, + .index = index, .bearing_x = face.glyph().bitmapLeft(), .bearing_y = face.glyph().bitmapTop(), .width = width, @@ -243,7 +248,6 @@ pub const Font = struct { // glyph : *Glyph = table_find_pointer(*text.font.glyphs, RunGlyph.Id); if (self.glyphs.getPtr(RunGlyph.Id)) |glyph| { - std.log.info("glyph: {}", .{glyph}); var v0 = rl.Vector2.zero(); var v1 = rl.Vector2.zero(); if (count_descent) { @@ -292,7 +296,6 @@ pub const Font = struct { } } - // -> vec2, float, s32 pub fn size_row(self: *Font, str: []const u8, n: i32, max_width: f32) struct {rl.Vector2, f32, i32} { _ = max_width; _ = n; @@ -326,7 +329,7 @@ pub const Font = struct { std.log.info("aah it's wrong!! idk how to handle the error rn!!", .{}); } - if (self.glyphs.getPtr(@intCast(ShapeCodepoint.Codepoint))) |glyph| { + if (self.glyphs.getPtr(@intCast(RunGlyph.Id))) |glyph| { size.y = @max(size.y, @as(f32, @floatFromInt(glyph.height))); // size.x += (ft.mulFix(RunGlyph.AdvanceX, self.face.size().metrics().x_scale) >> 6); size.x += @floatFromInt(ft.mulFix(RunGlyph.AdvanceX, @intCast(self.face.size().metrics().x_scale)) >> 6); diff --git a/src/client/main.zig b/src/client/main.zig index a4ddad7..6bb6c76 100644 --- a/src/client/main.zig +++ b/src/client/main.zig @@ -176,15 +176,10 @@ pub fn main() !void { // Draw //---------------------------------------------------------------------------------- - rl.clearBackground(.sky_blue); + rl.clearBackground(.black); rl.beginDrawing(); - // f.texture.drawPro( - // .{.x = 0, .y = 0, .width = 4096, .height = 4096}, - // .{.x = 0, .y = 0, .width = 512, .height = 512 }, - // .zero(), 0, .white); - rl.beginShaderMode(shader); f.render_text( @@ -224,6 +219,11 @@ pub fn main() !void { // rl.gl.rlEnd(); rl.endShaderMode(); + // f.texture.drawPro( + // .{.x = 0, .y = 0, .width = 4096, .height = 4096}, + // .{.x = 0, .y = 0, .width = 512, .height = 512 }, + // .zero(), 0, .white); + // const connected_text = "Connected"; //const not_connected_text = "Not Connected";