- Notifications
You must be signed in to change notification settings - Fork208
Manually tweaked, auto-generated raylib bindings for zig.https://github.com/raysan5/raylib
License
raylib-zig/raylib-zig
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Manually tweaked, auto-generatedraylib bindings for zig.
Bindings tested on raylib version 5.6-dev and Zig 0.15.1
Thanks to all thecontributors for their help with thisbinding.
constrl=@import("raylib");pubfnmain()anyerror!void {// Initialization//--------------------------------------------------------------------------------------constscreenWidth=800;constscreenHeight=450;rl.initWindow(screenWidth,screenHeight,"raylib-zig [core] example - basic window");deferrl.closeWindow();// Close window and OpenGL contextrl.setTargetFPS(60);// Set our game to run at 60 frames-per-second//--------------------------------------------------------------------------------------// Main game loopwhile (!rl.windowShouldClose()) {// Detect window close button or ESC key// Update//----------------------------------------------------------------------------------// TODO: Update your variables here//----------------------------------------------------------------------------------// Draw//----------------------------------------------------------------------------------rl.beginDrawing();deferrl.endDrawing();rl.clearBackground(.white);rl.drawText("Congrats! You created your first window!",190,200,20,.light_gray);//---------------------------------------------------------------------------------- }}
To build all available examples simplyzig build examples. To list available examples runzig build --help. If youwant to run an example, saybasic_window runzig build basic_window
- Execute
project_setup.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 runat any time to test your project
Download and add raylib-zig as a dependency by running the following command in your project root:
zig fetch --save git+https://github.com/raylib-zig/raylib-zig#develThen add raylib-zig as a dependency and import its modules and artifact in yourbuild.zig:
constraylib_dep=b.dependency("raylib_zig", .{ .target=target, .optimize=optimize,});constraylib=raylib_dep.module("raylib");// main raylib moduleconstraygui=raylib_dep.module("raygui");// raygui moduleconstraylib_artifact=raylib_dep.artifact("raylib");// raylib C library
Now add the modules and artifact to your target as you would normally:
exe.linkLibrary(raylib_artifact);exe.root_module.addImport("raylib",raylib);exe.root_module.addImport("raygui",raygui);
If you additionally want to support Web as a platform with emscripten, you will need to useemsdk by importingraylib-zig's build script withconst rlz = @import("raylib_zig"); and then accessing like described hereExporting for web.Refer to raylib-zig's project template on how to use them.
raylib allows customisations of certain parts of its build process such as choosing an OpenGL version, building as ashared library or not including certain modules. You can optionally pass these options to raylib-zig dependency like so
constraylib_dep=b.dependency("raylib_zig", .{ .target=target, .optimize=optimize, .linkage=.dynamic,// Build raylib as a shared library .opengl_version=rlz.OpenglVersion.gl_2_1,// Use OpenGL 2.1 (requires importing raylib-zig's build script)});
raylib lets the user enable and disable options for different features, loading different file formats for images,fonts, 3D models and audio, linkage variants. You can specify these options for your raylib-zig build by defining thecorresponding C macro before you link with it, e.g.:
raylib_artifact.root_module.addCMacro("SUPPORT_FILEFORMAT_JPG","");
To export your project for the web, first add emsdk to your dependencies.Its also possible to use a local emsdk folder.
zig fetch --save=emsdk git+https://github.com/emscripten-core/emsdk#4.0.9
Add this to your build method to build for the web
if (target.query.os_tag==.emscripten) {constemsdk=rlz.emsdk;constwasm=b.addLibrary(.{ .name=<your_project_name>, .root_module=exe_mod, });constinstall_dir:std.Build.InstallDir= .{ .custom="web" };constemcc_flags=emsdk.emccDefaultFlags(b.allocator, .{ .optimize=optimize });constemcc_settings=emsdk.emccDefaultSettings(b.allocator, .{ .optimize=optimize });constemcc_step=emsdk.emccStep(b,raylib_artifact,wasm, .{ .optimize=optimize, .flags=emcc_flags, .settings=emcc_settings, .install_dir=install_dir, });b.getInstallStep().dependOn(emcc_step);consthtml_filename=trystd.fmt.allocPrint(b.allocator,"{s}.html", .{wasm.name});constemrun_step=emsdk.emrunStep(b,b.getInstallPath(install_dir,html_filename), &.{}, );emrun_step.dependOn(emcc_step);run_step.dependOn(emrun_step);}
then you can run
zig build -Dtarget=wasm32-emscripten
once that is finished, the exported project should be located atzig-out/web
I plan on updating it every mayor release (2.5, 3.0, etc.). Keep in mind these are technically header files, so anyimplementation stuff should be updatable with some hacks on your side.
- (Done) Set up a proper package build and a build script for the examples
- Port all the examples
- Member functions/initialisers
About
Manually tweaked, auto-generated raylib bindings for zig.https://github.com/raysan5/raylib
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
