Skip to content

hexops/mach-examples

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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!

About

Mach core & engine examples

Resources

License

Unknown and 3 other licenses found

Licenses found

Unknown
LICENSE
BSD-3-Clause
LICENSE.webgpu-samples
Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages