c
This commit is contained in:
parent
71e4f781cf
commit
6c575dc997
31
build.zig
31
build.zig
@ -92,8 +92,7 @@ pub fn build(b: *std.Build) void {
|
|||||||
// harfbuzz_tests.root_module.linkLibrary(dep.artifact("freetype"));
|
// harfbuzz_tests.root_module.linkLibrary(dep.artifact("freetype"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// client.addCSourceFile(.{ .file = b.path("src/kb/kb_text_shape.h"), .language = .c, .flags = &.{"-DKB_TEXT_SHAPE_IMPLEMENTATION"} });
|
client.root_module.addImport("freetype", freetype_module);
|
||||||
|
|
||||||
client.root_module.addCSourceFile(.{ .file = b.path("src/kb/kb_text_shape.h"), .language = .c, .flags = &.{"-DKB_TEXT_SHAPE_IMPLEMENTATION"} });
|
client.root_module.addCSourceFile(.{ .file = b.path("src/kb/kb_text_shape.h"), .language = .c, .flags = &.{"-DKB_TEXT_SHAPE_IMPLEMENTATION"} });
|
||||||
|
|
||||||
const kb_text_shape = b.addTranslateC(.{
|
const kb_text_shape = b.addTranslateC(.{
|
||||||
@ -131,20 +130,24 @@ pub fn build(b: *std.Build) void {
|
|||||||
client.root_module.addImport("bufzilla", bufzilla.module("bufzilla"));
|
client.root_module.addImport("bufzilla", bufzilla.module("bufzilla"));
|
||||||
server.root_module.addImport("bufzilla", bufzilla.module("bufzilla"));
|
server.root_module.addImport("bufzilla", bufzilla.module("bufzilla"));
|
||||||
|
|
||||||
const raylib_dep = b.dependency("raylib_zig", .{
|
// const raylib_dep = b.dependency("raylib_zig", .{
|
||||||
.target = target,
|
// .target = target,
|
||||||
.optimize = optimize,
|
// .optimize = optimize,
|
||||||
});
|
// });
|
||||||
|
|
||||||
const raylib = raylib_dep.module("raylib"); // main raylib module
|
// const raylib = raylib_dep.module("raylib"); // main raylib module
|
||||||
const raygui = raylib_dep.module("raygui"); // raygui module
|
// const raygui = raylib_dep.module("raygui"); // raygui module
|
||||||
const raylib_artifact = raylib_dep.artifact("raylib"); // raylib C library
|
// const raylib_artifact = raylib_dep.artifact("raylib"); // raylib C library
|
||||||
raylib_artifact.root_module.addCMacro("SUPPORT_CUSTOM_FRAME_CONTROL", "");
|
// raylib_artifact.root_module.addCMacro("SUPPORT_CUSTOM_FRAME_CONTROL", "");
|
||||||
|
|
||||||
client.linkLibrary(raylib_artifact);
|
// client.linkLibrary(raylib_artifact);
|
||||||
client.root_module.addImport("raylib", raylib);
|
// client.root_module.addImport("raylib", raylib);
|
||||||
client.root_module.addImport("raygui", raygui);
|
// client.root_module.addImport("raygui", raygui);
|
||||||
client.root_module.addImport("freetype", freetype_module);
|
|
||||||
|
const raylib_dep = b.dependency("raylib", .{ .target = target, .optimize = optimize });
|
||||||
|
const raylib = raylib_dep.artifact("raylib");
|
||||||
|
raylib.root_module.addCMacro("SUPPORT_CUSTOM_FRAME_CONTROL", "");
|
||||||
|
client.linkLibrary(raylib);
|
||||||
|
|
||||||
b.installArtifact(client);
|
b.installArtifact(client);
|
||||||
b.installArtifact(server);
|
b.installArtifact(server);
|
||||||
|
|||||||
@ -56,6 +56,10 @@
|
|||||||
.url = "git+https://github.com/hexops/freetype#972cd37bccecae2cc9f54cf0b562263a13209d02",
|
.url = "git+https://github.com/hexops/freetype#972cd37bccecae2cc9f54cf0b562263a13209d02",
|
||||||
.hash = "freetype-0.0.0-AAAAAA5JcwBMujojfNLEq5g_WijZtU56mRLYx8bjjiMU",
|
.hash = "freetype-0.0.0-AAAAAA5JcwBMujojfNLEq5g_WijZtU56mRLYx8bjjiMU",
|
||||||
},
|
},
|
||||||
|
.raylib = .{
|
||||||
|
.url = "git+https://github.com/raysan5/raylib#29896a24039fb687d6ede44c63a78dd3b5829f8b",
|
||||||
|
.hash = "raylib-5.6.0-dev-whq8uM8HDQU5L4MyTYQJ2jJv9oFfadsWbEmuUEmXiPkq",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
.paths = .{
|
.paths = .{
|
||||||
"build.zig",
|
"build.zig",
|
||||||
|
|||||||
5
src/client/c.zig
Normal file
5
src/client/c.zig
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
pub const c = @cImport({
|
||||||
|
@cInclude("raylib.h");
|
||||||
|
@cInclude("raymath.h");
|
||||||
|
@cInclude("rlgl.h");
|
||||||
|
});
|
||||||
@ -1,12 +1,13 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const c = @import("c.zig").c;
|
||||||
const rl = @import("raylib");
|
// const rl = @import("raylib");
|
||||||
const kb = @import("kb");
|
const kb = @import("kb");
|
||||||
const ft = @import("freetype");
|
const ft = @import("freetype");
|
||||||
const rp = @import("stb_rect_pack");
|
const rp = @import("stb_rect_pack");
|
||||||
|
|
||||||
pub var ft_lib : ft.Library = undefined;
|
pub var ft_lib : ft.Library = undefined;
|
||||||
pub var shader : rl.Shader = undefined;
|
pub var shader : c.Shader = undefined;
|
||||||
|
// pub var shader : rl.Shader = undefined;
|
||||||
|
|
||||||
const ATLAS_SIZE = 4096;
|
const ATLAS_SIZE = 4096;
|
||||||
|
|
||||||
@ -35,15 +36,18 @@ const Glyph = struct {
|
|||||||
descent : i32,
|
descent : i32,
|
||||||
// advance : i16,
|
// advance : i16,
|
||||||
|
|
||||||
st0 : rl.Vector2,
|
st0 : c.Vector2,
|
||||||
st1 : rl.Vector2,
|
st1 : c.Vector2,
|
||||||
|
// st0 : rl.Vector2,
|
||||||
|
// st1 : rl.Vector2,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Font = struct {
|
pub const Font = struct {
|
||||||
face : ft.Face,
|
face : ft.Face,
|
||||||
glyphs : std.AutoHashMap(u32, Glyph),
|
glyphs : std.AutoHashMap(u32, Glyph),
|
||||||
kb : kb.kbts_font,
|
kb : kb.kbts_font,
|
||||||
texture : rl.Texture2D,
|
texture : c.Texture2D,
|
||||||
|
// texture : rl.Texture2D,
|
||||||
font_data : []u8,
|
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 {
|
||||||
@ -54,8 +58,9 @@ pub const Font = struct {
|
|||||||
|
|
||||||
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.setPixelSizes(0, @intCast(size));
|
// try face.setPixelSizes(0, @intCast(size));
|
||||||
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, 72 * 1);
|
||||||
try face.selectCharmap(.unicode);
|
try face.selectCharmap(.unicode);
|
||||||
|
|
||||||
@ -71,12 +76,13 @@ pub const Font = struct {
|
|||||||
defer allocator.free(_atlas);
|
defer allocator.free(_atlas);
|
||||||
@memset(_atlas, 0);
|
@memset(_atlas, 0);
|
||||||
|
|
||||||
const atlas : rl.Image = .{
|
const atlas : c.Image = .{
|
||||||
|
// const atlas : rl.Image = .{
|
||||||
.data = _atlas.ptr,
|
.data = _atlas.ptr,
|
||||||
.width = ATLAS_SIZE,
|
.width = ATLAS_SIZE,
|
||||||
.height = ATLAS_SIZE,
|
.height = ATLAS_SIZE,
|
||||||
.mipmaps = 1,
|
.mipmaps = 1,
|
||||||
.format = .uncompressed_grayscale
|
.format = c.PIXELFORMAT_UNCOMPRESSED_GRAYSCALE,
|
||||||
};
|
};
|
||||||
|
|
||||||
var iter = face.iterateCharmap();
|
var iter = face.iterateCharmap();
|
||||||
@ -167,7 +173,8 @@ pub const Font = struct {
|
|||||||
try glyphs.put(glyph.index, glyph);
|
try glyphs.put(glyph.index, glyph);
|
||||||
}
|
}
|
||||||
|
|
||||||
const texture = try rl.Texture.fromImage(atlas);
|
const texture = c.LoadTextureFromImage(atlas);
|
||||||
|
// const texture = try rl.Texture.fromImage(atlas);
|
||||||
|
|
||||||
var _kb = kb.kbts_FontFromMemory(font_data.ptr, @intCast(font_data.len), 0, null, null);
|
var _kb = kb.kbts_FontFromMemory(font_data.ptr, @intCast(font_data.len), 0, null, null);
|
||||||
|
|
||||||
@ -192,17 +199,21 @@ pub const Font = struct {
|
|||||||
self.glyphs.deinit();
|
self.glyphs.deinit();
|
||||||
self.face.deinit();
|
self.face.deinit();
|
||||||
kb.kbts_FreeFont(&self.kb);
|
kb.kbts_FreeFont(&self.kb);
|
||||||
self.texture.unload();
|
c.UnloadTexture(self.texture);
|
||||||
|
// self.texture.unload();
|
||||||
allocator.free(self.font_data);
|
allocator.free(self.font_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_text(
|
pub fn render_text(
|
||||||
self: *Font,
|
self: *Font,
|
||||||
text: []const u8,
|
text: []const u8,
|
||||||
pos: rl.Vector2,
|
pos: c.Vector2,
|
||||||
|
// pos: rl.Vector2,
|
||||||
window_space: bool,
|
window_space: bool,
|
||||||
colour: rl.Color,
|
colour: c.Color,
|
||||||
background: rl.Color,
|
background: c.Color,
|
||||||
|
// colour: rl.Color,
|
||||||
|
// background: rl.Color,
|
||||||
nice_background: bool,
|
nice_background: bool,
|
||||||
count_descent: bool
|
count_descent: bool
|
||||||
) void {
|
) void {
|
||||||
@ -212,10 +223,13 @@ pub const Font = struct {
|
|||||||
if (nice_background) {
|
if (nice_background) {
|
||||||
self.render_text(
|
self.render_text(
|
||||||
text,
|
text,
|
||||||
pos.add(.{.x = 3.0, .y = -3.0}),
|
c.Vector2Add(pos, .{.x = 3.0, .y = -3.0}),
|
||||||
|
// pos.add(.{.x = 3.0, .y = -3.0}),
|
||||||
window_space,
|
window_space,
|
||||||
rl.Color.init(0, 0, 0, 255),
|
c.Color{ .r = 0, .g = 0, .b = 0, .a = 255 },
|
||||||
rl.Color.init(0, 0, 0, 0),
|
c.Color{ .r = 0, .g = 0, .b = 0, .a = 0 },
|
||||||
|
// rl.Color.init(0, 0, 0, 255),
|
||||||
|
// rl.Color.init(0, 0, 0, 0),
|
||||||
false,
|
false,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
@ -234,7 +248,8 @@ pub const Font = struct {
|
|||||||
|
|
||||||
render_pos.y += font_ascent;
|
render_pos.y += font_ascent;
|
||||||
|
|
||||||
rl.drawLine(@intFromFloat(render_pos.x), @intFromFloat(render_pos.y), rl.getScreenWidth(), @intFromFloat(render_pos.y), .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);
|
const Context = kb.kbts_CreateShapeContext(null, null);
|
||||||
const kb_font = kb.kbts_ShapePushFont(Context, &self.kb);
|
const kb_font = kb.kbts_ShapePushFont(Context, &self.kb);
|
||||||
@ -250,9 +265,12 @@ pub const Font = struct {
|
|||||||
var x_offset : f32 = 0;
|
var x_offset : f32 = 0;
|
||||||
var y_offset : f32 = 0;
|
var y_offset : f32 = 0;
|
||||||
|
|
||||||
rl.beginShaderMode(shader);
|
c.BeginShaderMode(shader);
|
||||||
rl.gl.rlSetTexture(self.texture.id);
|
c.rlSetTexture(self.texture.id);
|
||||||
rl.gl.rlBegin(rl.gl.rl_quads);
|
c.rlBegin(c.RL_QUADS);
|
||||||
|
// rl.beginShaderMode(shader);
|
||||||
|
// rl.gl.rlSetTexture(self.texture.id);
|
||||||
|
// rl.gl.rlBegin(rl.gl.rl_quads);
|
||||||
|
|
||||||
// Layout runs naively left to right.
|
// Layout runs naively left to right.
|
||||||
var Run = kb.kbts_run{};
|
var Run = kb.kbts_run{};
|
||||||
@ -277,16 +295,18 @@ pub const Font = struct {
|
|||||||
|
|
||||||
// glyph : *Glyph = table_find_pointer(*text.font.glyphs, RunGlyph.Id);
|
// glyph : *Glyph = table_find_pointer(*text.font.glyphs, RunGlyph.Id);
|
||||||
if (self.glyphs.getPtr(RunGlyph.Id)) |glyph| {
|
if (self.glyphs.getPtr(RunGlyph.Id)) |glyph| {
|
||||||
var v0 = rl.Vector2.zero();
|
var v0 = c.Vector2{};
|
||||||
var v1 = rl.Vector2.zero();
|
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 = @as(f32, @floatFromInt(glyph.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));
|
||||||
// if (count_descent) {
|
// if (count_descent) {
|
||||||
v0 = render_pos.add(.{ .x = x_offset,// + glyph.bearing_x,
|
v0 = c.Vector2Add(render_pos, .{ .x = x_offset,// + glyph.bearing_x,
|
||||||
.y = y_offset - by });// + draw_size.y });// /*- max_descent*/};
|
.y = y_offset - by });// + draw_size.y });// /*- max_descent*/};
|
||||||
|
// v0 = render_pos.add(.{ .x = x_offset,// + glyph.bearing_x,
|
||||||
|
// .y = y_offset - by });// + draw_size.y });// /*- max_descent*/};
|
||||||
// } else {
|
// } else {
|
||||||
// v0 = render_pos.add(.{
|
// v0 = render_pos.add(.{
|
||||||
// .x = x_offset,// + glyph.bearing_x,
|
// .x = x_offset,// + glyph.bearing_x,
|
||||||
@ -294,9 +314,12 @@ pub const Font = struct {
|
|||||||
// });//* - glyph.height + draw_size.y*/};
|
// });//* - glyph.height + draw_size.y*/};
|
||||||
// }
|
// }
|
||||||
|
|
||||||
v1 = v0.add(rl.Vector2{ .x = @floatFromInt(glyph.width), .y = @floatFromInt(glyph.height) });
|
v1 = c.Vector2Add(v0, c.Vector2{ .x = @floatFromInt(glyph.width), .y = @floatFromInt(glyph.height) });
|
||||||
const p0 : rl.Vector4 = .{ .x = v0.x, .y = v0.y, .z = 0.0, .w = 1.0 };
|
// v1 = v0.add(rl.Vector2{ .x = @floatFromInt(glyph.width), .y = @floatFromInt(glyph.height) });
|
||||||
const p1 : rl.Vector4 = .{ .x = v1.x, .y = v1.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 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;
|
x_offset += advance_x;
|
||||||
y_offset += advance_y;
|
y_offset += advance_y;
|
||||||
|
|
||||||
@ -316,13 +339,20 @@ pub const Font = struct {
|
|||||||
// t1 := t0 + .{cast(float, glyph.width / ATLAS_SIZE), cast(float, glyph.height / ATLAS_SIZE)};
|
// t1 := t0 + .{cast(float, glyph.width / ATLAS_SIZE), cast(float, glyph.height / ATLAS_SIZE)};
|
||||||
// }
|
// }
|
||||||
|
|
||||||
rl.gl.rlColor4ub(colour.r, colour.g, colour.b, colour.a);
|
c.rlColor4ub(colour.r, colour.g, colour.b, colour.a);
|
||||||
rl.gl.rlNormal3f(0.0, 0.0, 1.0);
|
c.rlNormal3f(0.0, 0.0, 1.0);
|
||||||
|
|
||||||
rl.gl.rlTexCoord2f(st0.x, st0.y); rl.gl.rlVertex2f(p0.x, p0.y);
|
c.rlTexCoord2f(st0.x, st0.y); c.rlVertex2f(p0.x, p0.y);
|
||||||
rl.gl.rlTexCoord2f(st0.x, st1.y); rl.gl.rlVertex2f(p0.x, p1.y);
|
c.rlTexCoord2f(st0.x, st1.y); c.rlVertex2f(p0.x, p1.y);
|
||||||
rl.gl.rlTexCoord2f(st1.x, st1.y); rl.gl.rlVertex2f(p1.x, p1.y);
|
c.rlTexCoord2f(st1.x, st1.y); c.rlVertex2f(p1.x, p1.y);
|
||||||
rl.gl.rlTexCoord2f(st1.x, st0.y); rl.gl.rlVertex2f(p1.x, p0.y);
|
c.rlTexCoord2f(st1.x, st0.y); c.rlVertex2f(p1.x, p0.y);
|
||||||
|
// rl.gl.rlColor4ub(colour.r, colour.g, colour.b, colour.a);
|
||||||
|
// rl.gl.rlNormal3f(0.0, 0.0, 1.0);
|
||||||
|
|
||||||
|
// rl.gl.rlTexCoord2f(st0.x, st0.y); rl.gl.rlVertex2f(p0.x, p0.y);
|
||||||
|
// rl.gl.rlTexCoord2f(st0.x, st1.y); rl.gl.rlVertex2f(p0.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);
|
||||||
} else {
|
} else {
|
||||||
x_offset += advance_x;
|
x_offset += advance_x;
|
||||||
y_offset += advance_y;
|
y_offset += advance_y;
|
||||||
@ -331,26 +361,29 @@ pub const Font = struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rl.gl.rlEnd();
|
c.rlEnd();
|
||||||
rl.gl.rlSetTexture(0);
|
c.rlSetTexture(0);
|
||||||
rl.endShaderMode();
|
c.EndShaderMode();
|
||||||
|
// rl.gl.rlEnd();
|
||||||
|
// rl.gl.rlSetTexture(0);
|
||||||
|
// rl.endShaderMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn size_row(self: *Font, str: []const u8, n: i32, max_width: f32) struct {rl.Vector2, f32, i32} {
|
pub fn size_row(self: *Font, str: []const u8, n: i32, max_width: f32) struct {c.Vector2, f32, i32} {
|
||||||
_ = max_width;
|
_ = max_width;
|
||||||
_ = n;
|
_ = n;
|
||||||
const Context = kb.kbts_CreateShapeContext(null, null);
|
const Context = kb.kbts_CreateShapeContext(null, null);
|
||||||
const kb_font = kb.kbts_ShapePushFont(Context, &self.kb);
|
const kb_font = kb.kbts_ShapePushFont(Context, &self.kb);
|
||||||
if (kb_font == null) {
|
if (kb_font == null) {
|
||||||
std.log.info("Could not open font!", .{});
|
std.log.info("Could not open font!", .{});
|
||||||
return .{ rl.Vector2.zero(), 0, 0 };
|
return .{ c.Vector2.zero(), 0, 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
kb.kbts_ShapeBegin(Context, kb.KBTS_DIRECTION_DONT_KNOW, kb.KBTS_LANGUAGE_DONT_KNOW);
|
kb.kbts_ShapeBegin(Context, kb.KBTS_DIRECTION_DONT_KNOW, kb.KBTS_LANGUAGE_DONT_KNOW);
|
||||||
kb.kbts_ShapeUtf8(Context, str.ptr, @intCast(str.len), kb.KBTS_USER_ID_GENERATION_MODE_CODEPOINT_INDEX);
|
kb.kbts_ShapeUtf8(Context, str.ptr, @intCast(str.len), kb.KBTS_USER_ID_GENERATION_MODE_CODEPOINT_INDEX);
|
||||||
kb.kbts_ShapeEnd(Context);
|
kb.kbts_ShapeEnd(Context);
|
||||||
|
|
||||||
var size = rl.Vector2.zero();
|
var size = c.Vector2.zero();
|
||||||
var max_descent : f32 = 0;
|
var max_descent : f32 = 0;
|
||||||
|
|
||||||
// Layout runs naively left to right.
|
// Layout runs naively left to right.
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
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 shared = @import("shared");
|
const shared = @import("shared");
|
||||||
|
|
||||||
const client = @import("client.zig");
|
const client = @import("client.zig");
|
||||||
@ -16,7 +18,7 @@ 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.0;
|
var k : f32 = 1;
|
||||||
var frame : i32 = 0;
|
var frame : i32 = 0;
|
||||||
|
|
||||||
const screen_width = 1280;
|
const screen_width = 1280;
|
||||||
@ -38,23 +40,30 @@ pub fn main() !void {
|
|||||||
defer _ = dbg_allocator.deinit();
|
defer _ = dbg_allocator.deinit();
|
||||||
try znet.init();
|
try znet.init();
|
||||||
defer znet.deinit();
|
defer znet.deinit();
|
||||||
rl.setConfigFlags(.{ .window_highdpi = true });
|
c.SetConfigFlags(c.FLAG_WINDOW_HIGHDPI);
|
||||||
rl.initWindow(screen_width, screen_height, "zzz");
|
// rl.setConfigFlags(.{ .window_highdpi = true });
|
||||||
defer rl.closeWindow();
|
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();
|
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", 42, allocator);
|
||||||
defer f.deinit(allocator);
|
defer f.deinit(allocator);
|
||||||
|
|
||||||
font.shader = try rl.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_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_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");
|
||||||
|
|
||||||
@ -71,14 +80,14 @@ pub fn main() !void {
|
|||||||
});
|
});
|
||||||
defer host.deinit();
|
defer host.deinit();
|
||||||
|
|
||||||
const peer = try host.connect(.{
|
// const peer = try host.connect(.{
|
||||||
.addr = try .init(.{
|
// .addr = try .init(.{
|
||||||
.ip = .{ .ipv4 = "127.0.0.1" },
|
// .ip = .{ .ipv4 = "127.0.0.1" },
|
||||||
.port = .{ .uint = 5000 },
|
// .port = .{ .uint = 5000 },
|
||||||
}),
|
// }),
|
||||||
.channel_limit = .max,
|
// .channel_limit = .max,
|
||||||
.data = 0,
|
// .data = 0,
|
||||||
});
|
// });
|
||||||
|
|
||||||
// connect() catch |err| switch (err) {
|
// connect() catch |err| switch (err) {
|
||||||
// error.ConnectionRefused => {
|
// error.ConnectionRefused => {
|
||||||
@ -111,23 +120,26 @@ pub fn main() !void {
|
|||||||
|
|
||||||
// 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 } };
|
// 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();
|
// rl.initAudioDevice();
|
||||||
|
|
||||||
if (rl.isAudioDeviceReady()) {
|
// if (rl.isAudioDeviceReady()) {
|
||||||
std.log.info("audio device is ready!", .{});
|
// std.log.info("audio device is ready!", .{});
|
||||||
} else {
|
// } else {
|
||||||
std.log.info("audio device is NOT ready!", .{});
|
// std.log.info("audio device is NOT ready!", .{});
|
||||||
}
|
// }
|
||||||
|
|
||||||
const music = try rl.loadMusicStream("assets/romantic-piano-431010.mp3");
|
// const music = try rl.loadMusicStream("assets/romantic-piano-431010.mp3");
|
||||||
std.log.info("{}", .{rl.isMusicValid(music)});
|
// std.log.info("{}", .{rl.isMusicValid(music)});
|
||||||
// rl.playMusicStream(music);
|
// rl.playMusicStream(music);
|
||||||
std.log.info("is music playing? {}", .{rl.isMusicStreamPlaying(music)});
|
// std.log.info("is music playing? {}", .{rl.isMusicStreamPlaying(music)});
|
||||||
|
|
||||||
var old_time : f32 = @floatCast(rl.getTime());
|
var old_time : f32 = @floatCast(c.GetTime());
|
||||||
|
// var old_time : f32 = @floatCast(rl.getTime());
|
||||||
|
|
||||||
while (!rl.windowShouldClose()) { // Detect window close button or ESC key
|
while (!c.WindowShouldClose()) {
|
||||||
const new_time : f32 = @floatCast(rl.getTime());
|
// 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;
|
var frame_time = new_time - old_time;
|
||||||
old_time = new_time;
|
old_time = new_time;
|
||||||
|
|
||||||
@ -161,144 +173,158 @@ pub fn main() !void {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
rl.pollInputEvents();
|
c.PollInputEvents();
|
||||||
|
// rl.pollInputEvents();
|
||||||
|
|
||||||
if (peer.state() == .connected) {
|
// if (peer.state() == .connected) {
|
||||||
const packet = try znet.Packet.init("Hello, Server!", 0, .reliable);
|
// const packet = try znet.Packet.init("Hello, Server!", 0, .reliable);
|
||||||
try peer.send(packet);
|
// try peer.send(packet);
|
||||||
}
|
// }
|
||||||
// _ = peer;
|
// // _ = peer;
|
||||||
|
|
||||||
// Update
|
// // Update
|
||||||
//----------------------------------------------------------------------------------
|
// //----------------------------------------------------------------------------------
|
||||||
// TODO: Update your variables here
|
// // TODO: Update your variables here
|
||||||
//----------------------------------------------------------------------------------
|
// //----------------------------------------------------------------------------------
|
||||||
|
|
||||||
rl.updateMusicStream(music);
|
// rl.updateMusicStream(music);
|
||||||
|
|
||||||
while (accumulator > dt * k) {
|
// while (accumulator > dt * k) {
|
||||||
// update(dt * cast(float) k);
|
// // update(dt * cast(float) k);
|
||||||
accumulator -= dt * k;
|
// accumulator -= dt * k;
|
||||||
gt += dt * k;
|
// gt += dt * k;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Draw
|
// // Draw
|
||||||
//----------------------------------------------------------------------------------
|
// //----------------------------------------------------------------------------------
|
||||||
rl.clearBackground(.black);
|
c.BeginDrawing();
|
||||||
|
c.ClearBackground(c.SKYBLUE);
|
||||||
|
// rl.clearBackground(.black);
|
||||||
|
|
||||||
rl.beginDrawing();
|
// rl.beginDrawing();
|
||||||
|
|
||||||
// rl.drawRectangle(screen_width - 100, 0, 100, 100, .red);
|
// // rl.drawRectangle(screen_width - 100, 0, 100, 100, .red);
|
||||||
|
|
||||||
f.render_text(
|
f.render_text(
|
||||||
"Whereas, disregard and contempt for human rights have resulted!",
|
"Whereas, disregard and contempt for human rights have resulted!",
|
||||||
rl.Vector2.init(0, 0),
|
c.Vector2{ .x = 0, .y = 0},
|
||||||
true,
|
true,
|
||||||
rl.Color.white,
|
c.WHITE,
|
||||||
rl.Color.blank,
|
c.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.gl.rlEnd();
|
||||||
// rl.endShaderMode();
|
// // rl.endShaderMode();
|
||||||
|
|
||||||
// rl.beginShaderMode(test_shader2);
|
// // rl.beginShaderMode(test_shader2);
|
||||||
// rl.gl.rlBegin(rl.gl.rl_quads);
|
// // rl.gl.rlBegin(rl.gl.rl_quads);
|
||||||
|
|
||||||
// {
|
// // {
|
||||||
// const topLeft : rl.Vector2 = .{ .x = @as(f32, @floatFromInt(rl.getScreenWidth())) / 2.0, .y = 0 };
|
// // 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 bottomRight : rl.Vector2 = .{ .x = @floatFromInt(rl.getScreenWidth()), .y = @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.gl.rlEnd();
|
||||||
// rl.endShaderMode();
|
// // rl.endShaderMode();
|
||||||
|
|
||||||
// rl.beginShaderMode(test_shader2);
|
// // rl.beginShaderMode(test_shader2);
|
||||||
// rl.gl.rlBegin(rl.gl.rl_quads);
|
// // rl.gl.rlBegin(rl.gl.rl_quads);
|
||||||
|
|
||||||
// {
|
// // {
|
||||||
// const topLeft : rl.Vector2 = .{ .x = @as(f32, @floatFromInt(rl.getScreenWidth())) / 2.0, .y = 0 };
|
// // 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 bottomRight : rl.Vector2 = .{ .x = @floatFromInt(rl.getScreenWidth()), .y = @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.gl.rlEnd();
|
||||||
// rl.endShaderMode();
|
// // 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(
|
// // f.texture.drawPro(
|
||||||
// .{.x = 0, .y = 0, .width = 4096, .height = 4096},
|
// // .{.x = 0, .y = 0, .width = 4096, .height = 4096},
|
||||||
// .{.x = 0, .y = 0, .width = 512, .height = 512 },
|
// // .{.x = 0, .y = 0, .width = 512, .height = 512 },
|
||||||
// .zero(), 0, .white);
|
// // .zero(), 0, .white);
|
||||||
|
|
||||||
// const connected_text = "Connected";
|
// // const connected_text = "Connected";
|
||||||
//const not_connected_text = "Not Connected";
|
// //const not_connected_text = "Not Connected";
|
||||||
|
|
||||||
// switch (peer.state()) {
|
// // switch (peer.state()) {
|
||||||
// .connected => rl.drawText(connected_text, @divFloor(rl.getScreenWidth(), 2) - @divFloor(rl.measureText(connected_text, f.baseSize), 2), 50, 20, .white),
|
// // .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),
|
// // 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
|
// //@divFloor(rl.getScreenWidth(), 2) - @divFloor(rl.measureText(connected_text, f.baseSize), 2), 50
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// // const font_size : i32 = 180;
|
// // // 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 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};
|
// // // const pos = rl.Vector2{.x = 0, .y = 0};
|
||||||
// // rl.drawText(connected_text, pos.x, pos.y, font_size, .white);
|
// // // 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.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.drawRectangle(pos.x, pos.y, rl.getScreenWidth(), rl.getScreenHeight(), .white);
|
||||||
// rl.drawTexturePro(tx,
|
// // rl.drawTexturePro(tx,
|
||||||
// rl.Rectangle{.x = 0, .y = 0, .width = 32, .height = 32},
|
// // rl.Rectangle{.x = 0, .y = 0, .width = 32, .height = 32},
|
||||||
// rl.Rectangle{.x = 100, .y = 100, .width = 500, .height = 500},
|
// // rl.Rectangle{.x = 100, .y = 100, .width = 500, .height = 500},
|
||||||
// .{.x = 0, .y = 0},
|
// // .{.x = 0, .y = 0},
|
||||||
// 0,
|
// // 0,
|
||||||
// .white);
|
// // .white);
|
||||||
|
|
||||||
//rl.drawLineV(.{.x = @floatFromInt(@divFloor(rl.getScreenWidth(), 2)), .y = 0}, .{.x = @floatFromInt(@divFloor(rl.getScreenWidth(), 2)), .y = @floatFromInt(rl.getScreenHeight())}, .red);
|
// //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.drawText("Congrats! You created your first window!", rl.getMouseX(), rl.getMouseY(), 20, .white);
|
||||||
//rl.drawRectangleLines(0, 0, 100, 100, .red);
|
// //rl.drawRectangleLines(0, 0, 100, 100, .red);
|
||||||
// misc.drawFPS(0, 0, frame_time, frame);
|
// // misc.drawFPS(0, 0, frame_time, frame);
|
||||||
|
|
||||||
//elf.draw();
|
// //elf.draw();
|
||||||
|
|
||||||
// rl.beginMode3D(camera);
|
// // rl.beginMode3D(camera);
|
||||||
// rl.drawSphere(.{ .x = 0, .y = 0, .z = 0 }, 1, .red);
|
// // rl.drawSphere(.{ .x = 0, .y = 0, .z = 0 }, 1, .red);
|
||||||
// rl.endMode3D();
|
// // rl.endMode3D();
|
||||||
|
|
||||||
rl.endDrawing();
|
c.EndDrawing();
|
||||||
|
// rl.endDrawing();
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
// //----------------------------------------------------------------------------------
|
||||||
|
|
||||||
rl.swapScreenBuffer();
|
c.SwapScreenBuffer();
|
||||||
|
// rl.swapScreenBuffer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user