who's your daddy?

This commit is contained in:
Vicente Ferrari Smith 2026-01-21 23:37:38 +01:00
parent 04837e4d53
commit 3f4280ae37
3 changed files with 495 additions and 474 deletions

View File

@ -146,7 +146,7 @@ pub fn build(b: *std.Build) void {
const raylib_dep = b.dependency("raylib", .{ .target = target, .optimize = optimize }); const raylib_dep = b.dependency("raylib", .{ .target = target, .optimize = optimize });
const raylib = raylib_dep.artifact("raylib"); 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); client.linkLibrary(raylib);
b.installArtifact(client); b.installArtifact(client);

View File

@ -12,28 +12,29 @@ pub var shader : c.Shader = undefined;
const ATLAS_SIZE = 4096; const ATLAS_SIZE = 4096;
const Glyph = struct { const Glyph = struct {
utf32 : u32,
index : u32, index : u32,
x : i16, x : i16,
y : i16, y : i16,
width : i32, width : i32,
height : i32, height : i32,
// dpi_width : i32, dpi_width : f32,
// dpi_height : i32, dpi_height : f32,
// rwidth : i16, // rwidth : i16,
// rheight : i16, // rheight : i16,
bearing_x : i32, bearing_x : i32,
bearing_y : i32, bearing_y : i32,
// dpi_bearing_x : i32, dpi_bearing_x : f32,
// dpi_bearing_y : i32, dpi_bearing_y : f32,
// y_max : i16, // y_max : i16,
// y_min : i16, // y_min : i16,
ascent : i32,
descent : i32, descent : i32,
ascent : i32,
dpi_descent : f32,
dpi_ascent : f32,
// advance : i16, // advance : i16,
st0 : c.Vector2, st0 : c.Vector2,
@ -48,20 +49,18 @@ pub const Font = struct {
kb : kb.kbts_font, kb : kb.kbts_font,
texture : c.Texture2D, texture : c.Texture2D,
// texture : rl.Texture2D, // texture : rl.Texture2D,
font_data : []u8,
pub fn init(filename : []const u8, size : i32, allocator: std.mem.Allocator) !Font { 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); const font_data = try std.fs.cwd().readFileAlloc(allocator, filename, 10 * 1024 * 1024);
var face = try ft_lib.createFaceMemory(font_data, 0); var face = try ft_lib.createFaceMemory(font_data, 0);
var glyphs = std.AutoHashMap(u32, Glyph).init(allocator); var glyphs = std.AutoHashMap(u32, Glyph).init(allocator);
try face.setCharSize(0, size * 64, 0, 72 * @as(u16, @intFromFloat(c.GetWindowScaleDPI().y))); try face.setCharSize(0, size * 64, 0, 96 * @as(u16, @intFromFloat(c.GetWindowScaleDPI().y)));
// try face.setPixelSizes(0, @intCast(size)); // 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 * @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); try face.selectCharmap(.unicode);
var rects = try std.ArrayList(rp.stbrp_rect).initCapacity(allocator, 1024); var rects = try std.ArrayList(rp.stbrp_rect).initCapacity(allocator, 1024);
@ -85,16 +84,17 @@ pub const Font = struct {
.format = c.PIXELFORMAT_UNCOMPRESSED_GRAYSCALE, .format = c.PIXELFORMAT_UNCOMPRESSED_GRAYSCALE,
}; };
var iter = face.iterateCharmap(); // var iter = face.iterateCharmap();
while (iter.next()) |char| { // while (iter.next()) |char| {
const i = iter.index; for (0..face.numGlyphs()) |index| {
// const i = iter.index;
// for (0..face.numGlyphs()) |i| { // for (0..face.numGlyphs()) |i| {
try face.loadGlyph(@intCast(i), .{}); try face.loadGlyph(@intCast(index), .{});
const bmp = face.glyph().bitmap(); const bmp = face.glyph().bitmap();
try rects.append(allocator, .{ try rects.append(allocator, .{
.id = @intCast(char),//@intCast(face.glyph().glyphIndex()), .id = @intCast(index),//@intCast(face.glyph().glyphIndex()),
.w = @intCast(bmp.width()), .w = @intCast(bmp.width()),
.h = @intCast(bmp.rows()), .h = @intCast(bmp.rows()),
.x = 0, .x = 0,
@ -106,9 +106,8 @@ pub const Font = struct {
_ = rp.stbrp_pack_rects(&stbrpcontext, rects.items.ptr, @intCast(rects.items.len)); _ = rp.stbrp_pack_rects(&stbrpcontext, rects.items.ptr, @intCast(rects.items.len));
for (rects.items) |rect| { for (rects.items) |rect| {
const index : u32 = @intCast(rect.id);
if (rect.was_packed == 0) continue; 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 }); try face.loadGlyph(index, .{ .render = true });
const bmp = face.glyph().bitmap(); const bmp = face.glyph().bitmap();
@ -130,14 +129,32 @@ pub const Font = struct {
@memcpy(dst, src); @memcpy(dst, src);
} }
// std.log.info("{}", .{bmp.width()});
const width : i32 = @intCast(bmp.width()); const width : i32 = @intCast(bmp.width());
// std.log.info("{}", .{bmp.rows()});
const height : i32 = @intCast(bmp.rows()); const height : i32 = @intCast(bmp.rows());
// const dpi_width : i32 = @intFromFloat(@as(f32, @floatFromInt(width)) / rl.getWindowScaleDPI().x); // 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 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(); const bearing_x : i32 = face.glyph().bitmapLeft();
// std.log.info("{}", .{face.glyph().bitmapTop()});
const bearing_y : i32 = 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; const descent : i32 = height - bearing_y;
const ascent : i32 = @as(i32, @intCast(height)) - descent; // 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 x : i16 = @intCast(rect.x);
const y : i16 = @as(i16, @intCast(rect.y)) + @as(i16, @intCast(height)); const y : i16 = @as(i16, @intCast(rect.y)) + @as(i16, @intCast(height));
@ -151,23 +168,24 @@ pub const Font = struct {
const glyph = Glyph{ const glyph = Glyph{
.x = x, .x = x,
.y = y, .y = y,
.utf32 = char,
.index = index, .index = index,
.bearing_x = bearing_x, .bearing_x = bearing_x,
.bearing_y = bearing_y, .bearing_y = bearing_y,
// .dpi_bearing_x = @as(i32, @intFromFloat(@as(f32, @floatFromInt(bearing_x)) / rl.getWindowScaleDPI().x)), .dpi_bearing_x = dpi_bearing_x,
// .dpi_bearing_y = @as(i32, @intFromFloat(@as(f32, @floatFromInt(bearing_y)) / rl.getWindowScaleDPI().y)), .dpi_bearing_y = dpi_bearing_y,
.width = width, .width = width,
.height = height, .height = height,
// .dpi_width = dpi_width, .dpi_width = dpi_width,
// .dpi_height = dpi_height, .dpi_height = dpi_height,
// .rwidth = @intCast(face.glyph().metrics().width >> 6), // .rwidth = @intCast(face.glyph().metrics().width >> 6),
// .rheight = @intCast(face.glyph().metrics().height >> 6), // .rheight = @intCast(face.glyph().metrics().height >> 6),
.descent = descent, .descent = descent,
.ascent = ascent, .ascent = ascent,
.dpi_descent = dpi_descent,
.dpi_ascent = dpi_ascent,
// .advance = @intCast(face.glyph().advance().x >> 6), // .advance = @intCast(face.glyph().advance().x >> 6),
.st0 = .{.x = (fx + 0.5) / fs, .y = (fy - fh) / fs}, .st0 = .{.x = (fx + 0.5) / fs, .y = (fy - fh + 0.5) / fs},
.st1 = .{.x = (fx + fw) / fs, .y = (fy - 0.5) / fs}, .st1 = .{.x = (fx + fw - 0.5) / fs, .y = (fy - 0.5) / fs},
}; };
try glyphs.put(glyph.index, glyph); 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.", .{}); std.log.info("[Error] [kb_text_shape] Failed to load the font.", .{});
} }
allocator.free(font_data);
return .{ return .{
.face = face, .face = face,
.glyphs = glyphs, .glyphs = glyphs,
.kb = _kb, .kb = _kb,
.texture = texture, .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(); // var it = self.glyphs.valueIterator();
// while (it.next()) |g| { // while (it.next()) |g| {
// allocator.free(g.bitmap); // allocator.free(g.bitmap);
@ -201,7 +220,6 @@ pub const Font = struct {
kb.kbts_FreeFont(&self.kb); kb.kbts_FreeFont(&self.kb);
c.UnloadTexture(self.texture); c.UnloadTexture(self.texture);
// self.texture.unload(); // self.texture.unload();
allocator.free(self.font_data);
} }
pub fn render_text( pub fn render_text(
@ -248,7 +266,7 @@ pub const Font = struct {
render_pos.y += font_ascent; 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); // rl.drawLine(@intFromFloat(render_pos.x), @intFromFloat(render_pos.y), rl.getScreenWidth(), @intFromFloat(render_pos.y), .red);
const Context = kb.kbts_CreateShapeContext(null, null); 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_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 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_x = advance_x / rl.getWindowScaleDPI().x;
// const dpi_advance_y = advance_y / rl.getWindowScaleDPI().y; // const dpi_advance_y = advance_y / rl.getWindowScaleDPI().y;
@ -298,7 +318,7 @@ pub const Font = struct {
var v0 = c.Vector2{}; var v0 = c.Vector2{};
var v1 = c.Vector2{}; var v1 = c.Vector2{};
// const bx = @as(f32, @floatFromInt(glyph.bearing_x)); // 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 height = @as(f32, @floatFromInt(glyph.height));
// const descent = @as(f32, @floatFromInt(glyph.descent)); // const descent = @as(f32, @floatFromInt(glyph.descent));
// const ascent = @as(f32, @floatFromInt(glyph.ascent)); // const ascent = @as(f32, @floatFromInt(glyph.ascent));
@ -314,14 +334,14 @@ pub const Font = struct {
// });//* - glyph.height + draw_size.y*/}; // });//* - 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) }); // 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 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 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 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 }; // const p1 : rl.Vector4 = .{ .x = v1.x, .y = v1.y, .z = 0.0, .w = 1.0 };
x_offset += advance_x; x_offset += dpi_advance_x;
y_offset += advance_y; y_offset += dpi_advance_y;
// #if Y_IS_UP { // #if Y_IS_UP {
// t0 := Vector2.{ // 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, st1.y); rl.gl.rlVertex2f(p1.x, p1.y);
// rl.gl.rlTexCoord2f(st1.x, st0.y); rl.gl.rlVertex2f(p1.x, p0.y); // rl.gl.rlTexCoord2f(st1.x, st0.y); rl.gl.rlVertex2f(p1.x, p0.y);
} else { } else {
x_offset += advance_x; std.log.warn("kb_text_shape found the glyph, but we didn't load it from the font.", .{});
y_offset += advance_y; x_offset += dpi_advance_x;
y_offset += dpi_advance_y;
continue; continue;
} }
} }
@ -403,7 +424,7 @@ pub const Font = struct {
} }
if (self.glyphs.getPtr(@intCast(RunGlyph.Id))) |glyph| { 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 += (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); 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))); max_descent = @max(max_descent, @as(f32, @floatFromInt(glyph.descent)));

View File

@ -1,371 +1,371 @@
// const std = @import("std"); const std = @import("std");
// const zm = @import("zmath"); const zm = @import("zmath");
// const znet = @import("znet"); const znet = @import("znet");
// // const rl = @import("raylib"); // const rl = @import("raylib");
// const bufzilla = @import("bufzilla"); const bufzilla = @import("bufzilla");
// const ft = @import("freetype"); const ft = @import("freetype");
// const c = @import("c.zig").c; const c = @import("c.zig").c;
// const shared = @import("shared"); const shared = @import("shared");
// const client = @import("client.zig"); const client = @import("client.zig");
// const entity = @import("entity.zig"); const entity = @import("entity.zig");
// const misc = @import("misc.zig"); const misc = @import("misc.zig");
// const font = @import("font.zig"); const font = @import("font.zig");
// const dt : f32 = 1.0 / 200.0; const dt : f32 = 1.0 / 200.0;
// var t : f32 = 0; var t : f32 = 0;
// var gt : f32 = 0; var gt : f32 = 0;
// var accumulator : f32 = 0; var accumulator : f32 = 0;
// var k : f32 = 1; var k : f32 = 1;
// var frame : i32 = 0; var frame : i32 = 0;
// const screen_width = 1280; const screen_width = 1280;
// const screen_height = 720; const screen_height = 720;
// var running: bool = true; var running: bool = true;
// var dbg_allocator: std.heap.DebugAllocator(.{}) = undefined; var dbg_allocator: std.heap.DebugAllocator(.{}) = undefined;
// const allocator = dbg_allocator.allocator(); const allocator = dbg_allocator.allocator();
// var stdout: *std.io.Writer = undefined; var stdout: *std.io.Writer = undefined;
// // var connection: ?std.net.Stream = undefined; // var connection: ?std.net.Stream = undefined;
// pub fn main() !void { pub fn main() !void {
// std.log.info("Hello Client!", .{}); std.log.info("Hello Client!", .{});
// try init(); try init();
// defer _ = dbg_allocator.deinit(); defer _ = dbg_allocator.deinit();
// try znet.init(); try znet.init();
// defer znet.deinit(); defer znet.deinit();
// c.SetConfigFlags(c.FLAG_WINDOW_HIGHDPI); c.SetConfigFlags(c.FLAG_WINDOW_HIGHDPI);
// // rl.setConfigFlags(.{ .window_highdpi = true }); // rl.setConfigFlags(.{ .window_highdpi = true });
// c.InitWindow(screen_width, screen_height, "zzz"); c.InitWindow(screen_width, screen_height, "zzz");
// // rl.initWindow(screen_width, screen_height, "zzz"); // rl.initWindow(screen_width, screen_height, "zzz");
// defer c.CloseWindow(); defer c.CloseWindow();
// // defer rl.closeWindow(); // defer rl.closeWindow();
// font.ft_lib = try ft.Library.init(); font.ft_lib = try ft.Library.init();
// // std.log.debug("screen ? {}", .{rl.getScreenWidth()}); // std.log.debug("screen ? {}", .{rl.getScreenWidth()});
// // std.log.debug("screen ? {}", .{rl.getScreenHeight()}); // std.log.debug("screen ? {}", .{rl.getScreenHeight()});
// // std.log.debug("render ? {}", .{rl.getRenderWidth()}); // std.log.debug("render ? {}", .{rl.getRenderWidth()});
// // std.log.debug("render ? {}", .{rl.getRenderHeight()}); // std.log.debug("render ? {}", .{rl.getRenderHeight()});
// // std.log.debug("what's being used for viewport ? {}", .{rl.RLGL.State.framebufferWidth}); // 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); var f = try font.Font.init("assets/fonts/Vollkorn/static/Vollkorn-Regular.ttf", 7, allocator);
// defer f.deinit(allocator); defer f.deinit();
// font.shader = c.LoadShader(null, "assets/text.frag"); font.shader = c.LoadShader(null, "assets/text.frag");
// // const test_shader1 = try c.LoadShader(null, "assets/test_1.frag"); // const test_shader1 = try c.LoadShader(null, "assets/test_1.frag");
// // const test_shader2 = try c.LoadShader(null, "assets/test_2.frag"); // const test_shader2 = try c.LoadShader(null, "assets/test_2.frag");
// // font.shader = try rl.loadShader(null, "assets/text.frag"); // font.shader = try rl.loadShader(null, "assets/text.frag");
// // const test_shader1 = try rl.loadShader(null, "assets/test_1.frag"); // const test_shader1 = try rl.loadShader(null, "assets/test_1.frag");
// // const test_shader2 = try rl.loadShader(null, "assets/test_2.frag"); // const test_shader2 = try rl.loadShader(null, "assets/test_2.frag");
// // const img = rl.genImageColor(32, 32, .blank); // const img = rl.genImageColor(32, 32, .blank);
// // const tx = try rl.loadTextureFromImage(img); // const tx = try rl.loadTextureFromImage(img);
// // rl.unloadImage(img); // rl.unloadImage(img);
// const host = try znet.Host.init(.{ const host = try znet.Host.init(.{
// .addr = null, .addr = null,
// .peer_limit = 1, .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, // .channel_limit = .max,
// .incoming_bandwidth = .unlimited, // .data = 0,
// .outgoing_bandwidth = .unlimited,
// }); // });
// defer host.deinit();
// // const peer = try host.connect(.{ // connect() catch |err| switch (err) {
// // .addr = try .init(.{ // error.ConnectionRefused => {
// // .ip = .{ .ipv4 = "127.0.0.1" }, // std.log.err("server refused connection", .{});
// // .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);
// 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| { // else => {
// _ = data; // std.log.err("unexpected connect error: {}", .{err});
// // std.log.info("{}", .{data.peer}); // return err;
// },
// .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(); // try stdout.flush();
// // rl.pollInputEvents();
// // if (peer.state() == .connected) { var the_chunk = try shared.chunk.initChunk(allocator);
// // const packet = try znet.Packet.init("Hello, Server!", 0, .reliable); defer shared.chunk.deinitChunk(&the_chunk, allocator);
// // try peer.send(packet);
// // }
// // // _ = peer;
// // // Update shared.chunk.updateChunk(&the_chunk);
// // //----------------------------------------------------------------------------------
// // // TODO: Update your variables here
// // //----------------------------------------------------------------------------------
// // rl.updateMusicStream(music); //var elf = entity.Elf.init();
// // while (accumulator > dt * k) { // var send_buf: [1024]u8 = undefined;
// // // update(dt * cast(float) k); // var writer = if (connection) |*conn| conn.writer(&send_buf) else return;
// // accumulator -= dt * k;
// // gt += dt * k;
// // }
// // // Draw // try shared.protocol.sendHello(&writer.interface, .{ .msg = "Hello from client" });
// // //----------------------------------------------------------------------------------
// c.BeginDrawing();
// c.ClearBackground(c.SKYBLUE);
// // rl.clearBackground(.black);
// // rl.beginDrawing(); // 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});
// // // rl.drawRectangle(screen_width - 100, 0, 100, 100, .red); // 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);
// rl.beginDrawing();
// // 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( // f.render_text(
// "Whereas, disregard and contempt for human rights have resulted!", // "Whereas, disregard and contempt for human rights have resulted!",
// c.Vector2{ .x = 0, .y = 0}, // rl.Vector2.init(0, 0),
// true, // true,
// c.WHITE, // rl.Color.white,
// c.BLANK, // rl.Color.blank,
// false, // false,
// true // 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.beginShaderMode(test_shader1);
// // // rl.gl.rlBegin(rl.gl.rl_quads); // // rl.gl.rlBegin(rl.gl.rl_quads);
// // // { // // {
// // // const topLeft : rl.Vector2 = .{ .x = 0.0, .y = 0.0 }; // // 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())) }; // // 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, topLeft.y);
// // // rl.gl.rlVertex2f(topLeft.x, bottomRight.y); // // rl.gl.rlVertex2f(topLeft.x, bottomRight.y);
// // // rl.gl.rlVertex2f(bottomRight.x, bottomRight.y); // // rl.gl.rlVertex2f(bottomRight.x, bottomRight.y);
// // // rl.gl.rlVertex2f(bottomRight.x, topLeft.y); // // rl.gl.rlVertex2f(bottomRight.x, topLeft.y);
// // // }
// // // rl.gl.rlEnd();
// // // rl.endShaderMode();
// // // 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()) };
// // // 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);
// // // {
// // // 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.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
// // // // 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);
// // //elf.draw();
// // // rl.beginMode3D(camera);
// // // rl.drawSphere(.{ .x = 0, .y = 0, .z = 0 }, 1, .red);
// // // rl.endMode3D();
// c.EndDrawing();
// // rl.endDrawing();
// // //----------------------------------------------------------------------------------
// 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());
// // } // // }
// // test "fuzz example" { // // rl.gl.rlEnd();
// // const Context = struct { // // rl.endShaderMode();
// // fn testOne(context: @This(), input: []const u8) anyerror!void {
// // _ = context; // // rl.beginShaderMode(test_shader2);
// // // Try passing `--fuzz` to `zig build test` and see if it manages to fail this test case! // // rl.gl.rlBegin(rl.gl.rl_quads);
// // try std.testing.expect(!std.mem.eql(u8, "canyoufindme", input));
// // {
// // 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);
// // } // // }
// // };
// // try std.testing.fuzz(Context{}, Context.testOne, .{}); // // rl.gl.rlEnd();
// // rl.endShaderMode();
// // 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()) };
// // 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 });
// // 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);
// //elf.draw();
// // rl.beginMode3D(camera);
// // rl.drawSphere(.{ .x = 0, .y = 0, .z = 0 }, 1, .red);
// // rl.endMode3D();
c.EndDrawing();
// rl.endDrawing();
// //----------------------------------------------------------------------------------
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());
// }
// 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({ // const c = @cImport({
@ -467,120 +467,120 @@
// return; // return;
// } // }
const c = @cImport({ // const c = @cImport({
@cInclude("raylib.h"); // @cInclude("raylib.h");
}); // });
//------------------------------------------------------------------------------------ // //------------------------------------------------------------------------------------
// Program main entry point // // Program main entry point
//------------------------------------------------------------------------------------ // //------------------------------------------------------------------------------------
pub fn main() void { // pub fn main() void {
// Initialization // // Initialization
//-------------------------------------------------------------------------------------- // //--------------------------------------------------------------------------------------
const screenWidth = 800; // const screenWidth = 800;
const screenHeight = 450; // const screenHeight = 450;
c.SetConfigFlags(c.FLAG_WINDOW_HIGHDPI | c.FLAG_WINDOW_RESIZABLE); // c.SetConfigFlags(c.FLAG_WINDOW_HIGHDPI | c.FLAG_WINDOW_RESIZABLE);
c.InitWindow(screenWidth, screenHeight, "raylib [core] example - highdpi demo"); // c.InitWindow(screenWidth, screenHeight, "raylib [core] example - highdpi demo");
c.SetWindowMinSize(450, 450); // c.SetWindowMinSize(450, 450);
const logicalGridDescY = 120; // const logicalGridDescY = 120;
const logicalGridLabelY = logicalGridDescY + 30; // const logicalGridLabelY = logicalGridDescY + 30;
const logicalGridTop = logicalGridLabelY + 30; // const logicalGridTop = logicalGridLabelY + 30;
const logicalGridBottom = logicalGridTop + 80; // const logicalGridBottom = logicalGridTop + 80;
const pixelGridTop = logicalGridBottom - 20; // const pixelGridTop = logicalGridBottom - 20;
const pixelGridBottom = pixelGridTop + 80; // const pixelGridBottom = pixelGridTop + 80;
const pixelGridLabelY = pixelGridBottom + 30; // const pixelGridLabelY = pixelGridBottom + 30;
const pixelGridDescY = pixelGridLabelY + 30; // const pixelGridDescY = pixelGridLabelY + 30;
const cellSize = 50; // const cellSize = 50;
var cellSizePx : f32 = @floatFromInt(cellSize); // 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 // // Main game loop
while (!c.WindowShouldClose()) // Detect window close button or ESC key // while (!c.WindowShouldClose()) // Detect window close button or ESC key
{ // {
// Update // // Update
//---------------------------------------------------------------------------------- // //----------------------------------------------------------------------------------
const monitorCount = c.GetMonitorCount(); // const monitorCount = c.GetMonitorCount();
if ((monitorCount > 1) and c.IsKeyPressed(c.KEY_N)) { // if ((monitorCount > 1) and c.IsKeyPressed(c.KEY_N)) {
c.SetWindowMonitor(@mod((c.GetCurrentMonitor() + 1), monitorCount)); // c.SetWindowMonitor(@mod((c.GetCurrentMonitor() + 1), monitorCount));
} // }
const currentMonitor = c.GetCurrentMonitor(); // const currentMonitor = c.GetCurrentMonitor();
const dpiScale = c.GetWindowScaleDPI(); // const dpiScale = c.GetWindowScaleDPI();
cellSizePx = (@as(f32, @floatFromInt(cellSize)))/dpiScale.x; // cellSizePx = (@as(f32, @floatFromInt(cellSize)))/dpiScale.x;
//---------------------------------------------------------------------------------- // //----------------------------------------------------------------------------------
// Draw // // Draw
//---------------------------------------------------------------------------------- // //----------------------------------------------------------------------------------
c.BeginDrawing(); // c.BeginDrawing();
c.ClearBackground(c.RAYWHITE); // c.ClearBackground(c.RAYWHITE);
const windowCenter = @divFloor(c.GetScreenWidth(), 2); // const windowCenter = @divFloor(c.GetScreenWidth(), 2);
DrawTextCenter(c.TextFormat("Dpi Scale: %f", dpiScale.x), windowCenter, 30, 40, c.DARKGRAY); // 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("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); // DrawTextCenter(c.TextFormat("Window is %d \"logical points\" wide", c.GetScreenWidth()), windowCenter, logicalGridDescY, 20, c.ORANGE);
var odd = true; // var odd = true;
var i : i32 = cellSize; // var i : i32 = cellSize;
while (i < c.GetScreenWidth()) { // while (i < c.GetScreenWidth()) {
// for (int i = cellSize; i < GetScreenWidth(); i += cellSize, odd = !odd) { // // for (int i = cellSize; i < GetScreenWidth(); i += cellSize, odd = !odd) {
if (odd) c.DrawRectangle(i, logicalGridTop, cellSize, logicalGridBottom-logicalGridTop, c.ORANGE); // if (odd) c.DrawRectangle(i, logicalGridTop, cellSize, logicalGridBottom-logicalGridTop, c.ORANGE);
DrawTextCenter(c.TextFormat("%d", i), i, logicalGridLabelY, 10, c.LIGHTGRAY); // DrawTextCenter(c.TextFormat("%d", i), i, logicalGridLabelY, 10, c.LIGHTGRAY);
c.DrawLine(i, logicalGridLabelY + 10, i, logicalGridBottom, c.GRAY); // c.DrawLine(i, logicalGridLabelY + 10, i, logicalGridBottom, c.GRAY);
i += cellSize; // i += cellSize;
odd = !odd; // odd = !odd;
} // }
odd = true; // odd = true;
const minTextSpace = 30; // const minTextSpace = 30;
var lastTextX : i32 = -minTextSpace; // var lastTextX : i32 = -minTextSpace;
i = cellSize; // i = cellSize;
while (i < c.GetRenderWidth()) { // while (i < c.GetRenderWidth()) {
// for (int i = cellSize; i < GetRenderWidth(); i += cellSize, odd = !odd) { // // for (int i = cellSize; i < GetRenderWidth(); i += cellSize, odd = !odd) {
const x : i32 = @intFromFloat(@as(f32, @floatFromInt(i)) / dpiScale.x); // 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 }); // 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) // if ((x - lastTextX) >= minTextSpace)
{ // {
DrawTextCenter(c.TextFormat("%d", i), x, pixelGridLabelY, 10, c.LIGHTGRAY); // DrawTextCenter(c.TextFormat("%d", i), x, pixelGridLabelY, 10, c.LIGHTGRAY);
lastTextX = x; // lastTextX = x;
} // }
i += cellSize; // i += cellSize;
odd = !odd; // 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 text = "Can you see this?";
const size = c.MeasureTextEx(c.GetFontDefault(), text, 20, 3); // 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 }; // 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.DrawTextEx(c.GetFontDefault(), text, pos, 20, 3, c.LIGHTGRAY);
c.EndDrawing(); // c.EndDrawing();
//---------------------------------------------------------------------------------- // //----------------------------------------------------------------------------------
} // }
// De-Initialization // // De-Initialization
//-------------------------------------------------------------------------------------- // //--------------------------------------------------------------------------------------
c.CloseWindow(); // Close window and OpenGL context // c.CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- // //--------------------------------------------------------------------------------------
} // }
//------------------------------------------------------------------------------------ // //------------------------------------------------------------------------------------
// Module Functions Definition // // Module Functions Definition
//------------------------------------------------------------------------------------ // //------------------------------------------------------------------------------------
fn DrawTextCenter(text : [*:0]const u8, x : i32, y: i32, fontSize : i32, color: c.Color) void { // 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 { // // 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 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 }; // 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); // c.DrawTextEx(c.GetFontDefault(), text, pos, @as(f32, @floatFromInt(fontSize)), 3, color);
} // }