Skip to content

Commit

Permalink
feat: zig rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
FrothyMarrow committed May 22, 2024
1 parent 474d72b commit 3f1786b
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 375 deletions.
23 changes: 10 additions & 13 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,26 @@ pub fn build(b: *std.Build) void {
.link_libc = true,
.optimize = mode,
.target = target,
.root_source_file = .{
.src_path = .{
.owner = b,
.sub_path = "src/app.zig",
},
},
});

phy.defineCMacro("GL_SILENCE_DEPRECATION", &.{});
phy.defineCMacro("GLFW_INCLUDE_GLCOREARB", &.{});

phy.addIncludePath(.{
.src_path = .{ .owner = b, .sub_path = "include" },
});
phy.addCSourceFiles(.{
.root = .{
.src_path = .{ .owner = b, .sub_path = "src" },
},
.files = &.{
"main.c",
"vector.c",
},
});
phy.linkSystemLibrary("glfw");
phy.linkFramework("OpenGL");

b.installArtifact(phy);

const phy_run = b.addRunArtifact(phy);
const run_step = b.step("run", "Run the phy binary");
const run_step = b.step(
"run",
"Run the phy binary",
);
run_step.dependOn(&phy_run.step);
}
13 changes: 0 additions & 13 deletions include/vector.h

This file was deleted.

45 changes: 45 additions & 0 deletions src/app.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const std = @import("std");
const win = @import("window.zig");
const render = @import("render.zig");

const AppError = error{
WindowCreationError,
RendererCreationError,
};

pub fn main() AppError!void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();

const window = win.create(allocator, .{
.title = "Phy",
.width = 800,
.height = 600,
}) catch {
std.debug.print("Failed to create App window\n", .{});
return error.WindowCreationError;
};

defer allocator.destroy(window);
defer window.deinit();

const renderer = render.create(allocator) catch {
std.debug.print("Failed to create App renderer\n", .{});
return error.RendererCreationError;
};

defer allocator.destroy(renderer);

while (!window.shouldClose()) {
window.pollEvents();

renderer.clearColor(.{
.r = 0.2,
.g = 0.3,
.b = 0.3,
.a = 1.0,
});

window.swapBuffers();
}
}
Loading

0 comments on commit 3f1786b

Please sign in to comment.