Zig monthly, April 2022

OS interop, Graphics, WebAssembly, Talks, Wren language & more

nanovg-zig

@fabioarnold has released nanovg-zig:

A hardware-accelerated vector graphics library. I use this library to build the user interface of my (free) pixel art editor MiniPixel. I’ve since rewritten it in Zig and ported it to Wasm/WebGL.

You can use it to draw (blurred) text, arbitrary bezier curved shapes (with holes) and of course gradients. You can try the WebAssembly example here and find the source on GitHub here

wala: A language to simplify WebAssembly Text syntax

wala is a language trying to simplify WebAssembly Text syntax “while keeping the full expressiveness and retro-compatibility. Unwittingly becoming a Zig toolchain for WASM. - It aims to be for WASM what YAML is for JSON.”

func $fib export()
  u64 $n -> ?
  if {$n <= 2}
    1
    +
      $fib{$n - 2}
      $fib{$n - 1}

@CalmSystem cautions:

This is my first zig project […] FizzBuzz and others are already working, but some work is still needed before the first proper release.

Tile-based, multithreaded 3D software renderer

@danielabbott created a simple software renderer in Zig, a cool codebase to learn from if you’re into that sort of thing:

Simple bin-packed texture atlas

@mitchellh dropped a gist which provides a simple packed texture atlas in pure Zig, with no dependencies other than the stdlib.

zlog: Zero-Allocation Logging

Inspired by Go’s zerolog, @candrewlee14 has released zlog, a zero-allocation logging library.

Bindings for Wren (“a small, fast, class-based concurrent scripting language”)

@dantecatalfamo released wren-zig which provides Zig bindings to Wren, a fast lua-sized scripting language with classes and concurrency.

System.print("Hello, world!")

class Wren {
  flyTo(city) {
    System.print("Flying to %(city)")
  }
}

var adjectives = Fiber.new {
  ["small", "clean", "fast"].each {|word| Fiber.yield(word) }
}

while (!adjectives.isDone) System.print(adjectives.call())

(If you like that, you may also be interested in Buzz, “a small/lightweight typed scripting language written in Zig”, from last month’s article.)

snowflake simulator

@Rekihyt has built a simple snowflake simulator using OpenGL:

zig-arg: CLI flags, subcommands & nested subcommands

zig-arg is a clap-rs inspired Command Line Argument parser for Zig which support flags, subcommand and nested subcommands out of the box.

It looks quite slick, check out the Reddit discussion for some alternatives as well.

Zig MiLAN Party 2023 talks

The first-ever European Zig meetup was held in Milan, Italy - the Zig MiLAN Party! Here were some of the talks presented/recorded:

Windows explorer integration in Zig

Ever wondered how applications on Windows integrate with the right-click menu, and overlay their own pixels on files in the explorer? @squeek502’s new watchedoverlay project does just that, giving you the ability to right-click -> “Toggle watched” which renders a “Watched” green checkmark over files:

Jakub Konka’s work on iOS developer experience

I’m ecstatic this work is ongoing, so I had to include this! This work isn’t complete or very usable currently, as Jakub cautions below, but here are three repositories you may want to keep an eye on if you’re interested in the future Zig developer experience for iOS app development:

  • https://github.com/kubkon/ZigKit ‘will hopefully become a goto lib for low-level Apple frameworks bindings in Zig’
  • https://github.com/kubkon/zignature ‘the goto solution for codesigning your Apple apps with Zig (hopefully without even requiring access to frameworks, but time will tell if that is even possible)’
  • https://github.com/kubkon/zig-deploy ‘the final piece of the puzzle […] it uses ZigKit internally for low-level Apple bindings, including the undocumented and private framework MobileDevice which is used by Xcode (and oss tool ios-deploy) to speak to an Apple device such as an iPhone.’

Early days, and I strongly advise against using zig-deploy - wouldn’t want anyone to brick their phone! Having said that, any questions about any of this, you know where to find me!

fast polygon tesselator

I wrote a fast polygon tessellator (triangulates in one pass) in pure zig which can be used for vector graphics.

It’s able to handle complex cases and can draw the tiger head svg. This video shows what it’s doing to fill a whisker of the tiger. The demo app is here and the zig implementation is here

Be sure to check out the discussion on Reddit, too, which goes into further detail about how it works:

The vertices are chosen from a vertex queue similar to the y-monotone triangulation so most of the algorithm is making sure that each sub-polygon span is a y-monotone. And determining which regions to fill triangles depends on the winding rule. Currently, this tessellator does the evenodd fill rule but it shouldn’t be too hard to add the nonzero fill rule. :)

The Zig compiler can finally build itself

In case you missed it, the Zig self-hosted compiler has had a great deal of progress and can finally build itself.

This is a huge milestone for Zig, and while there’s still much work to do before the new compiler can be shipped to everyone - it’s looking like we’ll be able to have Zig-implemented-in-Zig (rather than C++) very soon which should lead to an explosion of improvements and new contributors.

Exciting times!

Mach engine updates

With Mach we’ve seen quite a burst of contributors! Thanks to @johanfforsberg, @d3m1gd, @zargio, @andoryuuta and more we’ve now got a great WebGPU example showcase showing off low-level graphics and a great starting point for anyone interested in learning WebGPU with Zig:

There’s also major work underway by @iddev5 to add Browser WebAssembly support-making Mach even more cross-platform, as well as @PiergiorgioZagaria’s work to create a ShaderToy-esque application called shaderexp which live-reloads WGSL shaders as you save in your editor.

glTF 2.0 in pure Zig

@kooparse has been working on a pure Zig parser for glTF 2.0:

Loading 3D models fully in Zig, without any parser/loader in other languages would be great, so I made a glTF 2.0 parser. I’m using it on my engine, and it works well enough for others' project usage (I guess). There are also some helpers to get local and global positions of each node and something to load data from binary. ‘Hope it could help some! 🙂

zig-gamedev updates

@michal-z is at it again, this time leveraging mach/gpu to bring his work to Windows/Linux/macOS:

  • triangle_wgpu is a simple but fairly complete app showing the ins-and-outs of WebGPU, creating bind group layouts, render peipelines, managing vertex/index/uniform buffers, depth buffers, etc.
  • procedural_mesh_wgpu leverages his zmesh library to efficiently draw several procedurally generated meshes, use simple physically-based shading, camera movement, and more.
  • Speaking of zmesh, v0.2 is out. It’s a small library/bindings for loading, generating, processing and optimizing triangle meshes - using par_shapes, meshoptimizer, and cgltf behind the scenes.

brucelib updates

You might also want to keep an eye on @hazeycode’s brucelib - although early stages, work continues and it’s recently gained an audio module which provides a basic mixer and wav file loader!

Thanks for reading!

If you like my work on zigmonthly, Mach engine, etc. consider sponsoring me on GitHub so I can do even more of it!

Subscribe

Enter your email to get one Zig newsletter per month (or use this RSS feed):