GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Durobot/raylib-zig-examples: Raylib examples ported to Zig

BranchesTags
Open more actions menu

Latest commit

 

History

57 Commits
57 Commits

Folders and files

NameName
Last commit message
Last commit date
sshots
sshots
 
 
zig-raylib-01-core-basic-window
zig-raylib-01-core-basic-window
 
 
zig-raylib-02-core-keyboard-input
zig-raylib-02-core-keyboard-input
 
 
zig-raylib-03-core-mouse-input
zig-raylib-03-core-mouse-input
 
 
zig-raylib-04-core-input-mouse-wheel
zig-raylib-04-core-input-mouse-wheel
 
 
zig-raylib-07-core-input-gestures
zig-raylib-07-core-input-gestures
 
 
zig-raylib-08-core-2d-camera
zig-raylib-08-core-2d-camera
 
 
zig-raylib-09-core-2d-camera-mouse-zoom
zig-raylib-09-core-2d-camera-mouse-zoom
 
 
zig-raylib-11-core-3d-camera-mode
zig-raylib-11-core-3d-camera-mode
 
 
zig-raylib-12-core-3d-camera-free
zig-raylib-12-core-3d-camera-free
 
 
zig-raylib-13-core-3d-camera-first-person
zig-raylib-13-core-3d-camera-first-person
 
 
zig-raylib-14a-core-3d-picking-(original)
zig-raylib-14a-core-3d-picking-(original)
 
 
zig-raylib-14b-core-3d-picking-(2-cubes)
zig-raylib-14b-core-3d-picking-(2-cubes)
 
 
zig-raylib-15-core-world-screen
zig-raylib-15-core-world-screen
 
 
zig-raylib-17-core-window-flags
zig-raylib-17-core-window-flags
 
 
zig-raylib-19-core-window-should-close
zig-raylib-19-core-window-should-close
 
 
zig-raylib-27-core-custom-frame-control
zig-raylib-27-core-custom-frame-control
 
 
zig-raylib-29-core-split-screen
zig-raylib-29-core-split-screen
 
 
zig-raylib-30-shapes-basic-shapes
zig-raylib-30-shapes-basic-shapes
 
 
zig-raylib-32-shapes-colors-palette
zig-raylib-32-shapes-colors-palette
 
 
zig-raylib-33-shapes-logo-raylib
zig-raylib-33-shapes-logo-raylib
 
 
zig-raylib-34-shapes-logo-raylib_anim
zig-raylib-34-shapes-logo-raylib_anim
 
 
zig-raylib-35-shapes-rectangle-scaling
zig-raylib-35-shapes-rectangle-scaling
 
 
zig-raylib-36-shapes-lines-bezier
zig-raylib-36-shapes-lines-bezier
 
 
zig-raylib-37-shapes-collision-area
zig-raylib-37-shapes-collision-area
 
 
zig-raylib-38-shapes-following-eyes
zig-raylib-38-shapes-following-eyes
 
 
zig-raylib-39-shapes-easings-ball_anim
zig-raylib-39-shapes-easings-ball_anim
 
 
zig-raylib-40-shapes-easings-box_anim
zig-raylib-40-shapes-easings-box_anim
 
 
zig-raylib-41-shapes-easings-rectangle_array
zig-raylib-41-shapes-easings-rectangle_array
 
 
zig-raylib-42-shapes-draw-ring
zig-raylib-42-shapes-draw-ring
 
 
zig-raylib-43-shapes-draw-circle_sector
zig-raylib-43-shapes-draw-circle_sector
 
 
zig-raylib-44-shapes-draw-rectangle_rounded
zig-raylib-44-shapes-draw-rectangle_rounded
 
 
zig-raylib-45-shapes-top-down_lights
zig-raylib-45-shapes-top-down_lights
 
 
zig-raylib-46-textures-logo-raylib
zig-raylib-46-textures-logo-raylib
 
 
zig-raylib-49-textures-image-generation
zig-raylib-49-textures-image-generation
 
 
zig-raylib-50-textures-image-loading
zig-raylib-50-textures-image-loading
 
 
zig-raylib-53-textures-to-image
zig-raylib-53-textures-to-image
 
 
zig-raylib-54a-textures-texture-from-raw-data-(comptime-init)
zig-raylib-54a-textures-texture-from-raw-data-(comptime-init)
 
 
zig-raylib-54b-textures-texture-from-raw-data-(runtime-init)
zig-raylib-54b-textures-texture-from-raw-data-(runtime-init)
 
 
zig-raylib-68-textures-textured-curve
zig-raylib-68-textures-textured-curve
 
 
zig-raylib-69-text-raylib-fonts
zig-raylib-69-text-raylib-fonts
 
 
zig-raylib-70-text-font-spritefont
zig-raylib-70-text-font-spritefont
 
 
zig-raylib-71-text-font-filters
zig-raylib-71-text-font-filters
 
 
zig-raylib-72-text-font-loading
zig-raylib-72-text-font-loading
 
 
zig-raylib-74-text-format-text
zig-raylib-74-text-format-text
 
 
zig-raylib-75-text-input-box
zig-raylib-75-text-input-box
 
 
zig-raylib-76-text-writing-anim
zig-raylib-76-text-writing-anim
 
 
zig-raylib-77-text-rectangle-bounds
zig-raylib-77-text-rectangle-bounds
 
 
zig-raylib-83-models-box-collisions
zig-raylib-83-models-box-collisions
 
 
zig-raylib-84-models-cubicmap
zig-raylib-84-models-cubicmap
 
 
zig-raylib-85-models-first-person-maze
zig-raylib-85-models-first-person-maze
 
 
zig-raylib-86-models-geometric-shapes
zig-raylib-86-models-geometric-shapes
 
 
zig-raylib-87a-models-mesh-generation-(MemAlloc-calloc)
zig-raylib-87a-models-mesh-generation-(MemAlloc-calloc)
 
 
zig-raylib-87b-models-mesh-generation-(Zig-allocator)
zig-raylib-87b-models-mesh-generation-(Zig-allocator)
 
 
zig-raylib-93-models-orthographic-projection
zig-raylib-93-models-orthographic-projection
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 
build_example.bat
build_example.bat
 
 
build_example.sh
build_example.sh
 
 
clean_all.bat
clean_all.bat
 
 
clean_all.sh
clean_all.sh
 
 

Repository files navigation

Raylib Zig Examples

These are some of raylib (raylib on github) examples ported to Zig.

See the screenshot gallery!

Please note these are raylib 4.5 examples, they have been updated to compile with either raylib 4.5, raylib 5.0 or raylib 5.5, but the content of example programs has not been updated to match raylib 5.0 or 5.5 examples.

The examples don't use any bindings or some other intermediate layer between Zig code and raylib. Instead, Zig's built-in translate-C feature takes care of everything (well, almost, see below).

For whatever reason, example 27 (custom frame control) does not work properly on Windows, and runs with certain jerkiness on Linux. My knowledge of raylib is not enough to figure out why.

I have done some minor modifications to the code, like changing camelCase variable names to snake_case, to fit Zig naming conventions.

Some of the examples are presented in multiple versions (14a and 14b; 54a and 54b; 87a and 87b), see the comments in the Zig code.

To make things easier, some of the examples come with resource files, necessary to run them. Their authors are credited below:

resource examples author licence notes
raylib_logo.png 46, 50, 53 @raysan5 (?) ?
fudesumi.raw 54a, 54b Eiden Marsal CC-BY-NC
road.png 68 ? ?
fonts/alagard.png 69 Hewett Tsoi Freeware Atlas created by @raysan5
fonts/alpha_beta.png 69 Brian Kent (AEnigma) Freeware Atlas created by @raysan5
fonts/jupiter_crash.png 69 Brian Kent (AEnigma) Freeware Atlas created by @raysan5
fonts/mecha.png 69 Captain Falcon Freeware Atlas created by @raysan5
fonts/pixantiqua.ttf 69 Gerhard Großmann Freeware Atlas created by @raysan5
fonts/pixelplay.png 69 Aleksander Shevchuk Freeware Atlas created by @raysan5
fonts/romulus.png 69 Hewett Tsoi Freeware Atlas created by @raysan5
fonts/setback.png 69 Brian Kent (AEnigma) Freeware Atlas created by @raysan5
custom_alagard.png 70 Brian Kent (AEnigma) Freeware Atlas created by @raysan5
custom_jupiter_crash.png 70 Brian Kent (AEnigma) Freeware Atlas created by @raysan5
custom_mecha.png 70 Brian Kent (AEnigma) Freeware Atlas created by @raysan5
KAISG.ttf 71 Dieter Steffmann Freeware Kaiserzeit Gotisch font
pixantiqua.fnt, pixantiqua.png 72 Gerhard Großmann Freeware Atlas made with BMFont by @raysan5
pixantiqua.ttf 72 Gerhard Großmann Freeware
cubicmap.png 84, 85 @raysan5 CC0
cubicmap_atlas.png 84, 85 @emegeme CC0

Building the examples

Note: some examples require additional header files. I recommend downloading them to the corresponding example's folder, as described in the comments in Zig code.

Examples 39, 40, 41 need reasings.h from https://github.com/raysan5/raylib/blob/master/examples/others/reasings.h; examples 42, 43, 44 need raygui.h from https://github.com/raysan5/raygui/blob/master/src/raygui.h.

In other words, the following additional header files are necessary for their respective examples to build:

zig-raylib-39-shapes-easings-ball_anim/reasings.h
zig-raylib-40-shapes-easings-box_anim/reasings.h
zig-raylib-41-shapes-easings-rectangle_array/reasings.h
zig-raylib-42-shapes-draw-ring/raygui.h
zig-raylib-43-shapes-draw-circle_sector/raygui.h
zig-raylib-44-shapes-draw-rectangle_rounded/raygui.h

On Linux:

  1. Install Zig - download from https://ziglang.org/download/.

    Versions that work are 0.12.0, 0.12.1, 0.13.0 (current stable release), and 0.14.0 (nightly development build). 0.11.0 probably still works too (come on, really? 0.11?), but this may change in the future.

    Latest version of Zig 0.14.0 I have tested the project with was 0.14.0-dev.3237+ddff1fa4c. Later versions may or may not work, you're welcome to try them and raise an issue on github if they don't.

    Unpack your version of Zig and add its folder to environment variable PATH. In many Linux distributions this is done by adding the following line to the end of .bashrc file in your home folder (replace /path/to/zig with the actual path, of course):

    export PATH="$PATH:/path/to/zig"

    Alternatively, you can install Zig from your distribution's repositories, if they contain Zig 0.12 and up.

  2. Install raylib. Versions 4.5 and 5.0 do work. Earlier or later version may work too. Use one of the following methods:

    1. Install it from your distribution's repositories. For example on Arch you can do it with pacman -S raylib command.

      You then should be able to build examples by running zig build-exe main.zig -lc -lraylib in each example's folder. To build using build_example.sh, (optionally) edit this file, setting RAYLIB_PATH, RAYLIB_INCLUDE_PATH, RAYLIB_EXTERNAL_INCLUDE_PATH and RAYLIB_LIB_PATH variables to '' (empty string). To build using build.sh found in each folder, (optionally) edit build.sh, setting tmp_raylib_path, tmp_raylib_include_path, tmp_raylib_external_include_path and tmp_raylib_lib_path variables to '' (empty string) at lines 12 - 15.

      Alternatively, you can

    2. Build raylib from source code. Download raylib from github. Click "tar.gz" under the release you want to download, or click "Downloads", then scroll down and click "Source code (tar.gz)". Unpack the downloaded archive.

      Now, in order to make raylib and/or raylib-zig-examples compile without errors, do one of the following, depending on your version of raylib:

      1. If you're using raylib 5.0, open src\build.zig, find lines containing lib.installHeader (they should be in pub fn build), and add the following line after them:

        lib.installHeader("src/rcamera.h", "rcamera.h");

        Otherwise example 13 won't compile.

      2. If you're using raylib 4.5, do one of the following:

        a. If build.zig in raylib root folder contains the following lines:

        const lib = raylib.addRaylib(b, target, optimize);
        lib.installHeader("src/raylib.h", "raylib.h");
        lib.install();

        then edit this file - remove or comment out this line: lib.install(); Add these lines below it, before the closing }:

        lib.installHeader("src/rlgl.h", "rlgl.h");
        lib.installHeader("src/raymath.h", "raymath.h");
        lib.installHeader("src/rcamera.h", "rcamera.h");
        b.installArtifact(lib);

        b. If, on the other hand, build.zig in raylib's root folder does not contain lib.install(); (see this commit), then in src/build.zig, in function pub fn build(b: *std.Build) void, after lib.installHeader("src/raylib.h", "raylib.h");, add these lines:

        lib.installHeader("src/rlgl.h", "rlgl.h");
        lib.installHeader("src/raymath.h", "raymath.h");
        lib.installHeader("src/rcamera.h", "rcamera.h");

      In raylib root folder, run zig build -Doptimize=ReleaseSmall or zig build -Doptimize=ReleaseFast. You could also use -Doptimize=ReleaseSafe, -Doptimize=Debug or simply run zig build.

      This should create zig-out folder, with two folders inside: include and lib, these contain raylib header files and static library, respectively.

      In raylib-zig-examples, in build_example.shset RAYLIB_PATH variable to the correct raylib path and make sure the values of RAYLIB_INCLUDE_PATH, RAYLIB_EXTERNAL_INCLUDE_PATH and RAYLIB_LIB_PATH make sense.

  3. Build the examples. You can use build_example.sh to either build individual examples by providing the example number, e.g. ./build_example.sh 03, or build them all: ./build_example.sh all.

    You can also run build.sh contained in each example's folder. raylib paths and Zig build mode set within each build.sh are used in this case.

    clean_all.sh and clean.sh in examples' folders can be used to delete binaries generated by the compiler.

On Windows:

  1. Install Zig - download from https://ziglang.org/download/.

    Versions that work are 0.12.0, 0.12.1, 0.13.0 (current stable release), and 0.14.0 (nightly development build). 0.11.0 probably still works too (come on, really? 0.11?), but this may change in the future.

    Latest version of Zig 0.14.0 I have tested the project with was 0.14.0-dev.3237+ddff1fa4c. Later versions may or may not work, you're welcome to try them and raise an issue on github if they don't.

    Unpack your version of Zig and add its folder to environment variable PATH.

  2. Install raylib. These examples were built using raylib 4.5.0, but an earlier or later version may work too.

    Build raylib from source code. Download raylib from github. Click "zip" under the release you want to download, or click "Downloads", then scroll down and click "Source code (zip)".

    Unpack the downloaded archive. Now, in order to make raylib and/or raylib-zig-examples compile without errors, do one of the following, depending on your version of raylib:

    1. If you're using raylib 5.0, open src\build.zig, find lines containing lib.installHeader (they should be in pub fn build), and add the following line after them:

      lib.installHeader("src/rcamera.h", "rcamera.h");

      Otherwise example 13 won't compile.

    2. If you're using raylib 4.5, do one of the following:

      a. If build.zig in raylib root folder contains the following lines:

      const lib = raylib.addRaylib(b, target, optimize);
      lib.installHeader("src/raylib.h", "raylib.h");
      lib.install();

      then edit this file - remove or comment out this line: lib.install(); Add these lines below it, before the closing }:

      lib.installHeader("src/rlgl.h", "rlgl.h");
      lib.installHeader("src/raymath.h", "raymath.h");
      lib.installHeader("src/rcamera.h", "rcamera.h");
      b.installArtifact(lib);

      b. If, on the other hand, build.zig in raylib's root folder does not contain lib.install(); (see this commit), then in src/build.zig, in function pub fn build(b: *std.Build) void, after lib.installHeader("src/raylib.h", "raylib.h");, add these lines:

      lib.installHeader("src/rlgl.h", "rlgl.h");
      lib.installHeader("src/raymath.h", "raymath.h");
      lib.installHeader("src/rcamera.h", "rcamera.h");

    In raylib root folder, run zig build -Doptimize=ReleaseSmall or zig build -Doptimize=ReleaseFast.

    Warning: leaving out -Doptimize parameter, using -Doptimize=Debug or -Doptimize=ReleaseSafe currently causes compilation of raylib-zig-examples to fail in ReleaseSmall and ReleaseFast modes down the road. You will see errors similar to these:

    error: lld-link: undefined symbol: __stack_chk_fail
    error: lld-link: undefined symbol: __stack_chk_guard
    

    Running zig build... should create zig-out folder, with two folders inside: include and lib, these contain raylib header files and static library, respectively.

    In raylib-zig-examples, in build_example.batset RAYLIB_PATH variable to the correct raylib path and make sure the values of RAYLIB_INCLUDE_PATH, RAYLIB_EXTERNAL_INCLUDE_PATH and RAYLIB_LIB_PATH make sense.

  3. Build the examples. You can use build_example.bat to either build individual examples by providing the example number, e.g. build_example.bat 03, or build them all: build_example.bat all.

    You can also run build.bat contained in each example's folder. raylib paths and Zig build mode set within each build.bat are used in this case.

    clean_all.bat and clean.bat in examples' folders can be used to delete binaries generated by the compiler.

About

Raylib examples ported to Zig

Topics

raylibraylib-zigzigziglang

Resources

Readme
Activity

Stars

56 stars

Watchers

0 watching

Forks

3 forks
Report repository

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.