No description
Find a file
2020-11-27 17:51:59 -06:00
examples Starting out with object orientation 2020-05-04 15:06:13 +10:00
lib set matrix math to use f64 instead of double 2020-11-27 17:51:59 -06:00
logo Update and move logo 2020-06-02 21:05:36 +10:00
raylib@7ef114d1da add raylib submodule 2020-05-23 03:46:54 -05:00
.gitignore Functions generated automatically 2020-05-09 23:12:17 +10:00
.gitmodules add raylib submodule 2020-05-23 03:46:54 -05:00
build.zig add argument to Pkg().link to enable linking to system raylib 2020-05-24 06:04:21 -05:00
lib.zig macosx not in zig 0.7 build 2020-11-27 15:17:50 -06:00
LICENSE Some minor improvements 2020-02-22 20:43:30 +10:00
projectSetup.sh adapt projectSetup.sh for use with lib.zig and raylib submodule 2020-05-24 21:59:40 -05:00
ReadMe.md Update ReadMe.md 2020-06-24 16:11:33 +10:00

logo

raylib-zig

Manually tweaked, auto generated raylib bindings for zig.

Bindings tested on raylib version 3.0 and Zig 0.6.0

Thanks to jessrud and sacredbirdman for their contributions to this binding.

The binding currently only supports a subset of raylib. For more information read here. Some of these issues are fixed on the workaround branch, however, this is entirely experimental.

Example

We can copy the default example with some minor changes:

usingnamespace @import("raylib");

pub fn main() anyerror!void
{
    // Initialization
    //--------------------------------------------------------------------------------------
    const screenWidth = 800;
    const screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "MyWindow");

    SetTargetFPS(60);               // Set our game to run at 60 frames-per-second
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();

            ClearBackground(WHITE);

            DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);

        EndDrawing();
        //----------------------------------------------------------------------------------
    }

    // De-Initialization
    //--------------------------------------------------------------------------------------
    CloseWindow();        // Close window and OpenGL context
    //--------------------------------------------------------------------------------------
}

Technical restrictions

Due to zig being a relatively new language it does not have full C ABI support at the moment. For use that mainly means we can't use any functions that return structs that are less than 16 bytes large. Here is an incomplete list of some functions affected by this:

  • DrawCircleV
  • DrawRectangleRec
  • DrawModel and all its variations

Parts of these issue are resolved on the workaround branch

Building the examples

To build all available examples simply zig build examples. To list available examples run zig build --help. If you want to run and examples, say basic_window run zig build basic_window

Building and using

  • Install raylib
  • Execute projectSetup.sh project_name, this will create a folder with the name specified
  • You can copy that folder anywhere you want and edit the source
  • Run zig build run at any time to test your project

When is the binding updated?

I plan on updating it every mayor release (2.5, 3.0, etc.). Keep in mind these are technically header files, so any implementation stuff should be updatable with some hacks on your side.

What's to be done?

  • (Done) Set up a proper package build and a build script for the examples
  • Port all the examples
  • Object orientation