Mojo-raylib: Complete raylib v6 bindings for Mojo

Inspired by the recent VOD by Mr. Azozin, I decided to create fully codegen’ed bindings for raylib.

I must also note this implementation GitHub - andresnowak/raylib-mojo · GitHub , but it unfortunately appears to be abandoned.

Installation

[workspace]
channels = ["https://conda.modular.com/max", "https://prefix.dev/conda-forge"]
platforms = ["osx-arm64", "linux-64"]
preview = ["pixi-build"]

[dependencies]
mojo_raylib = { path = "/path/to/mojo-raylib" }

[tasks.run]
cmd = "mojo build main.mojo -Xlinker -L$CONDA_PREFIX/lib -Xlinker -lmojo_raylib_shim -Xlinker -lraylib -o .pixi/main && .pixi/main"

Usage

Almost everything, including structs, is translated into mojo-safe proxies for the public api, so using mojo-raylib is not any different from using any other bindings lib in another language. The only difference is that the function names are transformed to snake_case to be inline with the language standard:

from mojo_raylib import Color, init_window, close_window, window_should_close
from mojo_raylib import begin_drawing, end_drawing, clear_background, draw_text, set_target_fps

def main():
    init_window(800, 450, "hello")
    set_target_fps(60)

    while not window_should_close():
        begin_drawing()
        clear_background(Color(245, 245, 245, 255))
        draw_text("Hello, raylib!", 190, 200, 20, Color(50, 50, 50, 255))
        end_drawing()
    close_window()

More examples

The repository contains a few examples ported from the original raylib repo, including audio, shaders, textures, and other parts of the lib.

Is the “mojo” prefix in the import name really necessary?

It feels more in line with the naming convention of the other libs both in python (e.g., raylibpy), and most other mojo libs having this prefix. Plus it’s a clear distinction from the original raylib