/mach-examples

Mach core & engine examples

Primary LanguageZigOtherNOASSERTION

Mach engine & core examples

example-advanced-gen-texture-light example-boids example-textured-cube

More screenshots / example showcase: https://machengine.org/gpu

Run examples

git clone --recursive https://github.com/hexops/mach-examples
cd mach-examples/
zig build run-textured-cube

Use Mach engine in your own project

First run zig init-exe to create your project, then add Mach as a Git submodule:

git submodule add https://github.com/hexops/mach libs/mach

In your build.zig, use mach.App:

const std = @import("std");
const mach = @import("libs/mach/build.zig");

pub fn build(b: *std.build.Builder) !void {
    const target = b.standardTargetOptions(.{});
    const mode = b.standardReleaseOptions();

    const app = try mach.App.init(b, .{
        .name = "myapp",
        .src = "src/main.zig",
        .target = target,
        .deps = &[_]std.build.Pkg{},
    });
    app.setBuildMode(mode);
    try app.link(.{});
    app.install();

    const run_cmd = try app.run();
    run_cmd.dependOn(b.getInstallStep());

    const run_step = b.step("run", "Run the app");
    run_step.dependOn(run_cmd);
}

Your src/main.zig file can now const mach = @import("mach"); and you can run your code using zig build run.

Cross-compilation

You can cross-compile to every OS using:

zig build -Dtarget=x86_64-windows
zig build -Dtarget=x86_64-linux
zig build -Dtarget=x86_64-macos.12
zig build -Dtarget=aarch64-macos.12

WebAssembly examples

We don't yet support graphics in the browser (hexops/mach#90) but you can run the virtual piano example in the browser:

zig build run-sysaudio -Dtarget=wasm32-freestanding

Then navigate to http://localhost:8080/sysaudio.html and click inside the border area + type on your keyboard to play notes.

Join the community

Join the Mach community on Discord or Matrix to discuss this project, ask questions, get help, etc.

Issues

Issues are tracked in the main Mach repository.

Contributing

We're actively looking for contributors to port WebGPU examples to Zig, and are always looking for useful small examples we can include. If you think you might have one, definitely share it with us so we can consider including it!