diff --git a/build.zig b/build.zig index a792d3a..759718e 100644 --- a/build.zig +++ b/build.zig @@ -146,7 +146,7 @@ pub fn build(b: *std.Build) void { const raylib_dep = b.dependency("raylib", .{ .target = target, .optimize = optimize }); const raylib = raylib_dep.artifact("raylib"); - // raylib.root_module.addCMacro("SUPPORT_CUSTOM_FRAME_CONTROL", ""); + raylib.root_module.addCMacro("SUPPORT_CUSTOM_FRAME_CONTROL", ""); client.linkLibrary(raylib); b.installArtifact(client); diff --git a/src/client/font.zig b/src/client/font.zig index 8fbc5af..aa208af 100644 --- a/src/client/font.zig +++ b/src/client/font.zig @@ -12,28 +12,29 @@ pub var shader : c.Shader = undefined; const ATLAS_SIZE = 4096; const Glyph = struct { - utf32 : u32, index : u32, x : i16, y : i16, width : i32, height : i32, - // dpi_width : i32, - // dpi_height : i32, + dpi_width : f32, + dpi_height : f32, // rwidth : i16, // rheight : i16, bearing_x : i32, bearing_y : i32, - // dpi_bearing_x : i32, - // dpi_bearing_y : i32, + dpi_bearing_x : f32, + dpi_bearing_y : f32, // y_max : i16, // y_min : i16, - ascent : i32, descent : i32, + ascent : i32, + dpi_descent : f32, + dpi_ascent : f32, // advance : i16, st0 : c.Vector2, @@ -48,20 +49,18 @@ pub const Font = struct { kb : kb.kbts_font, texture : c.Texture2D, // texture : rl.Texture2D, - font_data : []u8, pub fn init(filename : []const u8, size : i32, allocator: std.mem.Allocator) !Font { - // const pixel_size = size * 96.0 / 72.0; const font_data = try std.fs.cwd().readFileAlloc(allocator, filename, 10 * 1024 * 1024); var face = try ft_lib.createFaceMemory(font_data, 0); var glyphs = std.AutoHashMap(u32, Glyph).init(allocator); - try face.setCharSize(0, size * 64, 0, 72 * @as(u16, @intFromFloat(c.GetWindowScaleDPI().y))); - // try face.setPixelSizes(0, @intCast(size)); + try face.setCharSize(0, size * 64, 0, 96 * @as(u16, @intFromFloat(c.GetWindowScaleDPI().y))); + // try face.setPixelSizes(0, @intCast(size * @as(u16, @intFromFloat(c.GetWindowScaleDPI().y)))); // try face.setCharSize(0, size * 64, 0, 72 * @as(u16, @intFromFloat(rl.getWindowScaleDPI().y))); - // try face.setCharSize(0, size * 64, 0, 72 * 1); + // try face.setCharSize(0, size * 64, 0, 0); try face.selectCharmap(.unicode); var rects = try std.ArrayList(rp.stbrp_rect).initCapacity(allocator, 1024); @@ -85,16 +84,17 @@ pub const Font = struct { .format = c.PIXELFORMAT_UNCOMPRESSED_GRAYSCALE, }; - var iter = face.iterateCharmap(); - while (iter.next()) |char| { - const i = iter.index; + // var iter = face.iterateCharmap(); + // while (iter.next()) |char| { + for (0..face.numGlyphs()) |index| { + // const i = iter.index; // for (0..face.numGlyphs()) |i| { - try face.loadGlyph(@intCast(i), .{}); + try face.loadGlyph(@intCast(index), .{}); const bmp = face.glyph().bitmap(); try rects.append(allocator, .{ - .id = @intCast(char),//@intCast(face.glyph().glyphIndex()), + .id = @intCast(index),//@intCast(face.glyph().glyphIndex()), .w = @intCast(bmp.width()), .h = @intCast(bmp.rows()), .x = 0, @@ -106,9 +106,8 @@ pub const Font = struct { _ = rp.stbrp_pack_rects(&stbrpcontext, rects.items.ptr, @intCast(rects.items.len)); for (rects.items) |rect| { + const index : u32 = @intCast(rect.id); if (rect.was_packed == 0) continue; - 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(); @@ -130,14 +129,32 @@ pub const Font = struct { @memcpy(dst, src); } - const width : i32 = @intCast(bmp.width()); - const height : i32 = @intCast(bmp.rows()); - // const dpi_width : i32 = @intFromFloat(@as(f32, @floatFromInt(width)) / rl.getWindowScaleDPI().x); - // const dpi_height : i32 = @intFromFloat(@as(f32, @floatFromInt(height)) / rl.getWindowScaleDPI().y); - const bearing_x : i32 = face.glyph().bitmapLeft(); - const bearing_y : i32 = face.glyph().bitmapTop(); - const descent : i32 = height - bearing_y; - const ascent : i32 = @as(i32, @intCast(height)) - descent; + // std.log.info("{}", .{bmp.width()}); + const width : i32 = @intCast(bmp.width()); + // std.log.info("{}", .{bmp.rows()}); + const height : i32 = @intCast(bmp.rows()); + // const dpi_width : i32 = @intFromFloat(@as(f32, @floatFromInt(width)) / rl.getWindowScaleDPI().x); + // const dpi_height : i32 = @intFromFloat(@as(f32, @floatFromInt(height)) / rl.getWindowScaleDPI().y); + // std.log.info("{}", .{@as(f32, @floatFromInt(width)) / c.GetWindowScaleDPI().x}); + const dpi_width : f32 = @as(f32, @floatFromInt(width)) / c.GetWindowScaleDPI().x; + // std.log.info("{}", .{@as(f32, @floatFromInt(height)) / c.GetWindowScaleDPI().y}); + const dpi_height : f32 = @as(f32, @floatFromInt(height)) / c.GetWindowScaleDPI().y; + // std.log.info("{}", .{face.glyph().bitmapLeft()}); + const bearing_x : i32 = face.glyph().bitmapLeft(); + // std.log.info("{}", .{face.glyph().bitmapTop()}); + const bearing_y : i32 = face.glyph().bitmapTop(); + // std.log.info("{}", .{@as(f32, @floatFromInt(bearing_x)) / c.GetWindowScaleDPI().x}); + const dpi_bearing_x : f32 = @as(f32, @floatFromInt(bearing_x)) / c.GetWindowScaleDPI().x; + // std.log.info("{}", .{@as(f32, @floatFromInt(bearing_y)) / c.GetWindowScaleDPI().y}); + const dpi_bearing_y : f32 = @as(f32, @floatFromInt(bearing_y)) / c.GetWindowScaleDPI().y; + // std.log.info("{}", .{height - bearing_y}); + const descent : i32 = height - bearing_y; + // std.log.info("{}", .{height - descent}); + const ascent : i32 = height - descent; + // std.log.info("{}", .{dpi_height - dpi_bearing_y}); + const dpi_descent : f32 = dpi_height - dpi_bearing_y; + // std.log.info("{}", .{dpi_height - dpi_descent}); + const dpi_ascent : f32 = dpi_height - dpi_descent; const x : i16 = @intCast(rect.x); const y : i16 = @as(i16, @intCast(rect.y)) + @as(i16, @intCast(height)); @@ -151,23 +168,24 @@ pub const Font = struct { const glyph = Glyph{ .x = x, .y = y, - .utf32 = char, .index = index, .bearing_x = bearing_x, .bearing_y = bearing_y, - // .dpi_bearing_x = @as(i32, @intFromFloat(@as(f32, @floatFromInt(bearing_x)) / rl.getWindowScaleDPI().x)), - // .dpi_bearing_y = @as(i32, @intFromFloat(@as(f32, @floatFromInt(bearing_y)) / rl.getWindowScaleDPI().y)), + .dpi_bearing_x = dpi_bearing_x, + .dpi_bearing_y = dpi_bearing_y, .width = width, .height = height, - // .dpi_width = dpi_width, - // .dpi_height = dpi_height, + .dpi_width = dpi_width, + .dpi_height = dpi_height, // .rwidth = @intCast(face.glyph().metrics().width >> 6), // .rheight = @intCast(face.glyph().metrics().height >> 6), .descent = descent, .ascent = ascent, + .dpi_descent = dpi_descent, + .dpi_ascent = dpi_ascent, // .advance = @intCast(face.glyph().advance().x >> 6), - .st0 = .{.x = (fx + 0.5) / fs, .y = (fy - fh) / fs}, - .st1 = .{.x = (fx + fw) / fs, .y = (fy - 0.5) / fs}, + .st0 = .{.x = (fx + 0.5) / fs, .y = (fy - fh + 0.5) / fs}, + .st1 = .{.x = (fx + fw - 0.5) / fs, .y = (fy - 0.5) / fs}, }; try glyphs.put(glyph.index, glyph); @@ -182,16 +200,17 @@ pub const Font = struct { std.log.info("[Error] [kb_text_shape] Failed to load the font.", .{}); } + allocator.free(font_data); + return .{ .face = face, .glyphs = glyphs, .kb = _kb, .texture = texture, - .font_data = font_data, }; } - pub fn deinit(self: *Font, allocator: std.mem.Allocator) void { + pub fn deinit(self: *Font) void { // var it = self.glyphs.valueIterator(); // while (it.next()) |g| { // allocator.free(g.bitmap); @@ -201,7 +220,6 @@ pub const Font = struct { kb.kbts_FreeFont(&self.kb); c.UnloadTexture(self.texture); // self.texture.unload(); - allocator.free(self.font_data); } pub fn render_text( @@ -248,7 +266,7 @@ pub const Font = struct { render_pos.y += font_ascent; - c.DrawLine(@intFromFloat(render_pos.x), @intFromFloat(render_pos.y), c.GetScreenWidth(), @intFromFloat(render_pos.y), c.RED); + // c.DrawLine(@intFromFloat(render_pos.x), @intFromFloat(render_pos.y), c.GetScreenWidth(), @intFromFloat(render_pos.y), c.RED); // rl.drawLine(@intFromFloat(render_pos.x), @intFromFloat(render_pos.y), rl.getScreenWidth(), @intFromFloat(render_pos.y), .red); const Context = kb.kbts_CreateShapeContext(null, null); @@ -290,6 +308,8 @@ pub const Font = struct { const advance_x = @as(f32, @floatFromInt(ft.mulFix(RunGlyph.AdvanceX, @intCast(self.face.size().metrics().x_scale)) >> 6)); const advance_y = @as(f32, @floatFromInt(ft.mulFix(RunGlyph.AdvanceY, @intCast(self.face.size().metrics().y_scale)) >> 6)); + const dpi_advance_x = advance_x / c.GetWindowScaleDPI().x; + const dpi_advance_y = advance_y / c.GetWindowScaleDPI().y; // const dpi_advance_x = advance_x / rl.getWindowScaleDPI().x; // const dpi_advance_y = advance_y / rl.getWindowScaleDPI().y; @@ -298,7 +318,7 @@ pub const Font = struct { var v0 = c.Vector2{}; var v1 = c.Vector2{}; // const bx = @as(f32, @floatFromInt(glyph.bearing_x)); - const by = @as(f32, @floatFromInt(glyph.bearing_y)); + const by = glyph.dpi_bearing_y; // const height = @as(f32, @floatFromInt(glyph.height)); // const descent = @as(f32, @floatFromInt(glyph.descent)); // const ascent = @as(f32, @floatFromInt(glyph.ascent)); @@ -314,14 +334,14 @@ pub const Font = struct { // });//* - glyph.height + draw_size.y*/}; // } - v1 = c.Vector2Add(v0, c.Vector2{ .x = @floatFromInt(glyph.width), .y = @floatFromInt(glyph.height) }); + v1 = c.Vector2Add(v0, c.Vector2{ .x = glyph.dpi_width, .y = glyph.dpi_height }); // v1 = v0.add(rl.Vector2{ .x = @floatFromInt(glyph.width), .y = @floatFromInt(glyph.height) }); const p0 : c.Vector4 = .{ .x = v0.x, .y = v0.y, .z = 0.0, .w = 1.0 }; const p1 : c.Vector4 = .{ .x = v1.x, .y = v1.y, .z = 0.0, .w = 1.0 }; // const p0 : rl.Vector4 = .{ .x = v0.x, .y = v0.y, .z = 0.0, .w = 1.0 }; // const p1 : rl.Vector4 = .{ .x = v1.x, .y = v1.y, .z = 0.0, .w = 1.0 }; - x_offset += advance_x; - y_offset += advance_y; + x_offset += dpi_advance_x; + y_offset += dpi_advance_y; // #if Y_IS_UP { // t0 := Vector2.{ @@ -354,8 +374,9 @@ pub const Font = struct { // rl.gl.rlTexCoord2f(st1.x, st1.y); rl.gl.rlVertex2f(p1.x, p1.y); // rl.gl.rlTexCoord2f(st1.x, st0.y); rl.gl.rlVertex2f(p1.x, p0.y); } else { - x_offset += advance_x; - y_offset += advance_y; + std.log.warn("kb_text_shape found the glyph, but we didn't load it from the font.", .{}); + x_offset += dpi_advance_x; + y_offset += dpi_advance_y; continue; } } @@ -403,7 +424,7 @@ pub const Font = struct { } if (self.glyphs.getPtr(@intCast(RunGlyph.Id))) |glyph| { - size.y = @max(size.y, @as(f32, @floatFromInt(glyph.height))); + size.y = @max(size.y, @as(f32, @floatFromInt(glyph.dpi_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); max_descent = @max(max_descent, @as(f32, @floatFromInt(glyph.descent))); diff --git a/src/client/main.zig b/src/client/main.zig index b5e8eee..3fcd281 100644 --- a/src/client/main.zig +++ b/src/client/main.zig @@ -1,371 +1,371 @@ -// const std = @import("std"); -// const zm = @import("zmath"); -// const znet = @import("znet"); -// // const rl = @import("raylib"); -// const bufzilla = @import("bufzilla"); -// const ft = @import("freetype"); - -// const c = @import("c.zig").c; - -// const shared = @import("shared"); - -// const client = @import("client.zig"); -// const entity = @import("entity.zig"); -// const misc = @import("misc.zig"); -// const font = @import("font.zig"); - -// const dt : f32 = 1.0 / 200.0; -// var t : f32 = 0; -// var gt : f32 = 0; -// var accumulator : f32 = 0; -// var k : f32 = 1; -// var frame : i32 = 0; +const std = @import("std"); +const zm = @import("zmath"); +const znet = @import("znet"); +// const rl = @import("raylib"); +const bufzilla = @import("bufzilla"); +const ft = @import("freetype"); + +const c = @import("c.zig").c; + +const shared = @import("shared"); + +const client = @import("client.zig"); +const entity = @import("entity.zig"); +const misc = @import("misc.zig"); +const font = @import("font.zig"); + +const dt : f32 = 1.0 / 200.0; +var t : f32 = 0; +var gt : f32 = 0; +var accumulator : f32 = 0; +var k : f32 = 1; +var frame : i32 = 0; -// const screen_width = 1280; -// const screen_height = 720; +const screen_width = 1280; +const screen_height = 720; -// var running: bool = true; - -// var dbg_allocator: std.heap.DebugAllocator(.{}) = undefined; -// const allocator = dbg_allocator.allocator(); +var running: bool = true; + +var dbg_allocator: std.heap.DebugAllocator(.{}) = undefined; +const allocator = dbg_allocator.allocator(); -// var stdout: *std.io.Writer = undefined; - -// // var connection: ?std.net.Stream = undefined; +var stdout: *std.io.Writer = undefined; + +// var connection: ?std.net.Stream = undefined; -// pub fn main() !void { -// std.log.info("Hello Client!", .{}); +pub fn main() !void { + std.log.info("Hello Client!", .{}); -// try init(); -// defer _ = dbg_allocator.deinit(); -// try znet.init(); -// defer znet.deinit(); -// c.SetConfigFlags(c.FLAG_WINDOW_HIGHDPI); -// // rl.setConfigFlags(.{ .window_highdpi = true }); -// c.InitWindow(screen_width, screen_height, "zzz"); -// // rl.initWindow(screen_width, screen_height, "zzz"); -// defer c.CloseWindow(); -// // defer rl.closeWindow(); - -// font.ft_lib = try ft.Library.init(); + try init(); + defer _ = dbg_allocator.deinit(); + try znet.init(); + defer znet.deinit(); + c.SetConfigFlags(c.FLAG_WINDOW_HIGHDPI); + // rl.setConfigFlags(.{ .window_highdpi = true }); + c.InitWindow(screen_width, screen_height, "zzz"); + // rl.initWindow(screen_width, screen_height, "zzz"); + defer c.CloseWindow(); + // defer rl.closeWindow(); + + font.ft_lib = try ft.Library.init(); -// // std.log.debug("screen ? {}", .{rl.getScreenWidth()}); -// // std.log.debug("screen ? {}", .{rl.getScreenHeight()}); -// // std.log.debug("render ? {}", .{rl.getRenderWidth()}); -// // std.log.debug("render ? {}", .{rl.getRenderHeight()}); - -// // std.log.debug("what's being used for viewport ? {}", .{rl.RLGL.State.framebufferWidth}); - -// var f = try font.Font.init("assets/fonts/Vollkorn/static/Vollkorn-Regular.ttf", 42, allocator); -// defer f.deinit(allocator); - -// font.shader = c.LoadShader(null, "assets/text.frag"); -// // const test_shader1 = try c.LoadShader(null, "assets/test_1.frag"); -// // const test_shader2 = try c.LoadShader(null, "assets/test_2.frag"); - -// // font.shader = try rl.loadShader(null, "assets/text.frag"); -// // const test_shader1 = try rl.loadShader(null, "assets/test_1.frag"); -// // const test_shader2 = try rl.loadShader(null, "assets/test_2.frag"); - -// // const img = rl.genImageColor(32, 32, .blank); -// // const tx = try rl.loadTextureFromImage(img); -// // rl.unloadImage(img); - -// const host = try znet.Host.init(.{ -// .addr = null, -// .peer_limit = 1, -// .channel_limit = .max, -// .incoming_bandwidth = .unlimited, -// .outgoing_bandwidth = .unlimited, -// }); -// defer host.deinit(); - -// // const peer = try host.connect(.{ -// // .addr = try .init(.{ -// // .ip = .{ .ipv4 = "127.0.0.1" }, -// // .port = .{ .uint = 5000 }, -// // }), -// // .channel_limit = .max, -// // .data = 0, -// // }); + // std.log.debug("screen ? {}", .{rl.getScreenWidth()}); + // std.log.debug("screen ? {}", .{rl.getScreenHeight()}); + // std.log.debug("render ? {}", .{rl.getRenderWidth()}); + // std.log.debug("render ? {}", .{rl.getRenderHeight()}); + + // std.log.debug("what's being used for viewport ? {}", .{rl.RLGL.State.framebufferWidth}); + + var f = try font.Font.init("assets/fonts/Vollkorn/static/Vollkorn-Regular.ttf", 7, allocator); + defer f.deinit(); + + font.shader = c.LoadShader(null, "assets/text.frag"); + // const test_shader1 = try c.LoadShader(null, "assets/test_1.frag"); + // const test_shader2 = try c.LoadShader(null, "assets/test_2.frag"); + + // font.shader = try rl.loadShader(null, "assets/text.frag"); + // const test_shader1 = try rl.loadShader(null, "assets/test_1.frag"); + // const test_shader2 = try rl.loadShader(null, "assets/test_2.frag"); + + // const img = rl.genImageColor(32, 32, .blank); + // const tx = try rl.loadTextureFromImage(img); + // rl.unloadImage(img); + + const host = try znet.Host.init(.{ + .addr = null, + .peer_limit = 1, + .channel_limit = .max, + .incoming_bandwidth = .unlimited, + .outgoing_bandwidth = .unlimited, + }); + defer host.deinit(); + + // const peer = try host.connect(.{ + // .addr = try .init(.{ + // .ip = .{ .ipv4 = "127.0.0.1" }, + // .port = .{ .uint = 5000 }, + // }), + // .channel_limit = .max, + // .data = 0, + // }); -// // connect() catch |err| switch (err) { -// // error.ConnectionRefused => { -// // std.log.err("server refused connection", .{}); -// // }, -// // else => { -// // std.log.err("unexpected connect error: {}", .{err}); -// // return err; -// // }, -// // }; - -// // try stdout.flush(); - -// var the_chunk = try shared.chunk.initChunk(allocator); -// defer shared.chunk.deinitChunk(&the_chunk, allocator); + // connect() catch |err| switch (err) { + // error.ConnectionRefused => { + // std.log.err("server refused connection", .{}); + // }, + // else => { + // std.log.err("unexpected connect error: {}", .{err}); + // return err; + // }, + // }; + + // try stdout.flush(); + + var the_chunk = try shared.chunk.initChunk(allocator); + defer shared.chunk.deinitChunk(&the_chunk, allocator); -// shared.chunk.updateChunk(&the_chunk); + shared.chunk.updateChunk(&the_chunk); -// //var elf = entity.Elf.init(); - -// // var send_buf: [1024]u8 = undefined; -// // var writer = if (connection) |*conn| conn.writer(&send_buf) else return; - -// // try shared.protocol.sendHello(&writer.interface, .{ .msg = "Hello from client" }); - -// // var recv_buf: [1024]u8 = undefined; -// // var reader = if (connection) |*conn| conn.reader(&recv_buf) else return; -// // const line = try reader.interface().takeDelimiterExclusive('\n'); -// // std.log.info("{s}", .{line}); - -// // const camera = rl.Camera{ .fovy = 45, .position = .{ .x = 0, .y = 0, .z = 10 }, .projection = .perspective, .target = .{ .x = 0, .y = 0, .z = 0 }, .up = .{ .x = 0, .y = 1, .z = 0 } }; - -// // rl.initAudioDevice(); - -// // if (rl.isAudioDeviceReady()) { -// // std.log.info("audio device is ready!", .{}); -// // } else { -// // std.log.info("audio device is NOT ready!", .{}); -// // } - -// // const music = try rl.loadMusicStream("assets/romantic-piano-431010.mp3"); -// // std.log.info("{}", .{rl.isMusicValid(music)}); -// // rl.playMusicStream(music); -// // std.log.info("is music playing? {}", .{rl.isMusicStreamPlaying(music)}); - -// var old_time : f32 = @floatCast(c.GetTime()); -// // var old_time : f32 = @floatCast(rl.getTime()); - -// while (!c.WindowShouldClose()) { -// // while (!rl.windowShouldClose()) { // Detect window close button or ESC key -// const new_time : f32 = @floatCast(c.GetTime()); -// // const new_time : f32 = @floatCast(rl.getTime()); -// var frame_time = new_time - old_time; -// old_time = new_time; - -// if (frame_time > 0.25) -// frame_time = 0.25; - -// t += frame_time; -// accumulator += frame_time * k; - -// // std.log.info("t: {}", .{t}); - -// while (try host.service(0)) |event| switch (event) { -// .connect => |data| { -// _ = data; -// // std.log.info("{}", .{data.peer}); -// }, -// .disconnect => |data| { -// _ = data; -// // std.log.info("{}", .{data.peer}); -// }, -// .receive => |data| { -// defer data.packet.deinit(); - -// const slice = data.packet.dataSlice(); - -// var reader = bufzilla.Reader(.{}).init(slice); - -// const id = try reader.readPath("id"); - -// std.log.info("{any}", .{id}); -// }, -// }; - -// c.PollInputEvents(); -// // rl.pollInputEvents(); - -// // if (peer.state() == .connected) { -// // const packet = try znet.Packet.init("Hello, Server!", 0, .reliable); -// // try peer.send(packet); -// // } -// // // _ = peer; - -// // // Update -// // //---------------------------------------------------------------------------------- -// // // TODO: Update your variables here -// // //---------------------------------------------------------------------------------- - -// // rl.updateMusicStream(music); - -// // while (accumulator > dt * k) { -// // // update(dt * cast(float) k); -// // accumulator -= dt * k; -// // gt += dt * k; -// // } + //var elf = entity.Elf.init(); + + // var send_buf: [1024]u8 = undefined; + // var writer = if (connection) |*conn| conn.writer(&send_buf) else return; + + // try shared.protocol.sendHello(&writer.interface, .{ .msg = "Hello from client" }); + + // var recv_buf: [1024]u8 = undefined; + // var reader = if (connection) |*conn| conn.reader(&recv_buf) else return; + // const line = try reader.interface().takeDelimiterExclusive('\n'); + // std.log.info("{s}", .{line}); + + // const camera = rl.Camera{ .fovy = 45, .position = .{ .x = 0, .y = 0, .z = 10 }, .projection = .perspective, .target = .{ .x = 0, .y = 0, .z = 0 }, .up = .{ .x = 0, .y = 1, .z = 0 } }; + + // rl.initAudioDevice(); + + // if (rl.isAudioDeviceReady()) { + // std.log.info("audio device is ready!", .{}); + // } else { + // std.log.info("audio device is NOT ready!", .{}); + // } + + // const music = try rl.loadMusicStream("assets/romantic-piano-431010.mp3"); + // std.log.info("{}", .{rl.isMusicValid(music)}); + // rl.playMusicStream(music); + // std.log.info("is music playing? {}", .{rl.isMusicStreamPlaying(music)}); + + var old_time : f32 = @floatCast(c.GetTime()); + // var old_time : f32 = @floatCast(rl.getTime()); + + while (!c.WindowShouldClose()) { + // while (!rl.windowShouldClose()) { // Detect window close button or ESC key + const new_time : f32 = @floatCast(c.GetTime()); + // const new_time : f32 = @floatCast(rl.getTime()); + var frame_time = new_time - old_time; + old_time = new_time; + + if (frame_time > 0.25) + frame_time = 0.25; + + t += frame_time; + accumulator += frame_time * k; + + // std.log.info("t: {}", .{t}); + + while (try host.service(0)) |event| switch (event) { + .connect => |data| { + _ = data; + // std.log.info("{}", .{data.peer}); + }, + .disconnect => |data| { + _ = data; + // std.log.info("{}", .{data.peer}); + }, + .receive => |data| { + defer data.packet.deinit(); + + const slice = data.packet.dataSlice(); + + var reader = bufzilla.Reader(.{}).init(slice); + + const id = try reader.readPath("id"); + + std.log.info("{any}", .{id}); + }, + }; + + c.PollInputEvents(); + // rl.pollInputEvents(); + + // if (peer.state() == .connected) { + // const packet = try znet.Packet.init("Hello, Server!", 0, .reliable); + // try peer.send(packet); + // } + // // _ = peer; + + // // Update + // //---------------------------------------------------------------------------------- + // // TODO: Update your variables here + // //---------------------------------------------------------------------------------- + + // rl.updateMusicStream(music); + + // while (accumulator > dt * k) { + // // update(dt * cast(float) k); + // accumulator -= dt * k; + // gt += dt * k; + // } -// // // Draw -// // //---------------------------------------------------------------------------------- -// c.BeginDrawing(); -// c.ClearBackground(c.SKYBLUE); -// // rl.clearBackground(.black); + // // Draw + // //---------------------------------------------------------------------------------- + c.BeginDrawing(); + c.ClearBackground(c.SKYBLUE); + // rl.clearBackground(.black); -// // rl.beginDrawing(); + // rl.beginDrawing(); -// // // rl.drawRectangle(screen_width - 100, 0, 100, 100, .red); - -// f.render_text( -// "Whereas, disregard and contempt for human rights have resulted!", -// c.Vector2{ .x = 0, .y = 0}, -// true, -// c.WHITE, -// c.BLANK, -// false, -// true -// ); -// // f.render_text( -// // "Whereas, disregard and contempt for human rights have resulted!", -// // rl.Vector2.init(0, 0), -// // true, -// // rl.Color.white, -// // rl.Color.blank, -// // false, -// // true -// // ); - -// // // rl.beginShaderMode(test_shader1); -// // // rl.gl.rlBegin(rl.gl.rl_quads); - -// // // { -// // // const topLeft : rl.Vector2 = .{ .x = 0.0, .y = 0.0 }; -// // // const bottomRight : rl.Vector2 = .{ .x = @as(f32, @floatFromInt(rl.getScreenWidth())) / 2.0, .y = @as(f32, @floatFromInt(rl.getScreenHeight())) }; - -// // // rl.gl.rlVertex2f(topLeft.x, topLeft.y); -// // // rl.gl.rlVertex2f(topLeft.x, bottomRight.y); -// // // rl.gl.rlVertex2f(bottomRight.x, bottomRight.y); -// // // rl.gl.rlVertex2f(bottomRight.x, topLeft.y); + // // rl.drawRectangle(screen_width - 100, 0, 100, 100, .red); + + f.render_text( + "Whereas, disregard and contempt for human rights have resulted!fi", + c.Vector2{ .x = 0, .y = 0}, + true, + c.WHITE, + c.BLANK, + false, + true + ); + // f.render_text( + // "Whereas, disregard and contempt for human rights have resulted!", + // rl.Vector2.init(0, 0), + // true, + // rl.Color.white, + // rl.Color.blank, + // false, + // true + // ); + + // // rl.beginShaderMode(test_shader1); + // // rl.gl.rlBegin(rl.gl.rl_quads); + + // // { + // // const topLeft : rl.Vector2 = .{ .x = 0.0, .y = 0.0 }; + // // const bottomRight : rl.Vector2 = .{ .x = @as(f32, @floatFromInt(rl.getScreenWidth())) / 2.0, .y = @as(f32, @floatFromInt(rl.getScreenHeight())) }; + + // // rl.gl.rlVertex2f(topLeft.x, topLeft.y); + // // rl.gl.rlVertex2f(topLeft.x, bottomRight.y); + // // rl.gl.rlVertex2f(bottomRight.x, bottomRight.y); + // // rl.gl.rlVertex2f(bottomRight.x, topLeft.y); + + // // } + + // // rl.gl.rlEnd(); + // // rl.endShaderMode(); -// // // } - -// // // rl.gl.rlEnd(); -// // // rl.endShaderMode(); + // // rl.beginShaderMode(test_shader2); + // // rl.gl.rlBegin(rl.gl.rl_quads); -// // // rl.beginShaderMode(test_shader2); -// // // rl.gl.rlBegin(rl.gl.rl_quads); + // // { + // // const topLeft : rl.Vector2 = .{ .x = @as(f32, @floatFromInt(rl.getScreenWidth())) / 2.0, .y = 0 }; + // // const bottomRight : rl.Vector2 = .{ .x = @floatFromInt(rl.getScreenWidth()), .y = @floatFromInt(rl.getScreenHeight()) }; -// // // { -// // // const topLeft : rl.Vector2 = .{ .x = @as(f32, @floatFromInt(rl.getScreenWidth())) / 2.0, .y = 0 }; -// // // const bottomRight : rl.Vector2 = .{ .x = @floatFromInt(rl.getScreenWidth()), .y = @floatFromInt(rl.getScreenHeight()) }; + // // rl.gl.rlVertex2f(topLeft.x, topLeft.y); + // // rl.gl.rlVertex2f(topLeft.x, bottomRight.y); + // // rl.gl.rlVertex2f(bottomRight.x, bottomRight.y); + // // rl.gl.rlVertex2f(bottomRight.x, topLeft.y); + // // } + + // // rl.gl.rlEnd(); + // // rl.endShaderMode(); -// // // rl.gl.rlVertex2f(topLeft.x, topLeft.y); -// // // rl.gl.rlVertex2f(topLeft.x, bottomRight.y); -// // // rl.gl.rlVertex2f(bottomRight.x, bottomRight.y); -// // // rl.gl.rlVertex2f(bottomRight.x, topLeft.y); -// // // } - -// // // rl.gl.rlEnd(); -// // // rl.endShaderMode(); + // // rl.beginShaderMode(test_shader2); + // // rl.gl.rlBegin(rl.gl.rl_quads); -// // // rl.beginShaderMode(test_shader2); -// // // rl.gl.rlBegin(rl.gl.rl_quads); + // // { + // // const topLeft : rl.Vector2 = .{ .x = @as(f32, @floatFromInt(rl.getScreenWidth())) / 2.0, .y = 0 }; + // // const bottomRight : rl.Vector2 = .{ .x = @floatFromInt(rl.getScreenWidth()), .y = @floatFromInt(rl.getScreenHeight()) }; -// // // { -// // // const topLeft : rl.Vector2 = .{ .x = @as(f32, @floatFromInt(rl.getScreenWidth())) / 2.0, .y = 0 }; -// // // const bottomRight : rl.Vector2 = .{ .x = @floatFromInt(rl.getScreenWidth()), .y = @floatFromInt(rl.getScreenHeight()) }; + // // rl.gl.rlVertex2f(topLeft.x, topLeft.y); + // // rl.gl.rlVertex2f(topLeft.x, bottomRight.y); + // // rl.gl.rlVertex2f(bottomRight.x, bottomRight.y); + // // rl.gl.rlVertex2f(bottomRight.x, topLeft.y); + // // } + + // // rl.gl.rlEnd(); + // // rl.endShaderMode(); -// // // rl.gl.rlVertex2f(topLeft.x, topLeft.y); -// // // rl.gl.rlVertex2f(topLeft.x, bottomRight.y); -// // // rl.gl.rlVertex2f(bottomRight.x, bottomRight.y); -// // // rl.gl.rlVertex2f(bottomRight.x, topLeft.y); -// // // } - -// // // rl.gl.rlEnd(); -// // // rl.endShaderMode(); - -// // // rl.drawRectangle(400, 0, 400, 450, rl.Color{ .r = 54, .g = 54, .b = 54, .a = 255 }); + // // rl.drawRectangle(400, 0, 400, 450, rl.Color{ .r = 54, .g = 54, .b = 54, .a = 255 }); -// // // 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"; - -// // // switch (peer.state()) { -// // // .connected => rl.drawText(connected_text, @divFloor(rl.getScreenWidth(), 2) - @divFloor(rl.measureText(connected_text, f.baseSize), 2), 50, 20, .white), -// // // else => rl.drawText(not_connected_text, @divFloor(rl.getScreenWidth(), 2) - @divFloor(rl.measureText(not_connected_text, f.baseSize), 1), 50, 20, .white), -// // // } -// // //@divFloor(rl.getScreenWidth(), 2) - @divFloor(rl.measureText(connected_text, f.baseSize), 2), 50 + // // 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"; + + // // switch (peer.state()) { + // // .connected => rl.drawText(connected_text, @divFloor(rl.getScreenWidth(), 2) - @divFloor(rl.measureText(connected_text, f.baseSize), 2), 50, 20, .white), + // // else => rl.drawText(not_connected_text, @divFloor(rl.getScreenWidth(), 2) - @divFloor(rl.measureText(not_connected_text, f.baseSize), 1), 50, 20, .white), + // // } + // //@divFloor(rl.getScreenWidth(), 2) - @divFloor(rl.measureText(connected_text, f.baseSize), 2), 50 -// // // // const font_size : i32 = 180; -// // // // const text_size = rl.Vector2{.x = @floatFromInt(rl.measureText(connected_text, font_size)), .y = font_size};//rl.measureTextEx(try rl.getFontDefault(), connected_text, font_size, font_size / 10); -// // // // const pos = rl.Vector2{.x = 0, .y = 0}; -// // // // rl.drawText(connected_text, pos.x, pos.y, font_size, .white); -// // // // rl.drawRectangleLines(pos.x, pos.y, @intFromFloat(text_size.x), @intFromFloat(text_size.y), .red); -// // // // rl.drawRectangle(pos.x, pos.y, rl.getScreenWidth(), rl.getScreenHeight(), .white); -// // // rl.drawTexturePro(tx, -// // // rl.Rectangle{.x = 0, .y = 0, .width = 32, .height = 32}, -// // // rl.Rectangle{.x = 100, .y = 100, .width = 500, .height = 500}, -// // // .{.x = 0, .y = 0}, -// // // 0, -// // // .white); - -// // //rl.drawLineV(.{.x = @floatFromInt(@divFloor(rl.getScreenWidth(), 2)), .y = 0}, .{.x = @floatFromInt(@divFloor(rl.getScreenWidth(), 2)), .y = @floatFromInt(rl.getScreenHeight())}, .red); -// // //rl.drawText("Congrats! You created your first window!", rl.getMouseX(), rl.getMouseY(), 20, .white); -// // //rl.drawRectangleLines(0, 0, 100, 100, .red); -// // // misc.drawFPS(0, 0, frame_time, frame); + // // // const font_size : i32 = 180; + // // // const text_size = rl.Vector2{.x = @floatFromInt(rl.measureText(connected_text, font_size)), .y = font_size};//rl.measureTextEx(try rl.getFontDefault(), connected_text, font_size, font_size / 10); + // // // const pos = rl.Vector2{.x = 0, .y = 0}; + // // // rl.drawText(connected_text, pos.x, pos.y, font_size, .white); + // // // rl.drawRectangleLines(pos.x, pos.y, @intFromFloat(text_size.x), @intFromFloat(text_size.y), .red); + // // // rl.drawRectangle(pos.x, pos.y, rl.getScreenWidth(), rl.getScreenHeight(), .white); + // // rl.drawTexturePro(tx, + // // rl.Rectangle{.x = 0, .y = 0, .width = 32, .height = 32}, + // // rl.Rectangle{.x = 100, .y = 100, .width = 500, .height = 500}, + // // .{.x = 0, .y = 0}, + // // 0, + // // .white); + + // //rl.drawLineV(.{.x = @floatFromInt(@divFloor(rl.getScreenWidth(), 2)), .y = 0}, .{.x = @floatFromInt(@divFloor(rl.getScreenWidth(), 2)), .y = @floatFromInt(rl.getScreenHeight())}, .red); -// // //elf.draw(); + // //rl.drawText("Congrats! You created your first window!", rl.getMouseX(), rl.getMouseY(), 20, .white); + // //rl.drawRectangleLines(0, 0, 100, 100, .red); + // // misc.drawFPS(0, 0, frame_time, frame); -// // // rl.beginMode3D(camera); -// // // rl.drawSphere(.{ .x = 0, .y = 0, .z = 0 }, 1, .red); -// // // rl.endMode3D(); + // //elf.draw(); -// c.EndDrawing(); -// // rl.endDrawing(); + // // rl.beginMode3D(camera); + // // rl.drawSphere(.{ .x = 0, .y = 0, .z = 0 }, 1, .red); + // // rl.endMode3D(); -// // //---------------------------------------------------------------------------------- + c.EndDrawing(); + // rl.endDrawing(); -// c.SwapScreenBuffer(); -// // rl.swapScreenBuffer(); -// } + // //---------------------------------------------------------------------------------- + + c.SwapScreenBuffer(); + // rl.swapScreenBuffer(); + } +} + +fn init() !void { + dbg_allocator = std.heap.DebugAllocator(.{}).init; + var stdout_buffer: [1024]u8 = undefined; + var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer); + stdout = &stdout_writer.interface; + + // font.shader = try rl.loadShader(null, "assets/test.frag"); +} + +fn connect() !void { + // const address = try std.net.Address.parseIp4("127.0.0.1", shared.protocol.SERVER_PORT); + + // connection = try std.net.tcpConnectToAddress(address); + + // std.log.info("Connected to server", .{}); +} + +//fn handle_connection(connection: std.net.Server.Connection) !void {} + +// test "simple test" { +// const gpa = std.testing.allocator; +// var list: std.ArrayList(i32) = .empty; +// defer list.deinit(gpa); // Try commenting this out and see if zig detects the memory leak! +// try list.append(gpa, 42); +// try std.testing.expectEqual(@as(i32, 42), list.pop()); // } -// fn init() !void { -// dbg_allocator = std.heap.DebugAllocator(.{}).init; -// var stdout_buffer: [1024]u8 = undefined; -// var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer); -// stdout = &stdout_writer.interface; - -// // font.shader = try rl.loadShader(null, "assets/test.frag"); +// test "fuzz example" { +// const Context = struct { +// fn testOne(context: @This(), input: []const u8) anyerror!void { +// _ = context; +// // Try passing `--fuzz` to `zig build test` and see if it manages to fail this test case! +// try std.testing.expect(!std.mem.eql(u8, "canyoufindme", input)); +// } +// }; +// try std.testing.fuzz(Context{}, Context.testOne, .{}); // } -// fn connect() !void { -// // const address = try std.net.Address.parseIp4("127.0.0.1", shared.protocol.SERVER_PORT); - -// // connection = try std.net.tcpConnectToAddress(address); - -// // std.log.info("Connected to server", .{}); -// } - -// //fn handle_connection(connection: std.net.Server.Connection) !void {} - -// // test "simple test" { -// // const gpa = std.testing.allocator; -// // var list: std.ArrayList(i32) = .empty; -// // defer list.deinit(gpa); // Try commenting this out and see if zig detects the memory leak! -// // try list.append(gpa, 42); -// // try std.testing.expectEqual(@as(i32, 42), list.pop()); -// // } - -// // test "fuzz example" { -// // const Context = struct { -// // fn testOne(context: @This(), input: []const u8) anyerror!void { -// // _ = context; -// // // Try passing `--fuzz` to `zig build test` and see if it manages to fail this test case! -// // try std.testing.expect(!std.mem.eql(u8, "canyoufindme", input)); -// // } -// // }; -// // try std.testing.fuzz(Context{}, Context.testOne, .{}); -// // } - // const c = @cImport({ @@ -467,120 +467,120 @@ // return; // } -const c = @cImport({ - @cInclude("raylib.h"); -}); +// const c = @cImport({ +// @cInclude("raylib.h"); +// }); -//------------------------------------------------------------------------------------ -// Program main entry point -//------------------------------------------------------------------------------------ -pub fn main() void { - // Initialization - //-------------------------------------------------------------------------------------- - const screenWidth = 800; - const screenHeight = 450; +// //------------------------------------------------------------------------------------ +// // Program main entry point +// //------------------------------------------------------------------------------------ +// pub fn main() void { +// // Initialization +// //-------------------------------------------------------------------------------------- +// const screenWidth = 800; +// const screenHeight = 450; - c.SetConfigFlags(c.FLAG_WINDOW_HIGHDPI | c.FLAG_WINDOW_RESIZABLE); - c.InitWindow(screenWidth, screenHeight, "raylib [core] example - highdpi demo"); - c.SetWindowMinSize(450, 450); +// c.SetConfigFlags(c.FLAG_WINDOW_HIGHDPI | c.FLAG_WINDOW_RESIZABLE); +// c.InitWindow(screenWidth, screenHeight, "raylib [core] example - highdpi demo"); +// c.SetWindowMinSize(450, 450); - const logicalGridDescY = 120; - const logicalGridLabelY = logicalGridDescY + 30; - const logicalGridTop = logicalGridLabelY + 30; - const logicalGridBottom = logicalGridTop + 80; - const pixelGridTop = logicalGridBottom - 20; - const pixelGridBottom = pixelGridTop + 80; - const pixelGridLabelY = pixelGridBottom + 30; - const pixelGridDescY = pixelGridLabelY + 30; - const cellSize = 50; - var cellSizePx : f32 = @floatFromInt(cellSize); +// const logicalGridDescY = 120; +// const logicalGridLabelY = logicalGridDescY + 30; +// const logicalGridTop = logicalGridLabelY + 30; +// const logicalGridBottom = logicalGridTop + 80; +// const pixelGridTop = logicalGridBottom - 20; +// const pixelGridBottom = pixelGridTop + 80; +// const pixelGridLabelY = pixelGridBottom + 30; +// const pixelGridDescY = pixelGridLabelY + 30; +// const cellSize = 50; +// var cellSizePx : f32 = @floatFromInt(cellSize); - c.SetTargetFPS(60); // Set our game to run at 60 frames-per-second - //-------------------------------------------------------------------------------------- +// c.SetTargetFPS(60); // Set our game to run at 60 frames-per-second +// //-------------------------------------------------------------------------------------- - // Main game loop - while (!c.WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - const monitorCount = c.GetMonitorCount(); +// // Main game loop +// while (!c.WindowShouldClose()) // Detect window close button or ESC key +// { +// // Update +// //---------------------------------------------------------------------------------- +// const monitorCount = c.GetMonitorCount(); - if ((monitorCount > 1) and c.IsKeyPressed(c.KEY_N)) { - c.SetWindowMonitor(@mod((c.GetCurrentMonitor() + 1), monitorCount)); - } +// if ((monitorCount > 1) and c.IsKeyPressed(c.KEY_N)) { +// c.SetWindowMonitor(@mod((c.GetCurrentMonitor() + 1), monitorCount)); +// } - const currentMonitor = c.GetCurrentMonitor(); - const dpiScale = c.GetWindowScaleDPI(); - cellSizePx = (@as(f32, @floatFromInt(cellSize)))/dpiScale.x; - //---------------------------------------------------------------------------------- +// const currentMonitor = c.GetCurrentMonitor(); +// const dpiScale = c.GetWindowScaleDPI(); +// cellSizePx = (@as(f32, @floatFromInt(cellSize)))/dpiScale.x; +// //---------------------------------------------------------------------------------- - // Draw - //---------------------------------------------------------------------------------- - c.BeginDrawing(); +// // Draw +// //---------------------------------------------------------------------------------- +// c.BeginDrawing(); - c.ClearBackground(c.RAYWHITE); +// c.ClearBackground(c.RAYWHITE); - const windowCenter = @divFloor(c.GetScreenWidth(), 2); - DrawTextCenter(c.TextFormat("Dpi Scale: %f", dpiScale.x), windowCenter, 30, 40, c.DARKGRAY); - DrawTextCenter(c.TextFormat("Monitor: %d/%d ([N] next monitor)", currentMonitor+1, monitorCount), windowCenter, 70, 20, c.LIGHTGRAY); - DrawTextCenter(c.TextFormat("Window is %d \"logical points\" wide", c.GetScreenWidth()), windowCenter, logicalGridDescY, 20, c.ORANGE); +// const windowCenter = @divFloor(c.GetScreenWidth(), 2); +// DrawTextCenter(c.TextFormat("Dpi Scale: %f", dpiScale.x), windowCenter, 30, 40, c.DARKGRAY); +// DrawTextCenter(c.TextFormat("Monitor: %d/%d ([N] next monitor)", currentMonitor+1, monitorCount), windowCenter, 70, 20, c.LIGHTGRAY); +// DrawTextCenter(c.TextFormat("Window is %d \"logical points\" wide", c.GetScreenWidth()), windowCenter, logicalGridDescY, 20, c.ORANGE); - var odd = true; - var i : i32 = cellSize; - while (i < c.GetScreenWidth()) { - // for (int i = cellSize; i < GetScreenWidth(); i += cellSize, odd = !odd) { - if (odd) c.DrawRectangle(i, logicalGridTop, cellSize, logicalGridBottom-logicalGridTop, c.ORANGE); +// var odd = true; +// var i : i32 = cellSize; +// while (i < c.GetScreenWidth()) { +// // for (int i = cellSize; i < GetScreenWidth(); i += cellSize, odd = !odd) { +// if (odd) c.DrawRectangle(i, logicalGridTop, cellSize, logicalGridBottom-logicalGridTop, c.ORANGE); - DrawTextCenter(c.TextFormat("%d", i), i, logicalGridLabelY, 10, c.LIGHTGRAY); - c.DrawLine(i, logicalGridLabelY + 10, i, logicalGridBottom, c.GRAY); +// DrawTextCenter(c.TextFormat("%d", i), i, logicalGridLabelY, 10, c.LIGHTGRAY); +// c.DrawLine(i, logicalGridLabelY + 10, i, logicalGridBottom, c.GRAY); - i += cellSize; - odd = !odd; - } +// i += cellSize; +// odd = !odd; +// } - odd = true; - const minTextSpace = 30; - var lastTextX : i32 = -minTextSpace; - i = cellSize; - while (i < c.GetRenderWidth()) { - // for (int i = cellSize; i < GetRenderWidth(); i += cellSize, odd = !odd) { - const x : i32 = @intFromFloat(@as(f32, @floatFromInt(i)) / dpiScale.x); - if (odd) c.DrawRectangle(x, pixelGridTop, @intFromFloat(cellSizePx), pixelGridBottom - pixelGridTop, c.Color{ .r = 0, .g = 121, .b = 241, .a = 100 }); +// odd = true; +// const minTextSpace = 30; +// var lastTextX : i32 = -minTextSpace; +// i = cellSize; +// while (i < c.GetRenderWidth()) { +// // for (int i = cellSize; i < GetRenderWidth(); i += cellSize, odd = !odd) { +// const x : i32 = @intFromFloat(@as(f32, @floatFromInt(i)) / dpiScale.x); +// if (odd) c.DrawRectangle(x, pixelGridTop, @intFromFloat(cellSizePx), pixelGridBottom - pixelGridTop, c.Color{ .r = 0, .g = 121, .b = 241, .a = 100 }); - c.DrawLine(x, pixelGridTop, @intFromFloat(@as(f32, @floatFromInt(i)) / dpiScale.x), pixelGridLabelY - 10, c.GRAY); +// c.DrawLine(x, pixelGridTop, @intFromFloat(@as(f32, @floatFromInt(i)) / dpiScale.x), pixelGridLabelY - 10, c.GRAY); - if ((x - lastTextX) >= minTextSpace) - { - DrawTextCenter(c.TextFormat("%d", i), x, pixelGridLabelY, 10, c.LIGHTGRAY); - lastTextX = x; - } - i += cellSize; - odd = !odd; - } +// if ((x - lastTextX) >= minTextSpace) +// { +// DrawTextCenter(c.TextFormat("%d", i), x, pixelGridLabelY, 10, c.LIGHTGRAY); +// lastTextX = x; +// } +// i += cellSize; +// odd = !odd; +// } - DrawTextCenter(c.TextFormat("Window is %d \"physical pixels\" wide", c.GetRenderWidth()), windowCenter, pixelGridDescY, 20, c.BLUE); +// DrawTextCenter(c.TextFormat("Window is %d \"physical pixels\" wide", c.GetRenderWidth()), windowCenter, pixelGridDescY, 20, c.BLUE); - const text = "Can you see this?"; - const size = c.MeasureTextEx(c.GetFontDefault(), text, 20, 3); - const pos = c.Vector2{ .x = @as(f32, @floatFromInt(c.GetScreenWidth())) - size.x - 5, .y = @as(f32, @floatFromInt(c.GetScreenHeight())) - size.y - 5 }; - c.DrawTextEx(c.GetFontDefault(), text, pos, 20, 3, c.LIGHTGRAY); +// const text = "Can you see this?"; +// const size = c.MeasureTextEx(c.GetFontDefault(), text, 20, 3); +// const pos = c.Vector2{ .x = @as(f32, @floatFromInt(c.GetScreenWidth())) - size.x - 5, .y = @as(f32, @floatFromInt(c.GetScreenHeight())) - size.y - 5 }; +// c.DrawTextEx(c.GetFontDefault(), text, pos, 20, 3, c.LIGHTGRAY); - c.EndDrawing(); - //---------------------------------------------------------------------------------- - } +// c.EndDrawing(); +// //---------------------------------------------------------------------------------- +// } - // De-Initialization - //-------------------------------------------------------------------------------------- - c.CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- -} +// // De-Initialization +// //-------------------------------------------------------------------------------------- +// c.CloseWindow(); // Close window and OpenGL context +// //-------------------------------------------------------------------------------------- +// } -//------------------------------------------------------------------------------------ -// Module Functions Definition -//------------------------------------------------------------------------------------ -fn DrawTextCenter(text : [*:0]const u8, x : i32, y: i32, fontSize : i32, color: c.Color) void { -// fn DrawTextCenter(const char *text, int x, int y, int fontSize, Color color) void { - const size = c.MeasureTextEx(c.GetFontDefault(), text, @floatFromInt(fontSize), 3); - const pos = c.Vector2{ .x = @as(f32, @floatFromInt(x)) - size.x/2, .y = @as(f32, @floatFromInt(y)) - size.y/2 }; - c.DrawTextEx(c.GetFontDefault(), text, pos, @as(f32, @floatFromInt(fontSize)), 3, color); -} +// //------------------------------------------------------------------------------------ +// // Module Functions Definition +// //------------------------------------------------------------------------------------ +// fn DrawTextCenter(text : [*:0]const u8, x : i32, y: i32, fontSize : i32, color: c.Color) void { +// // fn DrawTextCenter(const char *text, int x, int y, int fontSize, Color color) void { +// const size = c.MeasureTextEx(c.GetFontDefault(), text, @floatFromInt(fontSize), 3); +// const pos = c.Vector2{ .x = @as(f32, @floatFromInt(x)) - size.x/2, .y = @as(f32, @floatFromInt(y)) - size.y/2 }; +// c.DrawTextEx(c.GetFontDefault(), text, pos, @as(f32, @floatFromInt(fontSize)), 3, color); +// }