Trying out sokol in zig
Go to file
2024-07-04 16:23:16 +02:00
src Added live error checking 2024-07-04 16:23:16 +02:00
.gitignore Initial 2024-06-09 00:48:23 +02:00
build.zig Added live error checking 2024-07-04 16:23:16 +02:00
build.zig.zon Cleanup 2024-06-11 01:17:51 +02:00
compile_shaders.bat Uniforms and compiling shaders with a script 2024-06-11 20:43:41 +02:00
readme.md Added live error checking 2024-07-04 16:23:16 +02:00
todo.todo Circle that doesnt stretch 2024-06-12 02:04:37 +02:00

A little learning playground of sokol in zig. Started on the gamejam at Decentrala, 9th June 2024.

The goal of this project is not fixed, and is just to try out some sokol features. But here's a few things I'd like to try out:

  • Draw a circle
  • Load and render textures
  • Render a 3D object
  • Compile it for WebAssembly and run it in the browser

Build

To build, you need to have zig master (you can use zvm to help you with this). Then just zig build run and that should be it!

Note that if you change shaders, you have to recompile them manually - run compile_shaders.bat.

Live error checking

This project has been configured so that zls can show live compile errors on save. To make it work, you need to set these zls config params (in VSCode just copy these to your preferences):

    "zig.zls.enableBuildOnSave": true,
    "zig.zls.buildOnSaveStep": "check"

Also, if you're in VSCode, install ErrorLens extension so you can see the errors inline.

Why zig?

Zig is a low level language and toolchain that is designed as a "better C". Its main goal is to be simple, robust and fast. A few strong points:

  • It can cross-compile from any platform to any platform.
  • It can include C headers and you can use it in zig directly.
  • It has a built-in build system that is also written in zig, so no other build systems like cmake are needed.
  • Unlike C++, it's not OOP, there are no hidden constructor and destructor calls and overcomplicated copy/move rules.
  • Unlike C, it solves A LOT of problems of C, and is MUCH harder to shoot yourself in the foot.
  • There are no hidden allocations, everything that is heap-allocating has to be done explicitely.
  • It has a powerful metaprogramming facility "comptime", which provides full static reflection.
  • I can go on listing more cool features, but that is enough for now.. :)

Why sokol?

Sokol is a cross platform graphics library with minimal footprint that can compile to any backend like DirectX, OpenGL, Vulcan, Metal or even WebAssembly.