├── .gitattributes ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── build.zig ├── build.zig.zon ├── emcc.zig ├── examples ├── audio │ ├── module_playing.zig │ ├── music_stream.zig │ ├── raw_stream.zig │ └── sound_loading.zig ├── core │ ├── 2d_camera.zig │ ├── 2d_camera_mouse_zoom.zig │ ├── 2d_camera_platformer.zig │ ├── 3d_camera_first_person.zig │ ├── 3d_camera_free.zig │ ├── 3d_picking.zig │ ├── basic_screen_manager.zig │ ├── basic_window.zig │ ├── basic_window_web.zig │ ├── input_keys.zig │ ├── input_mouse.zig │ ├── input_mouse_wheel.zig │ ├── input_multitouch.zig │ └── window_flags.zig ├── gui │ └── message_box.zig ├── models │ ├── models_heightmap.zig │ └── resources │ │ └── heightmap.png ├── shaders │ ├── raymarching.zig │ └── texture_outline.zig ├── shapes │ ├── basic_shapes.zig │ ├── bouncing_ball.zig │ ├── collision_area.zig │ ├── colors_palette.zig │ ├── draw_circle_sector.zig │ ├── draw_rectangle_rounded.zig │ ├── draw_ring.zig │ ├── following_eyes.zig │ ├── lines_bezier.zig │ ├── logo_raylib.zig │ ├── logo_raylib_anim.zig │ └── rectangle_scaling.zig ├── text │ ├── text_format_text.zig │ ├── text_raylib_fonts.zig │ └── text_writing_anim.zig └── textures │ ├── sprite_anim.zig │ ├── textures_background_scrolling.zig │ └── textures_image_loading.zig ├── lib ├── generate_functions.py ├── preludes │ ├── raygui-ext-prelude.zig │ ├── raygui-prelude.zig │ ├── raylib-ext-prelude.zig │ ├── raylib-prelude.zig │ ├── raymath-ext-prelude.zig │ ├── raymath-prelude.zig │ ├── rlgl-ext-prelude.zig │ └── rlgl-prelude.zig ├── raygui-ext.zig ├── raygui.h ├── raygui.zig ├── raylib-ext.zig ├── raylib.h ├── raylib.zig ├── raymath-ext.zig ├── raymath.h ├── raymath.zig ├── rlgl-ext.zig ├── rlgl.h └── rlgl.zig ├── logo └── logo.png ├── project_setup.ps1 ├── project_setup.sh └── resources ├── audio ├── country.mp3 ├── mini1111.xm ├── sound.wav └── target.ogg ├── shaders └── glsl330 │ ├── outline.fs │ └── raymarching.fs ├── text └── fonts │ ├── alagard.png │ ├── alpha_beta.png │ ├── jupiter_crash.png │ ├── mecha.png │ ├── pixantiqua.png │ ├── pixelplay.png │ ├── romulus.png │ └── setback.png └── textures ├── cyberpunk_street_background.png ├── cyberpunk_street_foreground.png ├── cyberpunk_street_midground.png ├── fudesumi.png └── scarfy.png /.gitattributes: -------------------------------------------------------------------------------- 1 | # Don't include raylib headers in language analysis 2 | *.h linguist-vendored 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | zig-cache/ 2 | .zig-cache/ 3 | zig-out/ 4 | .idea/ 5 | Project/* 6 | libraylib.a 7 | **/.DS_Store 8 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to raylib-zig 2 | 3 | Thank you for your interest in contributing to raylib-zig. There are some guidelines you will need to follow in order 4 | to get your contribution added to the project as fast as possible. 5 | 6 | ## Updates to the Zig version 7 | 8 | This binding will never target any Zig version newer than the latest release. Fixes that don't affect compatibility 9 | with the latest release and allow the binding to be used on a pre-release/HEAD version of Zig may be accepted. 10 | 11 | ## Updates to the raylib version 12 | 13 | Usually this binding will stay on the latest release commit for raylib, but occasionally upgrade to a HEAD version when 14 | there are changes made, critical to the Zig build. In those cases there will be a release tag on GitHub, marking the 15 | latest commit that uses a raylib release. Previously there were extra branches for older versions of raylib, but this 16 | approach was abandoned. 17 | 18 | ## Updates to the binding files 19 | 20 | raylib-zig is built mostly through the `generate_functions.py` script. It creates the definitions to access the raw C 21 | functions, and creates aliases with proper Zig argument and return types, Zig style names and errors. The raylib types, 22 | however, are created manually and should only be updated in their respective preludes: 23 | - `lib/preludes/raylib-prelude.zig` for raylib types 24 | - `lib/preludes/raymath-prelude.zig` for raymath types 25 | - `lib/preludes/rlgl-prelude.zig` for rlgl types 26 | - `lib/preludes/raygui-prelude.zig` for raygui types 27 | 28 | Before any commit you make, you should always run `generate_functions.py` to ensure your changes are persistent 29 | throughout other updates. 30 | 31 | ## Updates to the build files 32 | 33 | Updates to raylib-zig's `build.zig`, as any other contributions to binding files, are very welcome. However, when 34 | updating public names or APIs, you should always ensure that the project template in `project_setup.sh` still 35 | works with them. 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Nikolas Wipper 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![logo](https://github.com/Not-Nik/raylib-zig/raw/devel/logo/logo.png) 2 | 3 | # raylib-zig 4 | 5 | Manually tweaked, auto-generated [raylib](https://github.com/raysan5/raylib) bindings for zig. 6 | 7 | Bindings tested on raylib version 5.6-dev and Zig 0.14.0 8 | 9 | Thanks to all the [contributors](https://github.com/Not-Nik/raylib-zig/graphs/contributors) for their help with this 10 | binding. 11 | 12 | ## Example 13 | 14 | ```zig 15 | const rl = @import("raylib"); 16 | 17 | pub fn main() anyerror!void { 18 | // Initialization 19 | //-------------------------------------------------------------------------------------- 20 | const screenWidth = 800; 21 | const screenHeight = 450; 22 | 23 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window"); 24 | defer rl.closeWindow(); // Close window and OpenGL context 25 | 26 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 27 | //-------------------------------------------------------------------------------------- 28 | 29 | // Main game loop 30 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 31 | // Update 32 | //---------------------------------------------------------------------------------- 33 | // TODO: Update your variables here 34 | //---------------------------------------------------------------------------------- 35 | 36 | // Draw 37 | //---------------------------------------------------------------------------------- 38 | rl.beginDrawing(); 39 | defer rl.endDrawing(); 40 | 41 | rl.clearBackground(.white); 42 | 43 | rl.drawText("Congrats! You created your first window!", 190, 200, 20, .light_gray); 44 | //---------------------------------------------------------------------------------- 45 | } 46 | } 47 | ``` 48 | 49 | ## Building the examples 50 | 51 | To build all available examples simply `zig build examples`. To list available examples run `zig build --help`. If you 52 | want to run an example, say `basic_window` run `zig build basic_window` 53 | 54 | ## Building and using 55 | 56 | ### Using raylib-zig's template 57 | 58 | * Execute `project_setup.sh project_name`, this will create a folder with the name specified 59 | * You can copy that folder anywhere you want and edit the source 60 | * Run `zig build run` at any time to test your project 61 | 62 | ### In an existing project (e.g. created with `zig init`) 63 | 64 | Download and add raylib-zig as a dependency by running the following command in your project root: 65 | 66 | ``` 67 | zig fetch --save git+https://github.com/Not-Nik/raylib-zig#devel 68 | ``` 69 | 70 | Then add raylib-zig as a dependency and import its modules and artifact in your `build.zig`: 71 | 72 | ```zig 73 | const raylib_dep = b.dependency("raylib_zig", .{ 74 | .target = target, 75 | .optimize = optimize, 76 | }); 77 | 78 | const raylib = raylib_dep.module("raylib"); // main raylib module 79 | const raygui = raylib_dep.module("raygui"); // raygui module 80 | const raylib_artifact = raylib_dep.artifact("raylib"); // raylib C library 81 | ``` 82 | 83 | Now add the modules and artifact to your target as you would normally: 84 | 85 | ```zig 86 | exe.linkLibrary(raylib_artifact); 87 | exe.root_module.addImport("raylib", raylib); 88 | exe.root_module.addImport("raygui", raygui); 89 | ``` 90 | 91 | If you additionally want to support Web as a platform with emscripten, you will need to use `emcc.zig` by importing 92 | raylib-zig's build script with `const rlz = @import("raylib_zig");` and then accessing its functions with `rlz.emcc`. 93 | Refer to raylib-zig's project template on how to use them. 94 | 95 | ### Passing build options 96 | 97 | raylib allows customisations of certain parts of its build process such as choosing an OpenGL version, building as a 98 | shared library or not including certain modules. You can optionally pass these options to raylib-zig dependency like so 99 | 100 | ```zig 101 | const raylib_dep = b.dependency("raylib_zig", .{ 102 | .target = target, 103 | .optimize = optimize, 104 | .shared = true, // Build raylib as a shared library 105 | .opengl_version = rlz.OpenglVersion.gl_2_1, // Use OpenGL 2.1 (requires importing raylib-zig's build script) 106 | }); 107 | ``` 108 | 109 | ### Defining feature macros 110 | 111 | raylib lets the user enable and disable options for different features, loading different file formats for images, 112 | fonts, 3D models and audio, linkage variants. You can specify these options for your raylib-zig build by defining the 113 | corresponding C macro before you link with it, e.g.: 114 | 115 | ```zig 116 | raylib_artifact.root_module.addCMacro("SUPPORT_FILEFORMAT_JPG", ""); 117 | ``` 118 | 119 | ## Exporting for web 120 | 121 | To export your project for the web, first install emsdk. 122 | Once emsdk is installed, set it up by running 123 | 124 | `emsdk install latest` 125 | 126 | Find the folder where it's installed and run 127 | 128 | `zig build -Dtarget=wasm32-emscripten --sysroot [path to emsdk]/upstream/emscripten` 129 | 130 | once that is finished, the exported project should be located at `zig-out/htmlout` 131 | 132 | ### When is the binding updated? 133 | 134 | I plan on updating it every mayor release (2.5, 3.0, etc.). Keep in mind these are technically header files, so any 135 | implementation stuff should be updatable with some hacks on your side. 136 | 137 | ### What needs to be done? 138 | 139 | + _(Done)_ Set up a proper package build and a build script for the examples 140 | + Port all the examples 141 | + Member functions/initialisers 142 | -------------------------------------------------------------------------------- /build.zig.zon: -------------------------------------------------------------------------------- 1 | .{ 2 | .name = .raylib_zig, 3 | .version = "5.6.0-dev", 4 | .fingerprint = 0xc4cfa8c610114f28, 5 | .dependencies = .{ 6 | .raylib = .{ 7 | .url = "git+https://github.com/raysan5/raylib?ref=master#f5c96302d5623950dccdca31f8dd66d6d633dbd1", 8 | .hash = "raylib-5.5.0-whq8uFV0zQA9NXxhpYFZk_yHW6xzg5eKGmOtMJ2DOTdU", 9 | }, 10 | .raygui = .{ 11 | .url = "git+https://github.com/raysan5/raygui#1536ae35c7b42d863135f4181fd2a225e531f68b", 12 | .hash = "N-V-__8AAEp9UgBJ2n1eks3_3YZk3GCO1XOENazWaCO7ggM2", 13 | }, 14 | }, 15 | .minimum_zig_version = "0.14.0", 16 | .paths = .{ 17 | "build.zig", 18 | "build.zig.zon", 19 | "emcc.zig", 20 | "lib/raylib.zig", 21 | "lib/raylib-ext.zig", 22 | "lib/raymath.zig", 23 | "lib/raymath-ext.zig", 24 | "lib/rlgl.zig", 25 | "lib/rlgl-ext.zig", 26 | "lib/raygui.zig", 27 | "lib/raygui-ext.zig", 28 | }, 29 | } 30 | -------------------------------------------------------------------------------- /emcc.zig: -------------------------------------------------------------------------------- 1 | // raylib-zig (c) Nikolas Wipper 2020-2024 2 | 3 | const std = @import("std"); 4 | const builtin = @import("builtin"); 5 | 6 | const emccOutputDir = "zig-out" ++ std.fs.path.sep_str ++ "htmlout" ++ std.fs.path.sep_str; 7 | const emccOutputFile = "index.html"; 8 | pub fn emscriptenRunStep(b: *std.Build) !*std.Build.Step.Run { 9 | // If compiling on windows , use emrun.bat. 10 | const emrunExe = switch (builtin.os.tag) { 11 | .windows => "emrun.bat", 12 | else => "emrun", 13 | }; 14 | var emrun_run_arg = try b.allocator.alloc(u8, b.sysroot.?.len + emrunExe.len + 1); 15 | defer b.allocator.free(emrun_run_arg); 16 | 17 | if (b.sysroot == null) { 18 | emrun_run_arg = try std.fmt.bufPrint( 19 | emrun_run_arg, 20 | "{s}", 21 | .{ emrunExe } 22 | ); 23 | } else { 24 | emrun_run_arg = try std.fmt.bufPrint( 25 | emrun_run_arg, 26 | "{s}" ++ std.fs.path.sep_str ++ "{s}", 27 | .{ b.sysroot.?, emrunExe } 28 | ); 29 | } 30 | 31 | const run_cmd = b.addSystemCommand(&[_][]const u8{ emrun_run_arg, emccOutputDir ++ emccOutputFile }); 32 | return run_cmd; 33 | } 34 | 35 | // Creates the static library to build a project for Emscripten. 36 | pub fn compileForEmscripten( 37 | b: *std.Build, 38 | name: []const u8, 39 | root_source_file: []const u8, 40 | target: std.Build.ResolvedTarget, 41 | optimize: std.builtin.Mode, 42 | ) !*std.Build.Step.Compile { 43 | // TODO: It might be a good idea to create a custom compile step, that does 44 | // both the compile to static library and the link with emcc by overidding 45 | // the make function of the step. However it might also be a bad idea since 46 | // it messes with the build system itself. 47 | 48 | // The project is built as a library and linked later. 49 | const lib = b.addStaticLibrary(.{ 50 | .name = name, 51 | .root_source_file = b.path(root_source_file), 52 | .target = target, 53 | .optimize = optimize, 54 | }); 55 | 56 | const emscripten_headers = try std.fs.path.join(b.allocator, &.{ b.sysroot.?, "cache", "sysroot", "include" }); 57 | defer b.allocator.free(emscripten_headers); 58 | lib.addIncludePath(.{ .cwd_relative = emscripten_headers }); 59 | return lib; 60 | } 61 | 62 | // Links a set of items together using emscripten. 63 | // 64 | // Will accept objects and static libraries as items to link. As for files to 65 | // include, it is recomended to have a single resources directory and just pass 66 | // the entire directory instead of passing every file individually. The entire 67 | // path given will be the path to read the file within the program. So, if 68 | // "resources/image.png" is passed, your program will use "resources/image.png" 69 | // as the path to load the file. 70 | // 71 | // TODO: Test if shared libraries are accepted, I don't remember if emcc can 72 | // link a shared library with a project or not. 73 | // TODO: Add a parameter that allows a custom output directory. 74 | pub fn linkWithEmscripten( 75 | b: *std.Build, 76 | itemsToLink: []const *std.Build.Step.Compile, 77 | ) !*std.Build.Step.Run { 78 | const emccExe = switch (builtin.os.tag) { 79 | .windows => "emcc.bat", 80 | else => "emcc", 81 | }; 82 | var emcc_run_arg = try b.allocator.alloc(u8, b.sysroot.?.len + emccExe.len + 1); 83 | defer b.allocator.free(emcc_run_arg); 84 | 85 | if (b.sysroot == null) { 86 | emcc_run_arg = try std.fmt.bufPrint( 87 | emcc_run_arg, 88 | "{s}", 89 | .{ emccExe } 90 | ); 91 | } else { 92 | emcc_run_arg = try std.fmt.bufPrint( 93 | emcc_run_arg, 94 | "{s}" ++ std.fs.path.sep_str ++ "{s}", 95 | .{ b.sysroot.?, emccExe }, 96 | ); 97 | } 98 | 99 | // Create the output directory because emcc can't do it. 100 | const mkdir_command = switch (builtin.os.tag) { 101 | .windows => b.addSystemCommand(&.{ "cmd.exe", "/c", "if", "not", "exist", emccOutputDir, "mkdir", emccOutputDir }), 102 | else => b.addSystemCommand(&.{ "mkdir", "-p", emccOutputDir }), 103 | }; 104 | 105 | // Actually link everything together. 106 | const emcc_command = b.addSystemCommand(&[_][]const u8{emcc_run_arg}); 107 | 108 | for (itemsToLink) |item| { 109 | emcc_command.addFileArg(item.getEmittedBin()); 110 | emcc_command.step.dependOn(&item.step); 111 | } 112 | // This puts the file in zig-out/htmlout/index.html. 113 | emcc_command.step.dependOn(&mkdir_command.step); 114 | emcc_command.addArgs(&[_][]const u8{ 115 | "-o", 116 | emccOutputDir ++ emccOutputFile, 117 | "-sUSE_OFFSET_CONVERTER", 118 | "-sFULL-ES3=1", 119 | "-sUSE_GLFW=3", 120 | "-sASYNCIFY", 121 | "-O3", 122 | "-fsanitize=undefined", 123 | "--emrun", 124 | }); 125 | return emcc_command; 126 | } 127 | 128 | // TODO: See if zig's standard library already has somehing like this. 129 | fn lastIndexOf(string: []const u8, character: u8) usize { 130 | // Interestingly, Zig has no nice way of iterating a slice backwards. 131 | for (0..string.len) |i| { 132 | const index = string.len - i - 1; 133 | if (string[index] == character) return index; 134 | } 135 | return string.len - 1; 136 | } 137 | -------------------------------------------------------------------------------- /examples/audio/module_playing.zig: -------------------------------------------------------------------------------- 1 | const rl = @import("raylib"); 2 | 3 | const MAX_CIRCLES = 64; 4 | 5 | const CircleWave = struct { 6 | position: rl.Vector2, 7 | radius: f32, 8 | alpha: f32, 9 | speed: f32, 10 | color: rl.Color, 11 | }; 12 | 13 | const screenWidth = 800; 14 | const screenHeight = 450; 15 | 16 | const colors = [14]rl.Color{ .orange, .red, .gold, .lime, .blue, .violet, .brown, .light_gray, .pink, .yellow, .green, .sky_blue, .purple, .beige }; 17 | 18 | //------------------------------------------------------------------------------------ 19 | // Program main entry point 20 | //------------------------------------------------------------------------------------ 21 | pub fn main() !void { 22 | // Initialization 23 | //-------------------------------------------------------------------------------------- 24 | rl.setConfigFlags(rl.ConfigFlags{ .msaa_4x_hint = true }); // NOTE: Try to enable MSAA 4X 25 | 26 | rl.initWindow(screenWidth, screenHeight, "raylib [audio] example - module playing (streaming)"); 27 | defer rl.closeWindow(); // Close window and OpenGL context 28 | 29 | rl.initAudioDevice(); // Initialize audio device 30 | defer rl.closeAudioDevice(); // Close audio device (music streaming is automatically stopped) 31 | 32 | // Creates some circles for visual effect 33 | var circles: [MAX_CIRCLES]CircleWave = undefined; 34 | 35 | for (&circles) |*circle| { 36 | initCircle(circle); 37 | } 38 | 39 | var music: rl.Music = try rl.loadMusicStream("resources/audio/mini1111.xm"); 40 | defer rl.unloadMusicStream(music); // Unload music stream buffers from RAM 41 | 42 | music.looping = false; 43 | var pitch: f32 = 1; 44 | 45 | rl.playMusicStream(music); 46 | 47 | var timePlayed: f32 = 0; 48 | var pause: bool = false; 49 | 50 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 51 | //-------------------------------------------------------------------------------------- 52 | 53 | // Main game loop 54 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 55 | // Update 56 | //---------------------------------------------------------------------------------- 57 | rl.updateMusicStream(music); // Update music buffer with new stream data 58 | 59 | // Restart music playing (stop and play) 60 | if (rl.isKeyPressed(.space)) { 61 | rl.stopMusicStream(music); 62 | rl.playMusicStream(music); 63 | pause = false; 64 | } 65 | 66 | // Pause/Resume music playing 67 | if (rl.isKeyPressed(.p)) { 68 | pause = !pause; 69 | 70 | if (pause) { 71 | rl.pauseMusicStream(music); 72 | } else { 73 | rl.resumeMusicStream(music); 74 | } 75 | } 76 | 77 | if (rl.isKeyDown(.down)) { 78 | pitch -= 0.01; 79 | } else if (rl.isKeyDown(.up)) { 80 | pitch += 0.01; 81 | } 82 | 83 | rl.setMusicPitch(music, pitch); 84 | 85 | // Get timePlayed scaled to bar dimensions 86 | timePlayed = rl.getMusicTimePlayed(music) / rl.getMusicTimeLength(music) * (screenWidth - 40); 87 | 88 | if (!pause) { 89 | for (&circles) |*circle| { 90 | circle.alpha += circle.speed; 91 | circle.radius += circle.speed * 10.0; 92 | 93 | if (circle.alpha > 1.0) circle.speed *= -1; 94 | 95 | if (circle.alpha <= 0.0) { 96 | initCircle(circle); 97 | } 98 | } 99 | } 100 | //---------------------------------------------------------------------------------- 101 | 102 | // Draw 103 | //---------------------------------------------------------------------------------- 104 | rl.beginDrawing(); 105 | 106 | rl.clearBackground(.white); 107 | 108 | for (circles) |circle| { 109 | rl.drawCircleV(circle.position, circle.radius, .fade(circle.color, circle.alpha)); 110 | } 111 | 112 | // Draw time bar 113 | rl.drawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, .light_gray); 114 | rl.drawRectangle(20, screenHeight - 20 - 12, @intFromFloat(timePlayed), 12, .maroon); 115 | rl.drawRectangleLines(20, screenHeight - 20 - 12, screenWidth - 40, 12, .gray); 116 | 117 | // Draw help instructions 118 | rl.drawRectangle(20, 20, 425, 145, .white); 119 | rl.drawRectangleLines(20, 20, 425, 145, .gray); 120 | rl.drawText("PRESS SPACE TO RESTART MUSIC", 40, 40, 20, .black); 121 | rl.drawText("PRESS P TO PAUSE/RESUME", 40, 70, 20, .black); 122 | rl.drawText("PRESS UP/DOWN TO CHANGE SPEED", 40, 100, 20, .black); 123 | rl.drawText(rl.textFormat("SPEED: %f", .{pitch}), 40, 130, 20, .maroon); 124 | 125 | rl.endDrawing(); 126 | //---------------------------------------------------------------------------------- 127 | } 128 | } 129 | 130 | fn initCircle(circle: *CircleWave) void { 131 | circle.alpha = 0.0; 132 | circle.radius = getRandomValuef32(10, 40); 133 | circle.position.x = getRandomValuef32(@intFromFloat(circle.radius), @intFromFloat(screenWidth - circle.radius)); 134 | circle.position.y = getRandomValuef32(@intFromFloat(circle.radius), @intFromFloat(screenHeight - circle.radius)); 135 | circle.speed = getRandomValuef32(1, 100) / 2000.0; 136 | circle.color = colors[@intCast(rl.getRandomValue(0, 13))]; 137 | } 138 | 139 | fn getRandomValuef32(min: i32, max: i32) f32 { 140 | return @as(f32, @floatFromInt(rl.getRandomValue(min, max))); 141 | } 142 | -------------------------------------------------------------------------------- /examples/audio/music_stream.zig: -------------------------------------------------------------------------------- 1 | const rl = @import("raylib"); 2 | 3 | //------------------------------------------------------------------------------------ 4 | // Program main entry point 5 | //------------------------------------------------------------------------------------ 6 | pub fn main() !void { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const screenWidth = 800; 10 | const screenHeight = 450; 11 | 12 | rl.initWindow(screenWidth, screenHeight, "raylib [audio] example - music playing (streaming)"); 13 | defer rl.closeWindow(); // Close window and OpenGL context 14 | 15 | rl.initAudioDevice(); // Initialize audio device 16 | defer rl.closeAudioDevice(); // Close audio device (music streaming is automatically stopped) 17 | 18 | const music: rl.Music = try rl.loadMusicStream("resources/audio/country.mp3"); 19 | defer rl.unloadMusicStream(music); // Unload music stream buffers from RAM 20 | 21 | rl.playMusicStream(music); 22 | 23 | var timePlayed: f32 = 0; // Time played normalized [0.0f..1.0f] 24 | var pause: bool = false; // Music playing paused 25 | 26 | rl.setTargetFPS(30); // Set our game to run at 30 frames-per-second 27 | //-------------------------------------------------------------------------------------- 28 | 29 | // Main game loop 30 | while (!rl.windowShouldClose()) // Detect window close button or ESC key 31 | { 32 | // Update 33 | //---------------------------------------------------------------------------------- 34 | rl.updateMusicStream(music); // Update music buffer with new stream data 35 | 36 | // Restart music playing (stop and play) 37 | if (rl.isKeyPressed(.space)) { 38 | rl.stopMusicStream(music); 39 | rl.playMusicStream(music); 40 | } 41 | 42 | // Pause/Resume music playing 43 | if (rl.isKeyPressed(.p)) { 44 | pause = !pause; 45 | 46 | if (pause) { 47 | rl.pauseMusicStream(music); 48 | } else { 49 | rl.resumeMusicStream(music); 50 | } 51 | } 52 | 53 | // Get normalized time played for current music stream 54 | timePlayed = rl.getMusicTimePlayed(music) / rl.getMusicTimeLength(music); 55 | 56 | if (timePlayed > 1.0) { 57 | timePlayed = 1.0; // Make sure time played is no longer than music 58 | } 59 | //---------------------------------------------------------------------------------- 60 | 61 | // Draw 62 | //---------------------------------------------------------------------------------- 63 | rl.beginDrawing(); 64 | defer rl.endDrawing(); 65 | 66 | rl.clearBackground(.white); 67 | 68 | rl.drawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, .light_gray); 69 | 70 | rl.drawRectangle(200, 200, 400, 12, .light_gray); 71 | rl.drawRectangle(200, 200, @intFromFloat(timePlayed * 400), 12, .maroon); 72 | rl.drawRectangleLines(200, 200, 400, 12, .gray); 73 | 74 | rl.drawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, .light_gray); 75 | rl.drawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, .light_gray); 76 | //---------------------------------------------------------------------------------- 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /examples/audio/raw_stream.zig: -------------------------------------------------------------------------------- 1 | // raylib-zig (c) Nikolas Wipper 2023 2 | 3 | const rl = @import("raylib"); 4 | 5 | const MAX_SAMPLES = 512; 6 | const MAX_SAMPLES_PER_UPDATE = 4096; 7 | 8 | const pi = @import("std").math.pi; 9 | var frequency: f32 = 440; 10 | var audioFrequency: f32 = 440; 11 | var oldFrequency: f32 = 1; 12 | var sineIdx: f32 = 0; 13 | 14 | fn audioInputCallback(buffer: ?*anyopaque, frames: c_uint) callconv(.C) void { 15 | audioFrequency = frequency + (audioFrequency - frequency) * 0.95; 16 | 17 | const incr = audioFrequency / 44100; 18 | const d: [*]i16 = @alignCast(@ptrCast(buffer orelse return)); 19 | 20 | for (0..frames) |i| { 21 | d[i] = @intFromFloat(32000 * @sin(2 * pi * sineIdx)); 22 | sineIdx += incr; 23 | if (sineIdx > 1) { 24 | sineIdx -= 1; 25 | } 26 | } 27 | } 28 | 29 | pub fn main() anyerror!void { 30 | // Initialization 31 | //-------------------------------------------------------------------------------------- 32 | const screenWidth = 800; 33 | const screenHeight = 450; 34 | 35 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - raw audio streaming"); 36 | defer rl.closeWindow(); // Close window and OpenGL context 37 | 38 | rl.initAudioDevice(); // Initialize audio device 39 | defer rl.closeAudioDevice(); // Close audio device (music streaming is automatically stopped) 40 | 41 | rl.setAudioStreamBufferSizeDefault(MAX_SAMPLES_PER_UPDATE); 42 | 43 | // Init raw audio stream (sample rate: 44100, sample size: 16bit-short, channels: 1-mono) 44 | const stream = try rl.loadAudioStream(44100, 16, 1); 45 | defer rl.unloadAudioStream(stream); // Close raw audio stream and delete buffers from RAM 46 | 47 | rl.setAudioStreamCallback(stream, &audioInputCallback); 48 | 49 | // Buffer for the single cycle waveform we are synthesizing 50 | const data = try rl.mem.alloc(i16, MAX_SAMPLES); 51 | defer rl.mem.free(data); // Unload sine wave data 52 | 53 | // Frame buffer, describing the waveform when repeated over the course of a frame 54 | const writeBuf = try rl.mem.alloc(i16, MAX_SAMPLES_PER_UPDATE); 55 | defer rl.mem.free(writeBuf); // Unload write buffer 56 | 57 | rl.playAudioStream(stream); // Start processing stream buffer (no data loaded currently) 58 | 59 | // Computed size in samples of the sine wave 60 | var waveLength: i32 = 1; 61 | 62 | var position = rl.Vector2{ .x = 0, .y = 0 }; 63 | 64 | rl.setTargetFPS(30); // Set our game to run at 30 frames-per-second 65 | //-------------------------------------------------------------------------------------- 66 | 67 | // Main game loop 68 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 69 | // Update 70 | //---------------------------------------------------------------------------------- 71 | 72 | if (rl.isMouseButtonDown(.left)) { 73 | // Sample mouse input. 74 | const mousePosition = rl.getMousePosition(); 75 | 76 | const fp = (screenHeight - mousePosition.y); 77 | frequency = 40 + fp; 78 | 79 | const pan = (screenWidth - mousePosition.x) / screenWidth; 80 | rl.setAudioStreamPan(stream, pan); 81 | } 82 | 83 | // Rewrite the sine wave 84 | // Compute two cycles to allow buffer padding, simplifying any modulation, resampling, etc. 85 | if (frequency != oldFrequency) { 86 | // Compute wavelength. Limit size in both directions. 87 | //int oldWavelength = waveLength; 88 | waveLength = @intFromFloat(22050 / frequency); 89 | waveLength = @min(@max(1, waveLength), MAX_SAMPLES / 2); 90 | 91 | // Write sine wave 92 | const n: u32 = @intCast(waveLength * 2); 93 | for (0..n) |i| { 94 | const wlen: f32 = @floatFromInt(waveLength); 95 | const idx: f32 = @floatFromInt(i); 96 | data[i] = @intFromFloat(@sin((2 * pi * idx / wlen)) * 32000); 97 | } 98 | // Make sure the rest of the line is flat 99 | for (n..MAX_SAMPLES) |i| { 100 | data[i] = 0; 101 | } 102 | 103 | // Scale read cursor's position to minimize transition artifacts 104 | //readCursor = (int)(readCursor * ((float)waveLength / (float)oldWavelength)); 105 | oldFrequency = frequency; 106 | } 107 | //---------------------------------------------------------------------------------- 108 | 109 | // Draw 110 | //---------------------------------------------------------------------------------- 111 | rl.beginDrawing(); 112 | defer rl.endDrawing(); 113 | 114 | rl.clearBackground(.ray_white); 115 | 116 | rl.drawText(rl.textFormat("sine frequency: %i", .{@as(i32, @intFromFloat(frequency))}), 117 | rl.getScreenWidth() - 220, 10, 20, .red); 118 | rl.drawText("click mouse button to change frequency or pan", 119 | 10, 10, 20, .dark_gray); 120 | 121 | // Draw the current buffer state proportionate to the screen 122 | for (0..screenWidth) |i| { 123 | position.x = @floatFromInt(i); 124 | const y: f32 = @floatFromInt(data[@divFloor(i * MAX_SAMPLES, screenWidth)]); 125 | position.y = 250 + 50 * y / 32000; 126 | 127 | rl.drawPixelV(position, .red); 128 | } 129 | //---------------------------------------------------------------------------------- 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /examples/audio/sound_loading.zig: -------------------------------------------------------------------------------- 1 | const rl = @import("raylib"); 2 | 3 | //------------------------------------------------------------------------------------ 4 | // Program main entry point 5 | //------------------------------------------------------------------------------------ 6 | pub fn main() !void { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const screenWidth = 800; 10 | const screenHeight = 450; 11 | 12 | rl.initWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing"); 13 | defer rl.closeWindow(); // Close window and OpenGL context 14 | 15 | rl.initAudioDevice(); // Initialize audio device 16 | defer rl.closeAudioDevice(); // Close audio device 17 | 18 | const fxWav: rl.Sound = try rl.loadSound("resources/audio/sound.wav"); // Load WAV audio file 19 | const fxOgg: rl.Sound = try rl.loadSound("resources/audio/target.ogg"); // Load OGG audio file 20 | defer rl.unloadSound(fxWav); // Unload sound data 21 | defer rl.unloadSound(fxOgg); // Unload sound data 22 | 23 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 24 | //-------------------------------------------------------------------------------------- 25 | 26 | // Main game loop 27 | while (!rl.windowShouldClose()) // Detect window close button or ESC key 28 | { 29 | // Update 30 | //---------------------------------------------------------------------------------- 31 | if (rl.isKeyPressed(.space)) rl.playSound(fxWav); // Play WAV sound 32 | if (rl.isKeyPressed(.enter)) rl.playSound(fxOgg); // Play OGG sound 33 | //---------------------------------------------------------------------------------- 34 | 35 | // Draw 36 | //---------------------------------------------------------------------------------- 37 | rl.beginDrawing(); 38 | defer rl.endDrawing(); 39 | 40 | rl.clearBackground(.white); 41 | 42 | rl.drawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, .light_gray); 43 | rl.drawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, .light_gray); 44 | //---------------------------------------------------------------------------------- 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /examples/core/2d_camera.zig: -------------------------------------------------------------------------------- 1 | // raylib-zig (c) Nikolas Wipper 2023 2 | 3 | const rl = @import("raylib"); 4 | 5 | const MAX_BUILDINGS = 100; 6 | 7 | pub fn main() anyerror!void { 8 | // Initialization 9 | //-------------------------------------------------------------------------------------- 10 | const screenWidth = 800; 11 | const screenHeight = 450; 12 | 13 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - 2d camera"); 14 | defer rl.closeWindow(); // Close window and OpenGL context 15 | 16 | var player = rl.Rectangle{ .x = 400, .y = 280, .width = 40, .height = 40 }; 17 | var buildings: [MAX_BUILDINGS]rl.Rectangle = undefined; 18 | var buildColors: [MAX_BUILDINGS]rl.Color = undefined; 19 | 20 | var spacing: i32 = 0; 21 | 22 | for (0..buildings.len) |i| { 23 | buildings[i].width = @as(f32, @floatFromInt(rl.getRandomValue(50, 200))); 24 | buildings[i].height = @as(f32, @floatFromInt(rl.getRandomValue(100, 800))); 25 | buildings[i].y = screenHeight - 130 - buildings[i].height; 26 | buildings[i].x = @as(f32, @floatFromInt(-6000 + spacing)); 27 | 28 | spacing += @as(i32, @intFromFloat(buildings[i].width)); 29 | 30 | buildColors[i] = .init( 31 | @as(u8, @intCast(rl.getRandomValue(200, 240))), 32 | @as(u8, @intCast(rl.getRandomValue(200, 240))), 33 | @as(u8, @intCast(rl.getRandomValue(200, 250))), 34 | 255, 35 | ); 36 | } 37 | 38 | var camera = rl.Camera2D{ 39 | .target = .init(player.x + 20, player.y + 20), 40 | .offset = .init(screenWidth / 2, screenHeight / 2), 41 | .rotation = 0, 42 | .zoom = 1, 43 | }; 44 | 45 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 46 | //-------------------------------------------------------------------------------------- 47 | 48 | // Main game loop 49 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 50 | // Update 51 | //---------------------------------------------------------------------------------- 52 | 53 | // Player movement 54 | if (rl.isKeyDown(.right)) { 55 | player.x += 2; 56 | } else if (rl.isKeyDown(.left)) { 57 | player.x -= 2; 58 | } 59 | 60 | // Camera target follows player 61 | camera.target = .init(player.x + 20, player.y + 20); 62 | 63 | // Camera rotation controls 64 | if (rl.isKeyDown(.a)) { 65 | camera.rotation -= 1; 66 | } else if (rl.isKeyDown(.s)) { 67 | camera.rotation += 1; 68 | } 69 | 70 | // Limit camera rotation to 80 degrees (-40 to 40) 71 | camera.rotation = rl.math.clamp(camera.rotation, -40, 40); 72 | 73 | // Camera zoom controls 74 | camera.zoom += rl.getMouseWheelMove() * 0.05; 75 | 76 | camera.zoom = rl.math.clamp(camera.zoom, 0.1, 3.0); 77 | 78 | // Camera reset (zoom and rotation) 79 | if (rl.isKeyPressed(.r)) { 80 | camera.zoom = 1.0; 81 | camera.rotation = 0.0; 82 | } 83 | //---------------------------------------------------------------------------------- 84 | 85 | // Draw 86 | //---------------------------------------------------------------------------------- 87 | rl.beginDrawing(); 88 | defer rl.endDrawing(); 89 | 90 | rl.clearBackground(.ray_white); 91 | 92 | { 93 | camera.begin(); 94 | defer camera.end(); 95 | 96 | rl.drawRectangle(-6000, 320, 13000, 8000, .dark_gray); 97 | 98 | for (buildings, 0..) |building, i| { 99 | rl.drawRectangleRec(building, buildColors[i]); 100 | } 101 | 102 | rl.drawRectangleRec(player, .red); 103 | 104 | rl.drawLine( 105 | @as(i32, @intFromFloat(camera.target.x)), 106 | -screenHeight * 10, 107 | @as(i32, @intFromFloat(camera.target.x)), 108 | screenHeight * 10, 109 | .green, 110 | ); 111 | rl.drawLine( 112 | -screenWidth * 10, 113 | @as(i32, @intFromFloat(camera.target.y)), 114 | screenWidth * 10, 115 | @as(i32, @intFromFloat(camera.target.y)), 116 | .green, 117 | ); 118 | } 119 | 120 | rl.drawText("SCREEN AREA", 640, 10, 20, .red); 121 | 122 | rl.drawRectangle(0, 0, screenWidth, 5, .red); 123 | rl.drawRectangle(0, 5, 5, screenHeight - 10, .red); 124 | rl.drawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, .red); 125 | rl.drawRectangle(0, screenHeight - 5, screenWidth, 5, .red); 126 | 127 | rl.drawRectangle(10, 10, 250, 113, .fade(.sky_blue, 0.5)); 128 | rl.drawRectangleLines(10, 10, 250, 113, .blue); 129 | 130 | rl.drawText("Free 2d camera controls:", 20, 20, 10, .black); 131 | rl.drawText("- Right/Left to move Offset", 40, 40, 10, .dark_gray); 132 | rl.drawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, .dark_gray); 133 | rl.drawText("- A / S to Rotate", 40, 80, 10, .dark_gray); 134 | rl.drawText("- R to reset Zoom and Rotation", 40, 100, 10, .dark_gray); 135 | //---------------------------------------------------------------------------------- 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /examples/core/2d_camera_mouse_zoom.zig: -------------------------------------------------------------------------------- 1 | // port of raylib example https://github.com/raysan5/raylib/blob/master/examples/core/core_2d_camera_mouse_zoom.c 2 | 3 | const rl = @import("raylib"); 4 | 5 | pub fn main() anyerror!void { 6 | // Initialization 7 | //-------------------------------------------------------------------------------------- 8 | const screenWidth = 800; 9 | const screenHeight = 450; 10 | 11 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - 2d camera mouse zoom"); 12 | defer rl.closeWindow(); // Close window and OpenGL context 13 | 14 | var camera = rl.Camera2D{ 15 | .target = .{ .x = 0, .y = 0 }, 16 | .offset = .{ .x = 0, .y = 0 }, 17 | .zoom = 1.0, 18 | .rotation = 0, 19 | }; 20 | 21 | var zoomMode: i32 = 0; // 0-Mouse Wheel, 1-Mouse Move 22 | 23 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 24 | //-------------------------------------------------------------------------------------- 25 | 26 | // Main game loop 27 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 28 | // Update 29 | //---------------------------------------------------------------------------------- 30 | if (rl.isKeyPressed(.one)) { 31 | zoomMode = 0; 32 | } else if (rl.isKeyPressed(.two)) { 33 | zoomMode = 1; 34 | } 35 | 36 | // Translate based on mouse right click 37 | if (rl.isMouseButtonDown(.right)) { 38 | var delta = rl.getMouseDelta(); 39 | delta = rl.math.vector2Scale(delta, -1.0 / camera.zoom); 40 | camera.target = rl.math.vector2Add(camera.target, delta); 41 | } 42 | 43 | if (zoomMode == 0) { 44 | // Zoom based on mouse wheel 45 | const wheel = rl.getMouseWheelMove(); 46 | if (wheel != 0) { 47 | // Get the world point that is under the mouse 48 | const mouseWorldPos = rl.getScreenToWorld2D(rl.getMousePosition(), camera); 49 | 50 | // Set the offset to where the mouse is 51 | camera.offset = rl.getMousePosition(); 52 | 53 | // Set the target to match, so that the camera maps the world space point 54 | // under the cursor to the screen space point under the cursor at any zoom 55 | camera.target = mouseWorldPos; 56 | 57 | // Zoom increment 58 | var scaleFactor = 1.0 + (0.25 * @abs(wheel)); 59 | if (wheel < 0) { 60 | scaleFactor = 1.0 / scaleFactor; 61 | } 62 | camera.zoom = rl.math.clamp(camera.zoom * scaleFactor, 0.125, 64.0); 63 | } 64 | } else { 65 | // Zoom based on left click 66 | if (rl.isMouseButtonPressed(.left)) { 67 | // Get the world point that is under the mouse 68 | const mouseWorldPos = rl.getScreenToWorld2D(rl.getMousePosition(), camera); 69 | 70 | // Set the offset to where the mouse is 71 | camera.offset = rl.getMousePosition(); 72 | 73 | // Set the target to match, so that the camera maps the world space point 74 | // under the cursor to the screen space point under the cursor at any zoom 75 | camera.target = mouseWorldPos; 76 | } 77 | if (rl.isMouseButtonDown(.left)) { 78 | // Zoom increment 79 | const deltaX = rl.getMouseDelta().x; 80 | var scaleFactor = 1.0 + (0.01 * @abs(deltaX)); 81 | if (deltaX < 0) { 82 | scaleFactor = 1.0 / scaleFactor; 83 | } 84 | camera.zoom = rl.math.clamp(camera.zoom * scaleFactor, 0.125, 64.0); 85 | } 86 | } 87 | //---------------------------------------------------------------------------------- 88 | 89 | // Draw 90 | //---------------------------------------------------------------------------------- 91 | rl.beginDrawing(); 92 | defer rl.endDrawing(); 93 | 94 | rl.clearBackground(.ray_white); 95 | 96 | { 97 | camera.begin(); 98 | defer camera.end(); 99 | 100 | rl.gl.rlPushMatrix(); 101 | rl.gl.rlTranslatef(0, 25 * 50, 0); 102 | rl.gl.rlRotatef(90, 1, 0, 0); 103 | rl.drawGrid(100, 50); 104 | rl.gl.rlPopMatrix(); 105 | 106 | rl.drawCircle(screenWidth / 2, screenHeight / 2, 50, .maroon); 107 | } 108 | 109 | rl.drawText("[1][2] Select mouse zoom mode (Wheel or Move)", 20, 20, 20, .dark_gray); 110 | if (zoomMode == 0) { 111 | rl.drawText("Mouse right button drag to move, mouse wheel to zoom", 20, 50, 20, .dark_gray); 112 | } else { 113 | rl.drawText("Mouse right button drag to move, mouse press and move to zoom", 20, 50, 20, .dark_gray); 114 | } 115 | 116 | //---------------------------------------------------------------------------------- 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /examples/core/3d_camera_first_person.zig: -------------------------------------------------------------------------------- 1 | // raylib-zig (c) Nikolas Wipper 2023 2 | 3 | const rl = @import("raylib"); 4 | 5 | const MAX_COLUMNS = 20; 6 | 7 | pub fn main() anyerror!void { 8 | // Initialization 9 | //-------------------------------------------------------------------------------------- 10 | const screenWidth = 800; 11 | const screenHeight = 450; 12 | 13 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - 3d camera first person"); 14 | defer rl.closeWindow(); // Close window and OpenGL context 15 | 16 | var camera = rl.Camera3D{ 17 | .position = .init(4, 2, 4), 18 | .target = .init(0, 1.8, 0), 19 | .up = .init(0, 1, 0), 20 | .fovy = 60, 21 | .projection = .perspective, 22 | }; 23 | 24 | var heights: [MAX_COLUMNS]f32 = undefined; 25 | var positions: [MAX_COLUMNS]rl.Vector3 = undefined; 26 | var colors: [MAX_COLUMNS]rl.Color = undefined; 27 | 28 | for (0..heights.len) |i| { 29 | heights[i] = @as(f32, @floatFromInt(rl.getRandomValue(1, 12))); 30 | positions[i] = .init( 31 | @as(f32, @floatFromInt(rl.getRandomValue(-15, 15))), 32 | heights[i] / 2.0, 33 | @as(f32, @floatFromInt(rl.getRandomValue(-15, 15))), 34 | ); 35 | colors[i] = .init( 36 | @as(u8, @intCast(rl.getRandomValue(20, 255))), 37 | @as(u8, @intCast(rl.getRandomValue(10, 55))), 38 | 30, 39 | 255, 40 | ); 41 | } 42 | 43 | rl.disableCursor(); // Limit cursor to relative movement inside the window 44 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 45 | //-------------------------------------------------------------------------------------- 46 | 47 | // Main game loop 48 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 49 | // Update 50 | //---------------------------------------------------------------------------------- 51 | camera.update(.first_person); 52 | //---------------------------------------------------------------------------------- 53 | 54 | // Draw 55 | //---------------------------------------------------------------------------------- 56 | rl.beginDrawing(); 57 | defer rl.endDrawing(); 58 | 59 | rl.clearBackground(.ray_white); 60 | 61 | { 62 | camera.begin(); 63 | defer camera.end(); 64 | 65 | // Draw ground 66 | rl.drawPlane(.init(0, 0, 0), .init(32, 32), .light_gray); 67 | rl.drawCube(.init(-16.0, 2.5, 0.0), 1.0, 5.0, 32.0, .blue); // Draw a blue wall 68 | rl.drawCube(.init(16.0, 2.5, 0.0), 1.0, 5.0, 32.0, .lime); // Draw a green wall 69 | rl.drawCube(.init(0.0, 2.5, 16.0), 32.0, 5.0, 1.0, .gold); // Draw a yellow wall 70 | 71 | // Draw some cubes around 72 | for (heights, 0..) |height, i| { 73 | rl.drawCube(positions[i], 2.0, height, 2.0, colors[i]); 74 | rl.drawCubeWires(positions[i], 2.0, height, 2.0, .maroon); 75 | } 76 | } 77 | 78 | rl.drawRectangle(10, 10, 220, 70, .fade(.sky_blue, 0.5)); 79 | rl.drawRectangleLines(10, 10, 220, 70, .blue); 80 | 81 | rl.drawText("First person camera default controls:", 20, 20, 10, .black); 82 | rl.drawText("- Move with keys: W, A, S, D", 40, 40, 10, .dark_gray); 83 | rl.drawText("- Mouse move to look around", 40, 60, 10, .dark_gray); 84 | //---------------------------------------------------------------------------------- 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /examples/core/3d_camera_free.zig: -------------------------------------------------------------------------------- 1 | // A raylib port of https://github.com/raysan5/raylib/blob/master/examples/core/core_3d_camera_free.c 2 | 3 | const rl = @import("raylib"); 4 | 5 | //------------------------------------------------------------------------------------ 6 | // Program main entry point 7 | //------------------------------------------------------------------------------------ 8 | pub fn main() anyerror!void { 9 | // Initialization 10 | //-------------------------------------------------------------------------------- 11 | const screenWidth = 800; 12 | const screenHeight = 450; 13 | 14 | rl.initWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free"); 15 | defer rl.closeWindow(); // Close window and OpenGL context 16 | 17 | // Define the camera to look into our 3d world 18 | var camera = rl.Camera{ 19 | .position = .init(10, 10, 10), 20 | .target = .init(0, 0, 0), 21 | .up = .init(0, 1, 0), 22 | .fovy = 45, 23 | .projection = .perspective, 24 | }; 25 | 26 | const cubePosition = rl.Vector3.init(0, 0, 0); 27 | 28 | rl.disableCursor(); // Limit cursor to relative movement inside the window 29 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 30 | //-------------------------------------------------------------------------------- 31 | 32 | // Main game loop 33 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 34 | // Update 35 | //----------------------------------------------------------------------------- 36 | camera.update(.free); 37 | 38 | if (rl.isKeyPressed(.z)) { 39 | camera.target = .init(0, 0, 0); 40 | } 41 | //----------------------------------------------------------------------------- 42 | 43 | // Draw 44 | //----------------------------------------------------------------------------- 45 | rl.beginDrawing(); 46 | defer rl.endDrawing(); 47 | 48 | rl.clearBackground(.ray_white); 49 | 50 | { 51 | camera.begin(); 52 | defer camera.end(); 53 | 54 | rl.drawCube(cubePosition, 2, 2, 2, .red); 55 | rl.drawCubeWires(cubePosition, 2, 2, 2, .maroon); 56 | 57 | rl.drawGrid(10, 1); 58 | } 59 | 60 | rl.drawRectangle(10, 10, 320, 93, .fade(.sky_blue, 0.5)); 61 | rl.drawRectangleLines(10, 10, 320, 93, .blue); 62 | 63 | rl.drawText("Free camera default controls:", 20, 20, 10, .black); 64 | rl.drawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, .dark_gray); 65 | rl.drawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, .dark_gray); 66 | rl.drawText("- Z to zoom to (0, 0, 0)", 40, 80, 10, .dark_gray); 67 | //----------------------------------------------------------------------------- 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /examples/core/3d_picking.zig: -------------------------------------------------------------------------------- 1 | // A raylib-zig port of https://github.com/raysan5/raylib/blob/master/examples/core/core_3d_picking.c 2 | const rl = @import("raylib"); 3 | 4 | pub fn main() anyerror!void { 5 | // Initialization 6 | //-------------------------------------------------------------------------------------- 7 | const screenWidth = 800; 8 | const screenHeight = 450; 9 | 10 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - 3d picking"); 11 | 12 | // Define the camera to look into our 3d world 13 | var camera = rl.Camera{ 14 | .position = .init(10, 10, 10), 15 | .target = .init(0, 0, 0), 16 | .up = .init(0, 1, 0), 17 | .fovy = 45, 18 | .projection = .perspective, 19 | }; 20 | 21 | const cubePosition = rl.Vector3.init(0, 1, 0); 22 | const cubeSize = rl.Vector3.init(2, 2, 2); 23 | 24 | var ray: rl.Ray = undefined; // Picking line ray 25 | var collision: rl.RayCollision = undefined; // Ray collision hit info 26 | 27 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 28 | //-------------------------------------------------------------------------------------- 29 | 30 | // Main game loop 31 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 32 | // Update 33 | //---------------------------------------------------------------------------------- 34 | if (rl.isCursorHidden()) rl.updateCamera(&camera, .first_person); 35 | 36 | // Toggle camera controls 37 | if (rl.isMouseButtonPressed(.right)) { 38 | if (rl.isCursorHidden()) rl.enableCursor() else rl.disableCursor(); 39 | } 40 | 41 | if (rl.isMouseButtonPressed(.left)) { 42 | if (!collision.hit) { 43 | ray = rl.getScreenToWorldRay(rl.getMousePosition(), camera); 44 | 45 | // Check collision between ray and box 46 | collision = rl.getRayCollisionBox(ray, rl.BoundingBox{ 47 | .max = .init(cubePosition.x - cubeSize.x / 2, cubePosition.y - cubeSize.y / 2, cubePosition.z - cubeSize.z / 2), 48 | .min = .init(cubePosition.x + cubeSize.x / 2, cubePosition.y + cubeSize.y / 2, cubePosition.z + cubeSize.z / 2), 49 | }); 50 | } else collision.hit = false; 51 | } 52 | //---------------------------------------------------------------------------------- 53 | 54 | // Draw 55 | //---------------------------------------------------------------------------------- 56 | 57 | rl.beginDrawing(); 58 | defer rl.endDrawing(); 59 | rl.clearBackground(.ray_white); 60 | 61 | { 62 | camera.begin(); 63 | defer camera.end(); 64 | 65 | if (collision.hit) { 66 | rl.drawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, .red); 67 | rl.drawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, .maroon); 68 | 69 | rl.drawCubeWires(cubePosition, cubeSize.x + 0.2, cubeSize.y + 0.2, cubeSize.z + 0.2, .green); 70 | } else { 71 | rl.drawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, .gray); 72 | rl.drawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, .dark_gray); 73 | } 74 | 75 | rl.drawRay(ray, .maroon); 76 | rl.drawGrid(10, 1); 77 | } 78 | 79 | rl.drawText("Try clicking on the box with your mouse!", 240, 10, 20, .dark_gray); 80 | 81 | if (collision.hit) { 82 | rl.drawText("BOX SELECTED", @divTrunc((screenWidth - rl.measureText("BOX SELECTED", 30)), 2), screenHeight * 0.1, 30, .green); 83 | } 84 | 85 | rl.drawText("Right click mouse to toggle camera controls", 10, 430, 10, .gray); 86 | 87 | rl.drawFPS(10, 10); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /examples/core/basic_screen_manager.zig: -------------------------------------------------------------------------------- 1 | //! # raylib-zig [core] examples - basic screen manager 2 | //! 3 | //! NOTE: This example illustrates a very simple screen manager based on a 4 | //! states machines 5 | //! 6 | //! Example originally created with raylib-zig 5.0, last time updated with 7 | //! raylib-zig 5.0 8 | //! 9 | //! Copyright (c) Nikolas Wipper 2024 10 | 11 | const rl = @import("raylib"); 12 | 13 | const screen_width = 800; 14 | const screen_height = 450; 15 | 16 | /// Valid game states used in the state machine 17 | const GameScreen = enum { 18 | logo, 19 | title, 20 | gameplay, 21 | ending, 22 | }; 23 | 24 | pub fn main() anyerror!void { 25 | // Initialization 26 | // ------------------------------------------------------------------------- 27 | rl.initWindow( 28 | screen_width, 29 | screen_height, 30 | "raylib-zig [core] example - basic screen height", 31 | ); 32 | defer rl.closeWindow(); // Close window and OpenGL context 33 | 34 | // TODO: Initialize all required variables and load all required data here! 35 | 36 | var current_screen: GameScreen = .logo; 37 | 38 | var frames_counter: i32 = 0; // Useful to count frames 39 | 40 | rl.setTargetFPS(60); // Set desired framerate 41 | 42 | // Main game loop 43 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 44 | // Update 45 | // --------------------------------------------------------------------- 46 | switch (current_screen) { 47 | .logo => { 48 | // TODO: Update `logo` state variables here! 49 | 50 | frames_counter += 1; // Count frames 51 | 52 | // Wait for 2 seconds (120 frames) before jumping to `title` screen 53 | if (frames_counter > 120) current_screen = .title; 54 | }, 55 | .title => { 56 | // TODO: Update `title` state variables here! 57 | 58 | // Press ENTER to change to `gameplay` state 59 | if (rl.isKeyPressed(.enter) or rl.isGestureDetected(.tap)) { 60 | current_screen = .gameplay; 61 | } 62 | }, 63 | .gameplay => { 64 | // TODO: Update `gameplay` state variables here! 65 | 66 | // Press ENTER to change to `ending` state 67 | if (rl.isKeyPressed(.enter) or rl.isGestureDetected(.tap)) { 68 | current_screen = .ending; 69 | } 70 | }, 71 | .ending => { 72 | // TODO: Update `ending` state variables here! 73 | 74 | // Press ENTER to return to `title` state 75 | if (rl.isKeyPressed(.enter) or rl.isGestureDetected(.tap)) { 76 | current_screen = .title; 77 | } 78 | }, 79 | } 80 | // --------------------------------------------------------------------- 81 | 82 | // Draw 83 | // --------------------------------------------------------------------- 84 | { 85 | rl.beginDrawing(); 86 | defer rl.endDrawing(); 87 | 88 | rl.clearBackground(.ray_white); 89 | 90 | switch (current_screen) { 91 | .logo => { 92 | // TODO: Draw `logo` state here! 93 | rl.drawText("LOGO SCREEN", 20, 20, 40, .light_gray); 94 | rl.drawText( 95 | "WAIT for 2 SECONDS...", 96 | 290, 97 | 220, 98 | 20, 99 | .gray, 100 | ); 101 | }, 102 | .title => { 103 | // TODO: Draw `title` state here! 104 | rl.drawRectangle( 105 | 0, 106 | 0, 107 | screen_width, 108 | screen_height, 109 | .green, 110 | ); 111 | rl.drawText( 112 | "TITLE SCREEN", 113 | 20, 114 | 20, 115 | 40, 116 | .dark_green, 117 | ); 118 | rl.drawText( 119 | "PRESS ENTER or TAP to JUMP to GAMEPLAY SCREEN", 120 | 120, 121 | 220, 122 | 20, 123 | .dark_green, 124 | ); 125 | }, 126 | .gameplay => { 127 | // TODO: Draw `gameplay` state here! 128 | rl.drawRectangle( 129 | 0, 130 | 0, 131 | screen_width, 132 | screen_height, 133 | .purple, 134 | ); 135 | rl.drawText("GAMEPLAY SCREEN", 20, 20, 40, .maroon); 136 | rl.drawText( 137 | "PRESS ENTER or TAP to JUMP to ENDING SCREEN", 138 | 130, 139 | 220, 140 | 20, 141 | .maroon, 142 | ); 143 | }, 144 | .ending => { 145 | // TODO: Draw `ending` state here! 146 | rl.drawRectangle( 147 | 0, 148 | 0, 149 | screen_width, 150 | screen_height, 151 | .blue, 152 | ); 153 | rl.drawText( 154 | "ENDING SCREEN", 155 | 20, 156 | 20, 157 | 40, 158 | .dark_blue, 159 | ); 160 | rl.drawText( 161 | "PRESS ENTER or TAP to RETURN to TITLE SCREEN", 162 | 120, 163 | 220, 164 | 20, 165 | .dark_blue, 166 | ); 167 | }, 168 | } 169 | } 170 | // --------------------------------------------------------------------- 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /examples/core/basic_window.zig: -------------------------------------------------------------------------------- 1 | // raylib-zig (c) Nikolas Wipper 2023 2 | 3 | const rl = @import("raylib"); 4 | 5 | pub fn main() anyerror!void { 6 | // Initialization 7 | //-------------------------------------------------------------------------------------- 8 | const screenWidth = 800; 9 | const screenHeight = 450; 10 | 11 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window"); 12 | defer rl.closeWindow(); // Close window and OpenGL context 13 | 14 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 15 | //-------------------------------------------------------------------------------------- 16 | 17 | // Main game loop 18 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 19 | // Update 20 | //---------------------------------------------------------------------------------- 21 | // TODO: Update your variables here 22 | //---------------------------------------------------------------------------------- 23 | 24 | // Draw 25 | //---------------------------------------------------------------------------------- 26 | rl.beginDrawing(); 27 | defer rl.endDrawing(); 28 | 29 | rl.clearBackground(.white); 30 | 31 | rl.drawText("Congrats! You created your first window!", 190, 200, 20, .light_gray); 32 | //---------------------------------------------------------------------------------- 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /examples/core/basic_window_web.zig: -------------------------------------------------------------------------------- 1 | // A raylib-zig port of https://github.com/raysan5/raylib/blob/master/examples/core/core_basic_window_web.c 2 | 3 | const rl = @import("raylib"); 4 | const builtin = @import("builtin"); 5 | 6 | const c = if (builtin.os.tag == .emscripten) @cImport({ 7 | @cInclude("emscripten/emscripten.h"); 8 | }); 9 | 10 | //---------------------------------------------------------------------------------- 11 | // Global Variables Definition 12 | //---------------------------------------------------------------------------------- 13 | const screenWidth = 800; 14 | const screenHeight = 450; 15 | 16 | //------------------------------------------------------------------------------------ 17 | // Program main entry point 18 | //------------------------------------------------------------------------------------ 19 | pub fn main() anyerror!void { 20 | 21 | // Initialization 22 | //-------------------------------------------------------------------------------------- 23 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window"); 24 | defer rl.closeWindow(); // Close window and OpenGL context 25 | 26 | if (builtin.os.tag == .emscripten) { 27 | c.emscripten_set_main_loop(@ptrCast(&updateDrawFrame), 0, 1); 28 | } else { 29 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 30 | 31 | // Main game loop 32 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 33 | updateDrawFrame(); 34 | } 35 | } 36 | } 37 | 38 | // Update and Draw one frame 39 | fn updateDrawFrame() void { 40 | // Update 41 | //---------------------------------------------------------------------------------- 42 | // TODO: Update your variables here 43 | //---------------------------------------------------------------------------------- 44 | 45 | // Draw 46 | //---------------------------------------------------------------------------------- 47 | rl.beginDrawing(); 48 | defer rl.endDrawing(); 49 | 50 | rl.clearBackground(.white); 51 | 52 | rl.drawText("Congrats! You created your first window!", 190, 200, 20, .light_gray); 53 | //---------------------------------------------------------------------------------- 54 | } 55 | -------------------------------------------------------------------------------- /examples/core/input_keys.zig: -------------------------------------------------------------------------------- 1 | // raylib-zig (c) Nikolas Wipper 2023 2 | 3 | const rl = @import("raylib"); 4 | 5 | pub fn main() anyerror!void { 6 | // Initialization 7 | //-------------------------------------------------------------------------------------- 8 | const screenWidth = 800; 9 | const screenHeight = 450; 10 | 11 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - keyboard input"); 12 | defer rl.closeWindow(); // Close window and OpenGL context 13 | 14 | var ballPosition = rl.Vector2.init(screenWidth / 2, screenHeight / 2); 15 | 16 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 17 | //-------------------------------------------------------------------------------------- 18 | 19 | // Main game loop 20 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 21 | 22 | // Update 23 | //---------------------------------------------------------------------------------- 24 | if (rl.isKeyDown(.right)) { 25 | ballPosition.x += 2.0; 26 | } 27 | if (rl.isKeyDown(.left)) { 28 | ballPosition.x -= 2.0; 29 | } 30 | if (rl.isKeyDown(.up)) { 31 | ballPosition.y -= 2.0; 32 | } 33 | if (rl.isKeyDown(.down)) { 34 | ballPosition.y += 2.0; 35 | } 36 | //---------------------------------------------------------------------------------- 37 | 38 | // Draw 39 | //---------------------------------------------------------------------------------- 40 | rl.beginDrawing(); 41 | defer rl.endDrawing(); 42 | 43 | rl.clearBackground(.ray_white); 44 | 45 | rl.drawText("move the ball with arrow keys", 10, 10, 20, .dark_gray); 46 | 47 | rl.drawCircleV(ballPosition, 50, .maroon); 48 | //---------------------------------------------------------------------------------- 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /examples/core/input_mouse.zig: -------------------------------------------------------------------------------- 1 | // raylib-zig (c) Nikolas Wipper 2023 2 | 3 | const rl = @import("raylib"); 4 | 5 | pub fn main() anyerror!void { 6 | // Initialization 7 | //-------------------------------------------------------------------------------------- 8 | const screenWidth = 800; 9 | const screenHeight = 450; 10 | 11 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - mouse input"); 12 | defer rl.closeWindow(); // Close window and OpenGL context 13 | 14 | var ballPosition = rl.Vector2.init(-100, -100); 15 | var ballColor = rl.Color.dark_blue; 16 | 17 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 18 | //-------------------------------------------------------------------------------------- 19 | 20 | // Main game loop 21 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 22 | // Update 23 | //---------------------------------------------------------------------------------- 24 | ballPosition = rl.getMousePosition(); 25 | ballPosition.x = @as(f32, @floatFromInt(rl.getMouseX())); 26 | ballPosition.y = @as(f32, @floatFromInt(rl.getMouseY())); 27 | 28 | if (rl.isMouseButtonPressed(.left)) { 29 | ballColor = .maroon; 30 | } else if (rl.isMouseButtonPressed(.middle)) { 31 | ballColor = .lime; 32 | } else if (rl.isMouseButtonPressed(.right)) { 33 | ballColor = .dark_blue; 34 | } 35 | //---------------------------------------------------------------------------------- 36 | 37 | // Draw 38 | //---------------------------------------------------------------------------------- 39 | rl.beginDrawing(); 40 | defer rl.endDrawing(); 41 | 42 | rl.clearBackground(.ray_white); 43 | 44 | rl.drawCircleV(ballPosition, 40, ballColor); 45 | 46 | rl.drawText("move ball with mouse and click mouse button to change color", 10, 10, 20, .dark_gray); 47 | //---------------------------------------------------------------------------------- 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /examples/core/input_mouse_wheel.zig: -------------------------------------------------------------------------------- 1 | // raylib-zig (c) Nikolas Wipper 2023 2 | 3 | const rl = @import("raylib"); 4 | const std = @import("std"); 5 | 6 | pub fn main() anyerror!void { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const screenWidth = 800; 10 | const screenHeight = 450; 11 | 12 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window"); 13 | defer rl.closeWindow(); // Close window and OpenGL context 14 | 15 | var boxPositionY: f32 = screenHeight / 2 - 40; 16 | const scrollSpeed: f32 = 4; // Scrolling speed in pixels 17 | 18 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 19 | //-------------------------------------------------------------------------------------- 20 | 21 | // Main game loop 22 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 23 | // Update 24 | //---------------------------------------------------------------------------------- 25 | boxPositionY -= (rl.getMouseWheelMove() * scrollSpeed); 26 | //---------------------------------------------------------------------------------- 27 | 28 | // Draw 29 | //---------------------------------------------------------------------------------- 30 | rl.beginDrawing(); 31 | defer rl.endDrawing(); 32 | 33 | rl.clearBackground(.white); 34 | 35 | rl.drawRectangle(screenWidth / 2 - 40, @as(i32, @intFromFloat(boxPositionY)), 80, 80, .maroon); 36 | 37 | rl.drawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, .gray); 38 | 39 | rl.drawText( 40 | rl.textFormat("Box position Y: %03i", .{@as(i32, @intFromFloat(boxPositionY))}), 41 | 10, 42 | 40, 43 | 20, 44 | .light_gray, 45 | ); 46 | //---------------------------------------------------------------------------------- 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /examples/core/input_multitouch.zig: -------------------------------------------------------------------------------- 1 | // raylib-zig (c) Nikolas Wipper 2023 2 | 3 | const rl = @import("raylib"); 4 | 5 | pub fn main() anyerror!void { 6 | // Initialization 7 | //-------------------------------------------------------------------------------------- 8 | const screenWidth = 800; 9 | const screenHeight = 450; 10 | 11 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window"); 12 | defer rl.closeWindow(); // Close window and OpenGL context 13 | 14 | var ballPosition = rl.Vector2.init(-100, -100); 15 | var ballColor = rl.Color.beige; 16 | 17 | var touchCounter: f32 = 0; 18 | var touchPosition = rl.Vector2.init(0, 0); 19 | 20 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 21 | //-------------------------------------------------------------------------------------- 22 | 23 | // Main game loop 24 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 25 | // Update 26 | //---------------------------------------------------------------------------------- 27 | ballPosition = rl.getMousePosition(); 28 | 29 | ballColor = .beige; 30 | 31 | if (rl.isMouseButtonDown(.left)) { 32 | ballColor = .maroon; 33 | } 34 | if (rl.isMouseButtonDown(.middle)) { 35 | ballColor = .lime; 36 | } 37 | if (rl.isMouseButtonDown(.right)) { 38 | ballColor = .dark_blue; 39 | } 40 | 41 | if (rl.isMouseButtonPressed(.left)) { 42 | touchCounter = 10; 43 | } 44 | if (rl.isMouseButtonPressed(.middle)) { 45 | touchCounter = 10; 46 | } 47 | if (rl.isMouseButtonPressed(.right)) { 48 | touchCounter = 10; 49 | } 50 | 51 | if (touchCounter > 0) { 52 | touchCounter -= 1; 53 | } 54 | //---------------------------------------------------------------------------------- 55 | 56 | // Draw 57 | //---------------------------------------------------------------------------------- 58 | rl.beginDrawing(); 59 | defer rl.endDrawing(); 60 | 61 | rl.clearBackground(.ray_white); 62 | 63 | const nums = [_]i32{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; 64 | for (nums) |i| { 65 | touchPosition = rl.getTouchPosition(i); // Get the touch point 66 | 67 | // Make sure point is not (-1,-1) as this means there is no touch for it 68 | if ((touchPosition.x >= 0) and (touchPosition.y >= 0)) { 69 | 70 | // Draw circle and touch index number 71 | rl.drawCircleV(touchPosition, 34, .orange); 72 | rl.drawText( 73 | rl.textFormat("%d", .{i}), 74 | @as(i32, @intFromFloat(touchPosition.x)) - 10, 75 | @as(i32, @intFromFloat(touchPosition.y)) - 70, 76 | 40, 77 | .black, 78 | ); 79 | } 80 | } 81 | 82 | // Draw the normal mouse location 83 | rl.drawCircleV(ballPosition, 30 + (touchCounter * 3), ballColor); 84 | 85 | rl.drawText("move ball with mouse and click mouse button to change color", 10, 10, 20, .dark_gray); 86 | rl.drawText("touch the screen at multiple locations to get multiple balls", 10, 30, 20, .dark_gray); 87 | //---------------------------------------------------------------------------------- 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /examples/core/window_flags.zig: -------------------------------------------------------------------------------- 1 | //! # raylib-zig [core] example - window flags 2 | //! 3 | //! Example originally created with raylib-zig 5.0, last time updated with 4 | //! raylib-zig 5.0 5 | //! 6 | //! Example licensed under an unmodified zlib/libpng license, which is an 7 | //! OSI-certified, BSD-like license that allows static linking with closed 8 | //! source software 9 | //! 10 | //! Copyright (c) Nikolas Wipper 2024 11 | 12 | const rl = @import("raylib"); 13 | 14 | const screen_width = 800; 15 | const screen_height = 450; 16 | 17 | pub fn main() anyerror!void { 18 | // Initialization 19 | // ------------------------------------------------------------------------- 20 | 21 | // Possible window flags 22 | // flag_vsync_hint 23 | // flag_fullscreen_mode -> not working properly -> wrong scaling! 24 | // flag_window_resizable 25 | // flag_window_undecorated 26 | // flag_window_transparent 27 | // flag_window_hidden 28 | // flag_window_minimized -> Not supported on window creation 29 | // flag_window_maximized -> Not supported on window creation 30 | // flag_window_unfocused 31 | // flag_window_topmost 32 | // flag_window_highdpi -> errors after minimize-resize, fb size is recalculated 33 | // flag_window_always_run 34 | // flag_msaa_4x_hint 35 | 36 | // Set configuration flags for window creation 37 | // rl.setConfigFlags( 38 | // @enumFromInt(@intFromEnum(rl.ConfigFlags.flag_vsync_hint) | @intFromEnum(rl.ConfigFlags.flag_msaa_4x_hint) | @intFromEnum(rl.ConfigFlags.flag_window_highdpi)), 39 | // ); 40 | rl.initWindow( 41 | screen_width, 42 | screen_height, 43 | "raylib-zig [core] example - window flags", 44 | ); 45 | defer rl.closeWindow(); // Close window and OpenGL context 46 | 47 | var ball_position = rl.Vector2.init( 48 | @floatFromInt(@divFloor(rl.getScreenWidth(), 2)), 49 | @floatFromInt(@divFloor(rl.getScreenHeight(), 2)), 50 | ); 51 | var ball_speed = rl.Vector2.init(5, 4); 52 | const ball_radius: f32 = 20; 53 | 54 | var frames_counter: i32 = 0; 55 | 56 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 57 | 58 | while (!rl.windowShouldClose()) { 59 | // Update 60 | // --------------------------------------------------------------------- 61 | if (rl.isKeyPressed(.f)) rl.toggleFullscreen(); // Modifies window size when scaling! 62 | 63 | if (rl.isKeyPressed(.r)) { 64 | if (rl.isWindowState(rl.ConfigFlags { .window_resizable = true })) { 65 | rl.clearWindowState(rl.ConfigFlags { .window_resizable = true }); 66 | } else { 67 | rl.setWindowState(rl.ConfigFlags { .window_resizable = true }); 68 | } 69 | } 70 | 71 | if (rl.isKeyPressed(.d)) { 72 | if (rl.isWindowState(rl.ConfigFlags { .window_undecorated = true })) { 73 | rl.clearWindowState(rl.ConfigFlags { .window_undecorated = true }); 74 | } else { 75 | rl.setWindowState(rl.ConfigFlags { .window_undecorated = true }); 76 | } 77 | } 78 | 79 | if (rl.isKeyPressed(.h)) { 80 | if (!rl.isWindowState(rl.ConfigFlags { .window_hidden = true })) { 81 | rl.setWindowState(rl.ConfigFlags { .window_hidden = true }); 82 | } 83 | frames_counter = 0; 84 | } 85 | 86 | if (rl.isWindowState(rl.ConfigFlags { .window_hidden = true })) { 87 | frames_counter += 1; 88 | if (frames_counter >= 240) rl.clearWindowState(rl.ConfigFlags { .window_hidden = true }); // Show window after 3 seconds 89 | } 90 | 91 | if (rl.isKeyPressed(.n)) { 92 | if (!rl.isWindowState(rl.ConfigFlags { .window_minimized = true })) { 93 | rl.minimizeWindow(); 94 | } 95 | frames_counter = 0; 96 | } 97 | 98 | if (rl.isWindowState(rl.ConfigFlags { .window_minimized = true })) { 99 | frames_counter += 1; 100 | if (frames_counter >= 240) rl.restoreWindow(); // Restore window after 3 seconds 101 | } 102 | 103 | if (rl.isKeyPressed(.m)) { 104 | // NOTE: Requires `flag_window_resizable` enabled! 105 | if (rl.isWindowState(rl.ConfigFlags { .window_maximized = true })) { 106 | rl.restoreWindow(); 107 | } else rl.maximizeWindow(); 108 | } 109 | 110 | if (rl.isKeyPressed(.u)) { 111 | if (rl.isWindowState(rl.ConfigFlags { .window_unfocused = true })) { 112 | rl.clearWindowState(rl.ConfigFlags { .window_unfocused = true }); 113 | } else rl.setWindowState(rl.ConfigFlags { .window_unfocused = true }); 114 | } 115 | 116 | if (rl.isKeyPressed(.t)) { 117 | if (rl.isWindowState(rl.ConfigFlags { .window_topmost = true })) { 118 | rl.clearWindowState(rl.ConfigFlags { .window_topmost = true }); 119 | } else rl.setWindowState(rl.ConfigFlags { .window_topmost = true }); 120 | } 121 | 122 | if (rl.isKeyPressed(.a)) { 123 | if (rl.isWindowState(rl.ConfigFlags { .window_always_run = true })) { 124 | rl.clearWindowState(rl.ConfigFlags { .window_always_run = true }); 125 | } else rl.setWindowState(rl.ConfigFlags { .window_always_run = true }); 126 | } 127 | 128 | if (rl.isKeyPressed(.v)) { 129 | if (rl.isWindowState(rl.ConfigFlags { .vsync_hint = true })) { 130 | rl.clearWindowState(rl.ConfigFlags { .vsync_hint = true }); 131 | } else rl.setWindowState(rl.ConfigFlags { .vsync_hint = true }); 132 | } 133 | 134 | // Bouncing ball logic 135 | ball_position = ball_position.add(ball_speed); 136 | 137 | if (ball_position.x >= (@as(f32, @floatFromInt(rl.getScreenWidth())) - ball_radius) or ball_position.x <= ball_radius) { 138 | ball_speed.x *= -1; 139 | } 140 | if (ball_position.y >= (@as(f32, @floatFromInt(rl.getScreenHeight())) - ball_radius) or ball_position.y <= ball_radius) { 141 | ball_speed.y *= -1; 142 | } 143 | // --------------------------------------------------------------------- 144 | 145 | // Draw 146 | // --------------------------------------------------------------------- 147 | { 148 | rl.beginDrawing(); 149 | defer rl.endDrawing(); 150 | 151 | if (rl.isWindowState(rl.ConfigFlags { .window_transparent = true })) { 152 | rl.clearBackground(.blank); 153 | } else rl.clearBackground(.ray_white); 154 | 155 | rl.drawCircleV(ball_position, ball_radius, .maroon); 156 | rl.drawRectangleLinesEx( 157 | .init(0, 0, @floatFromInt(rl.getScreenWidth()), @floatFromInt(rl.getScreenHeight())), 158 | 4, 159 | .ray_white, 160 | ); 161 | 162 | rl.drawCircleV(rl.getMousePosition(), 10, .dark_blue); 163 | 164 | rl.drawFPS(10, 10); 165 | 166 | rl.drawText( 167 | rl.textFormat("Screen Size: [%i, %i]", .{ rl.getScreenWidth(), rl.getScreenHeight() }), 168 | 10, 169 | 40, 170 | 10, 171 | .green, 172 | ); 173 | 174 | // Draw window state info 175 | rl.drawText( 176 | "Following flags can be set after window creation:", 177 | 10, 178 | 60, 179 | 10, 180 | .gray, 181 | ); 182 | rl.drawText( 183 | rl.textFormat("[F] flag_fullscreen_mode: %d", .{ 184 | @as(i32, @intFromBool(rl.isWindowState(rl.ConfigFlags { .fullscreen_mode = true }))), 185 | }), 186 | 10, 187 | 80, 188 | 10, 189 | .lime, 190 | ); 191 | rl.drawText( 192 | rl.textFormat("[R] flag_window_resizable: %d", .{ 193 | @as(i32, @intFromBool(rl.isWindowState(rl.ConfigFlags { .window_resizable = true }))), 194 | }), 195 | 10, 196 | 100, 197 | 10, 198 | .lime, 199 | ); 200 | rl.drawText( 201 | rl.textFormat("[D] flag_window_undecorated: %d", .{ 202 | @as(i32, @intFromBool(rl.isWindowState(rl.ConfigFlags { .window_undecorated = true }))), 203 | }), 204 | 10, 205 | 120, 206 | 10, 207 | .lime, 208 | ); 209 | rl.drawText( 210 | rl.textFormat("[H] flag_window_hidden: %d", .{ 211 | @as(i32, @intFromBool(rl.isWindowState(rl.ConfigFlags { .window_hidden = true }))), 212 | }), 213 | 10, 214 | 140, 215 | 10, 216 | .lime, 217 | ); 218 | rl.drawText( 219 | rl.textFormat("[N] flag_window_minimized: %d", .{ 220 | @as(i32, @intFromBool(rl.isWindowState(rl.ConfigFlags { .window_minimized = true }))), 221 | }), 222 | 10, 223 | 160, 224 | 10, 225 | .lime, 226 | ); 227 | rl.drawText( 228 | rl.textFormat("[M] flag_window_maximized: %d", .{ 229 | @as(i32, @intFromBool(rl.isWindowState(rl.ConfigFlags { .window_maximized = true }))), 230 | }), 231 | 10, 232 | 180, 233 | 10, 234 | .lime, 235 | ); 236 | rl.drawText( 237 | rl.textFormat("[U] flag_window_unfocused: %d", .{ 238 | @as(i32, @intFromBool(rl.isWindowState(rl.ConfigFlags { .window_unfocused = true }))), 239 | }), 240 | 10, 241 | 200, 242 | 10, 243 | .lime, 244 | ); 245 | rl.drawText( 246 | rl.textFormat("[T] flag_window_topmost: %d", .{ 247 | @as(i32, @intFromBool(rl.isWindowState(rl.ConfigFlags { .window_topmost = true }))), 248 | }), 249 | 10, 250 | 220, 251 | 10, 252 | .lime, 253 | ); 254 | rl.drawText( 255 | rl.textFormat("[A] flag_window_always_run: %d", .{ 256 | @as(i32, @intFromBool(rl.isWindowState(rl.ConfigFlags { .window_always_run = true }))), 257 | }), 258 | 10, 259 | 240, 260 | 10, 261 | .lime, 262 | ); 263 | rl.drawText( 264 | rl.textFormat("[V] flag_vsync_hint: %d", .{ 265 | @as(i32, @intFromBool(rl.isWindowState(rl.ConfigFlags { .vsync_hint = true }))), 266 | }), 267 | 10, 268 | 260, 269 | 10, 270 | .lime, 271 | ); 272 | 273 | rl.drawText( 274 | "Following flags can only be set before window creation:", 275 | 10, 276 | 300, 277 | 10, 278 | .gray, 279 | ); 280 | rl.drawText( 281 | rl.textFormat("flag_window_highdpi: %d", .{ 282 | @as(i32, @intFromBool(rl.isWindowState(rl.ConfigFlags { .window_highdpi = true }))), 283 | }), 284 | 10, 285 | 320, 286 | 10, 287 | .lime, 288 | ); 289 | rl.drawText( 290 | rl.textFormat("flag_window_transparent: %d", .{ 291 | @as(i32, @intFromBool(rl.isWindowState(rl.ConfigFlags { .window_transparent = true }))), 292 | }), 293 | 10, 294 | 340, 295 | 10, 296 | .lime, 297 | ); 298 | rl.drawText( 299 | rl.textFormat("flag_msaa_4x_hint: %d", .{ 300 | @as(i32, @intFromBool(rl.isWindowState(rl.ConfigFlags { .msaa_4x_hint = true }))), 301 | }), 302 | 10, 303 | 360, 304 | 10, 305 | .lime, 306 | ); 307 | } 308 | // --------------------------------------------------------------------- 309 | } 310 | } 311 | -------------------------------------------------------------------------------- /examples/gui/message_box.zig: -------------------------------------------------------------------------------- 1 | //! # raylib-zig [gui] example - message box 2 | //! 3 | //! Example originally created with raylib-zig 5.6-dev, last time updated with 4 | //! raylib-zig 5.6-dev 5 | //! 6 | //! Example licensed under an unmodified zlib/libpng license, which is an 7 | //! OSI-certified, BSD-like license that allows static linking with closed 8 | //! source software 9 | //! 10 | //! Copyright (c) Nikolas Wipper 2025 11 | 12 | const std = @import("std"); 13 | const rl = @import("raylib"); 14 | const rg = @import("raygui"); 15 | 16 | /// `rl.getColor` only accepts a `u32`. Performing `@intCast` on the return value 17 | /// of `rg.getStyle` invokes checked undefined behavior from Zig when passed to 18 | /// `rl.getColor`, hence the custom implementation here... 19 | fn getColor(hex: i32) rl.Color { 20 | var color: rl.Color = .black; 21 | // zig fmt: off 22 | color.r = @intCast((hex >> 24) & 0xFF); 23 | color.g = @intCast((hex >> 16) & 0xFF); 24 | color.b = @intCast((hex >> 8) & 0xFF); 25 | color.a = @intCast((hex >> 0) & 0xFF); 26 | // zig fmt: on 27 | return color; 28 | } 29 | 30 | pub fn main() !void { 31 | rl.initWindow(400, 200, "raygui - controls test suite"); 32 | defer rl.closeWindow(); 33 | 34 | rl.setTargetFPS(60); 35 | 36 | var show_message_box = false; 37 | 38 | const color_int = rg.getStyle(.default, .{ .default = .background_color }); 39 | 40 | while (!rl.windowShouldClose()) { 41 | rl.beginDrawing(); 42 | defer rl.endDrawing(); 43 | 44 | rl.clearBackground(getColor(color_int)); 45 | 46 | if (rg.button(.init(24, 24, 120, 30), "#191#Show Message")) 47 | show_message_box = true; 48 | 49 | if (show_message_box) { 50 | const result = rg.messageBox( 51 | .init(85, 70, 250, 100), 52 | "#191#Message Box", 53 | "Hi! This is a message", 54 | "Nice;Cool", 55 | ); 56 | 57 | if (result >= 0) show_message_box = false; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /examples/models/models_heightmap.zig: -------------------------------------------------------------------------------- 1 | const rl = @import("raylib"); 2 | 3 | pub fn main() anyerror!void { 4 | const screenWidth: i32 = 800; 5 | const screenHeight: i32 = 450; 6 | 7 | rl.initWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing"); 8 | const cameraPosition: rl.Vector3 = .{ .x = 18, .y = 21, .z = 18 }; 9 | const cameraTarget: rl.Vector3 = .{ .x = 0, .y = 0, .z = 0 }; 10 | const cameraUp: rl.Vector3 = .{ .x = 0, .y = 1, .z = 0 }; 11 | const cameraProjection = rl.CameraProjection.perspective; 12 | var camera = rl.Camera{ .fovy = 45.0, .position = cameraPosition, .up = cameraUp, .projection = cameraProjection, .target = cameraTarget }; 13 | 14 | const image: rl.Image = try rl.loadImage("examples/models/resources/heightmap.png"); 15 | 16 | const texture: rl.Texture2D = try rl.loadTextureFromImage(image); 17 | 18 | const meshSize = rl.Vector3{ .x = 16, .y = 8, .z = 16 }; 19 | const mesh = rl.genMeshHeightmap(image, meshSize); 20 | 21 | var model = try rl.loadModelFromMesh(mesh); 22 | model.materials[0].maps[@intFromEnum(rl.MATERIAL_MAP_DIFFUSE)].texture = texture; 23 | 24 | const mapPosition = rl.Vector3{ .x = -8.0, .y = 0.0, .z = -8.0 }; 25 | 26 | rl.unloadImage(image); 27 | 28 | rl.setTargetFPS(60); 29 | 30 | while (!rl.windowShouldClose()) { 31 | rl.updateCamera(&camera, .orbital); 32 | rl.beginDrawing(); 33 | 34 | rl.clearBackground(.ray_white); 35 | rl.beginMode3D(camera); 36 | rl.drawModel(model, mapPosition, 1, .red); 37 | rl.drawGrid(20, 1.0); 38 | rl.endMode3D(); 39 | rl.drawTexture(texture, screenWidth - texture.width - 20, 20, .white); 40 | rl.drawRectangleLines(screenWidth - texture.width - 20, 20, texture.width, texture.height, .green); 41 | rl.drawFPS(10, 10); 42 | 43 | rl.endDrawing(); 44 | } 45 | rl.unloadTexture(texture); 46 | rl.unloadModel(model); 47 | 48 | rl.closeWindow(); 49 | } 50 | -------------------------------------------------------------------------------- /examples/models/resources/heightmap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Not-Nik/raylib-zig/3bf08a304cfe2baf839705063ff999b8d8bc8c54/examples/models/resources/heightmap.png -------------------------------------------------------------------------------- /examples/shaders/raymarching.zig: -------------------------------------------------------------------------------- 1 | // raylib [shaders] example - Raymarching shapes generation 2 | // 3 | // Example complexity rating: [★★★★] 4/4 4 | // 5 | // NOTE: This example requires raylib OpenGL 3.3 for shaders support and only #version 330 6 | // is currently supported. OpenGL ES 2.0 platforms are not supported at the moment. 7 | // 8 | // Example originally created with raylib 2.0, last time updated with raylib 4.2 9 | // 10 | // Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, 11 | // BSD-like license that allows static linking with closed source software 12 | // 13 | // Copyright (c) 2018-2025 Ramon Santamaria (@raysan5) 14 | 15 | const rl = @import("raylib"); 16 | const std = @import("std"); 17 | 18 | //------------------------------------------------------------------------------------ 19 | // Program main entry point 20 | //------------------------------------------------------------------------------------ 21 | pub fn main() anyerror!void { 22 | // Initialization 23 | //-------------------------------------------------------------------------------------- 24 | const screenWidth = 800; 25 | const screenHeight = 450; 26 | 27 | rl.setConfigFlags(rl.ConfigFlags{ .window_resizable = true }); 28 | rl.initWindow(screenWidth, screenHeight, "raylib [shaders] example - raymarching shapes"); 29 | defer rl.closeWindow(); // Close window and OpenGL context 30 | 31 | // Define the camera to look into our 3d world 32 | var camera = rl.Camera3D{ 33 | .position = .{ .x = 2.5, .y = 2.5, .z = 3.0 }, // Camera position 34 | .target = .{ .x = 0.0, .y = 0.0, .z = 0.7 }, // Camera looking at point 35 | .up = .{ .x = 0.0, .y = 1.0, .z = 0.0 }, // Camera up vector (rotation towards target) 36 | .fovy = 65.0, // Camera field-of-view Y 37 | .projection = .perspective, // Camera projection type 38 | }; 39 | 40 | // Load raymarching shader 41 | const shader = try rl.loadShader(null, "resources/shaders/glsl330/raymarching.fs"); 42 | defer rl.unloadShader(shader); 43 | 44 | // Get shader locations for required uniforms 45 | const viewEyeLoc = rl.getShaderLocation(shader, "viewEye"); 46 | const viewCenterLoc = rl.getShaderLocation(shader, "viewCenter"); 47 | const runTimeLoc = rl.getShaderLocation(shader, "runTime"); 48 | const resolutionLoc = rl.getShaderLocation(shader, "resolution"); 49 | 50 | var resolution = [2]f32{ @floatFromInt(screenWidth), @floatFromInt(screenHeight) }; 51 | rl.setShaderValue(shader, resolutionLoc, &resolution, .vec2); 52 | 53 | var runTime: f32 = 0.0; 54 | 55 | rl.disableCursor(); // Limit cursor to relative movement inside the window 56 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 57 | //-------------------------------------------------------------------------------------- 58 | 59 | // Main game loop 60 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 61 | // Update 62 | //---------------------------------------------------------------------------------- 63 | rl.updateCamera(&camera, .first_person); 64 | 65 | const cameraPos = [3]f32{ camera.position.x, camera.position.y, camera.position.z }; 66 | const cameraTarget = [3]f32{ camera.target.x, camera.target.y, camera.target.z }; 67 | 68 | const deltaTime = rl.getFrameTime(); 69 | runTime += deltaTime; 70 | 71 | // Set shader required uniform values 72 | rl.setShaderValue(shader, viewEyeLoc, &cameraPos, .vec3); 73 | rl.setShaderValue(shader, viewCenterLoc, &cameraTarget, .vec3); 74 | rl.setShaderValue(shader, runTimeLoc, &runTime, .float); 75 | 76 | // Check if screen is resized 77 | if (rl.isWindowResized()) { 78 | resolution = [2]f32{ 79 | @floatFromInt(rl.getScreenWidth()), 80 | @floatFromInt(rl.getScreenHeight()), 81 | }; 82 | rl.setShaderValue(shader, resolutionLoc, &resolution, .vec2); 83 | } 84 | 85 | // Draw 86 | //---------------------------------------------------------------------------------- 87 | rl.beginDrawing(); 88 | defer rl.endDrawing(); 89 | 90 | rl.clearBackground(.ray_white); 91 | 92 | // We only draw a white full-screen rectangle, 93 | // frame is generated in shader using raymarching 94 | { 95 | rl.beginShaderMode(shader); 96 | defer rl.endShaderMode(); 97 | 98 | rl.drawRectangle( 99 | 0, 100 | 0, 101 | rl.getScreenWidth(), 102 | rl.getScreenHeight(), 103 | .white, 104 | ); 105 | } 106 | 107 | rl.drawText( 108 | "(c) Raymarching shader by Iñigo Quilez. MIT License.", 109 | rl.getScreenWidth() - 280, 110 | rl.getScreenHeight() - 20, 111 | 10, 112 | .black, 113 | ); 114 | //---------------------------------------------------------------------------------- 115 | } 116 | } 117 | 118 | -------------------------------------------------------------------------------- /examples/shaders/texture_outline.zig: -------------------------------------------------------------------------------- 1 | // A raylib port of https://github.com/raysan5/raylib/blob/master/examples/shaders/shaders_texture_outline.c 2 | 3 | const rl = @import("raylib"); 4 | const std = @import("std"); 5 | 6 | //------------------------------------------------------------------------------------ 7 | // Program main entry point 8 | //------------------------------------------------------------------------------------ 9 | pub fn main() anyerror!void { 10 | // Initialization 11 | //-------------------------------------------------------------------------------------- 12 | const screenWidth = 800; 13 | const screenHeight = 450; 14 | 15 | rl.initWindow(screenWidth, screenHeight, "raylib [shaders] example - Apply an outline to a texture"); 16 | defer rl.closeWindow(); // Close window and OpenGL context 17 | 18 | const texture: rl.Texture = try .init("resources/textures/fudesumi.png"); 19 | defer rl.unloadTexture(texture); 20 | 21 | const shdrOutline: rl.Shader = try rl.loadShader(null, "resources/shaders/glsl330/outline.fs"); 22 | defer rl.unloadShader(shdrOutline); 23 | 24 | var outlineSize: f32 = 2.0; 25 | const outlineColor = [4]f32{ 1.0, 0.0, 0.0, 1.0 }; // Normalized RED color 26 | const textureSize = rl.Vector2.init( 27 | @as(f32, @floatFromInt(texture.width)), 28 | @as(f32, @floatFromInt(texture.height)), 29 | ); 30 | 31 | // Get shader locations 32 | const outlineSizeLoc = rl.getShaderLocation(shdrOutline, "outlineSize"); 33 | const outlineColorLoc = rl.getShaderLocation(shdrOutline, "outlineColor"); 34 | const textureSizeLoc = rl.getShaderLocation(shdrOutline, "textureSize"); 35 | 36 | // Set shader values (they can be changed later) 37 | rl.setShaderValue( 38 | shdrOutline, 39 | outlineSizeLoc, 40 | &outlineSize, 41 | .float, 42 | ); 43 | rl.setShaderValue( 44 | shdrOutline, 45 | outlineColorLoc, 46 | &outlineColor, 47 | .vec4, 48 | ); 49 | rl.setShaderValue( 50 | shdrOutline, 51 | textureSizeLoc, 52 | &textureSize, 53 | .vec2, 54 | ); 55 | 56 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 57 | //-------------------------------------------------------------------------------------- 58 | 59 | // Main game loop 60 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 61 | // Update 62 | //---------------------------------------------------------------------------------- 63 | outlineSize += rl.getMouseWheelMove(); 64 | if (outlineSize < 1.0) outlineSize = 1.0; 65 | 66 | rl.setShaderValue( 67 | shdrOutline, 68 | outlineSizeLoc, 69 | &outlineSize, 70 | .float, 71 | ); 72 | //---------------------------------------------------------------------------------- 73 | 74 | // Draw 75 | //---------------------------------------------------------------------------------- 76 | rl.beginDrawing(); 77 | defer rl.endDrawing(); 78 | 79 | rl.clearBackground(.ray_white); 80 | 81 | { 82 | rl.beginShaderMode(shdrOutline); 83 | defer rl.endShaderMode(); 84 | 85 | texture.draw( 86 | @divFloor(rl.getScreenWidth(), 2) - @divFloor(texture.width, 2), 87 | -30, 88 | .white, 89 | ); 90 | } 91 | 92 | rl.drawText("Shader-based\ntexture\noutline", 10, 10, 20, .gray); 93 | 94 | rl.drawText( 95 | rl.textFormat("Outline size: %i px", .{@as(i32, @intFromFloat(outlineSize))}), 96 | 10, 97 | 120, 98 | 20, 99 | .maroon, 100 | ); 101 | 102 | rl.drawFPS(710, 10); 103 | //---------------------------------------------------------------------------------- 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /examples/shapes/basic_shapes.zig: -------------------------------------------------------------------------------- 1 | const rl = @import("raylib"); 2 | 3 | pub fn main() anyerror!void { 4 | // Initialization 5 | //-------------------------------------------------------------------------------------- 6 | const screenWidth = 800; 7 | const screenHeight = 450; 8 | 9 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [shapes] example - basic shapes drawing"); 10 | defer rl.closeWindow(); // Close window and OpenGL context 11 | 12 | var rotation: f32 = 0.0; 13 | 14 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 15 | //-------------------------------------------------------------------------------------- 16 | 17 | // Main game loop 18 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 19 | // Update 20 | //---------------------------------------------------------------------------------- 21 | rotation += 0.2; 22 | //---------------------------------------------------------------------------------- 23 | 24 | // Draw 25 | //---------------------------------------------------------------------------------- 26 | rl.beginDrawing(); 27 | defer rl.endDrawing(); 28 | 29 | rl.clearBackground(.ray_white); 30 | 31 | rl.drawText("some basic shapes available on raylib", 20, 20, 20, .dark_gray); 32 | 33 | // Circle shapes and lines 34 | rl.drawCircle(screenWidth / 5, 120, 35, .dark_blue); 35 | rl.drawCircleGradient(screenWidth / 5, 220, 60, .green, .sky_blue); 36 | rl.drawCircleLines(screenWidth / 5, 340, 80, .dark_blue); 37 | 38 | // Rectangle shapes and lines 39 | rl.drawRectangle(screenWidth / 4 * 2 - 60, 100, 120, 60, .red); 40 | rl.drawRectangleGradientH(screenWidth / 4 * 2 - 90, 170, 180, 130, .maroon, .gold); 41 | rl.drawRectangleLines(screenWidth / 4 * 2 - 40, 320, 80, 60, .orange); // NOTE: Uses QUADS internally, not lines 42 | 43 | // Triangle shapes and lines 44 | rl.drawTriangle(.{ .x = (screenWidth / 4.0 * 3.0), .y = 80.0 }, .{ .x = (screenWidth / 4.0 * 3.0 - 60.0), .y = 150.0 }, .{ .x = (screenWidth / 4.0 * 3.0 + 60.0), .y = 150.0 }, .violet); 45 | 46 | rl.drawTriangleLines(.{ .x = (screenWidth / 4.0 * 3.0), .y = 160.0 }, .{ .x = (screenWidth / 4.0 * 3.0 - 20.0), .y = 230.0 }, .{ .x = (screenWidth / 4.0 * 3.0 + 20.0), .y = 230.0 }, .dark_blue); 47 | 48 | // Polygon shapes and lines 49 | rl.drawPoly(.{ .x = (screenWidth / 4.0 * 3), .y = 330 }, 6, 80, rotation, .brown); 50 | rl.drawPolyLines(.{ .x = (screenWidth / 4.0 * 3), .y = 330 }, 6, 90, rotation, .brown); 51 | rl.drawPolyLinesEx(.{ .x = (screenWidth / 4.0 * 3), .y = 330 }, 6, 85, rotation, 6, .beige); 52 | 53 | // NOTE: We draw all LINES based shapes together to optimize internal drawing, 54 | // this way, all LINES are rendered in a single draw pass 55 | rl.drawLine(18, 42, screenWidth - 18, 42, .black); 56 | //---------------------------------------------------------------------------------- 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /examples/shapes/bouncing_ball.zig: -------------------------------------------------------------------------------- 1 | const rl = @import("raylib"); 2 | 3 | pub fn main() anyerror!void { 4 | // Initialization 5 | //-------------------------------------------------------------------------------------- 6 | const screenWidth = 800; 7 | const screenHeight = 450; 8 | 9 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [shapes] example - bouncing ball"); 10 | defer rl.closeWindow(); // Close window and OpenGL context 11 | 12 | var ballPosition: rl.Vector2 = rl.Vector2{ 13 | .x = @floatFromInt(@divExact(rl.getScreenWidth(), 2)), 14 | .y = @floatFromInt(@divExact(rl.getScreenHeight(), 2)), 15 | }; 16 | var ballSpeed: rl.Vector2 = rl.Vector2{ .x = 5.0, .y = 4.0 }; 17 | const ballRadius: i32 = 20; 18 | 19 | var pause: bool = false; 20 | var framesCounter: i32 = 0; 21 | 22 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 23 | //-------------------------------------------------------------------------------------- 24 | 25 | // Main game loop 26 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 27 | // Update 28 | //---------------------------------------------------------------------------------- 29 | if (rl.isKeyPressed(.space)) { 30 | pause = !pause; 31 | } 32 | 33 | if (!pause) { 34 | ballPosition.x += ballSpeed.x; 35 | ballPosition.y += ballSpeed.y; 36 | 37 | const ballWidthEdge: f32 = @floatFromInt(rl.getScreenWidth() - ballRadius); 38 | if ((ballPosition.x >= ballWidthEdge) or (ballPosition.x <= ballRadius)) { 39 | ballSpeed.x = ballSpeed.x * -1.0; 40 | } 41 | 42 | const ballHeightEdge: f32 = @floatFromInt(rl.getScreenHeight() - ballRadius); 43 | if ((ballPosition.y >= ballHeightEdge) or (ballPosition.y <= ballRadius)) { 44 | ballSpeed.y = ballSpeed.y * -1.0; 45 | } 46 | } else { 47 | framesCounter += 1; 48 | } 49 | //---------------------------------------------------------------------------------- 50 | 51 | // Draw 52 | //---------------------------------------------------------------------------------- 53 | rl.beginDrawing(); 54 | defer rl.endDrawing(); 55 | 56 | rl.clearBackground(.ray_white); 57 | 58 | rl.drawCircleV(ballPosition, ballRadius, .maroon); 59 | rl.drawText("PRESS SPACE to PAUSE BALL MOVEMENT", 10, rl.getScreenHeight() - 25, 20, .light_gray); 60 | 61 | // On pause, we draw a blinking message 62 | if (pause and @mod(@divFloor(framesCounter, 30), 2) == 0) { 63 | rl.drawText("PAUSED", 350, 200, 30, .gray); 64 | } 65 | 66 | rl.drawFPS(10, 10); 67 | //---------------------------------------------------------------------------------- 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /examples/shapes/collision_area.zig: -------------------------------------------------------------------------------- 1 | const rl = @import("raylib"); 2 | 3 | fn boxFmt(colliding: bool) rl.Color { 4 | if (colliding) return .red; 5 | return .black; 6 | } 7 | 8 | pub fn main() anyerror!void { 9 | // Initialization 10 | //-------------------------------------------------------------------------------------- 11 | const screenWidth = 800; 12 | const screenHeight = 450; 13 | 14 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [shapes] example - collision area"); 15 | defer rl.closeWindow(); // Close window and OpenGL context 16 | 17 | // Box A: Movingbox 18 | var boxA = rl.Rectangle{ .x = 10, .y = (@as(f32, @floatFromInt(rl.getScreenHeight())) / 2.0) - 50, .width = 200, .height = 100 }; 19 | var boxASpeedX: f32 = 4; 20 | 21 | // Box B: Mouse moved box 22 | var boxB = rl.Rectangle{ .x = (@as(f32, @floatFromInt(rl.getScreenWidth())) / 2.0) - 30, .y = (@as(f32, @floatFromInt(rl.getScreenHeight())) / 2.0) - 30, .width = 60, .height = 60 }; 23 | 24 | var boxCollision = rl.Rectangle{ .x = 0, .y = 0, .width = 0, .height = 0 }; 25 | 26 | const screenUpperLimit = 40; 27 | 28 | var pause = false; 29 | var collision = false; 30 | 31 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 32 | //-------------------------------------------------------------------------------------- 33 | 34 | // Main game loop 35 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 36 | // Update 37 | //---------------------------------------------------------------------------------- 38 | // Move box if not paused 39 | if (!pause) { 40 | boxA.x += boxASpeedX; 41 | } 42 | 43 | // Bounce box on x screen limits 44 | if ((boxA.x + boxA.width) >= @as(f32, @floatFromInt(rl.getScreenWidth())) or (boxA.x <= 0)) { 45 | boxASpeedX *= -1; 46 | } 47 | 48 | // Update player-controlled-box (box02) 49 | boxB.x = @as(f32, @floatFromInt(rl.getMouseX())) - boxB.width / 2; 50 | boxB.y = @as(f32, @floatFromInt(rl.getMouseY())) - boxB.height / 2; 51 | 52 | // Make sure Box B does not go out of move area limits 53 | if ((boxB.x + boxB.width) >= @as(f32, @floatFromInt(rl.getScreenWidth()))) { 54 | boxB.x = @as(f32, @floatFromInt(rl.getScreenWidth())) - boxB.width; 55 | } else if (boxB.x <= 0) { 56 | boxB.x = 0; 57 | } 58 | 59 | if ((boxB.y + boxB.height) >= @as(f32, @floatFromInt(rl.getScreenHeight()))) { 60 | boxB.y = @as(f32, @floatFromInt(rl.getScreenHeight())) - boxB.height; 61 | } else if (boxB.y <= screenUpperLimit) { 62 | boxB.y = screenUpperLimit; 63 | } 64 | 65 | // Check boxes collision 66 | collision = rl.checkCollisionRecs(boxA, boxB); 67 | 68 | // Get collision rectangle (only on collision) 69 | if (collision) { 70 | boxCollision = rl.getCollisionRec(boxA, boxB); 71 | } 72 | 73 | // Pause Box A movement 74 | if (rl.isKeyPressed(.space)) { 75 | pause = !pause; 76 | } 77 | //---------------------------------------------------------------------------------- 78 | 79 | // Draw 80 | //---------------------------------------------------------------------------------- 81 | rl.beginDrawing(); 82 | defer rl.endDrawing(); 83 | 84 | rl.drawRectangle(0, 0, screenWidth, screenUpperLimit, boxFmt(collision)); 85 | 86 | rl.drawRectangleRec(boxA, .gold); 87 | rl.drawRectangleRec(boxB, .blue); 88 | 89 | if (collision) { 90 | // Draw collision area 91 | rl.drawRectangleRec(boxCollision, .lime); 92 | 93 | // Draw collision message 94 | rl.drawText( 95 | "COLLISION!", 96 | @divFloor(rl.getScreenWidth(), @as(i32, 2)) - @divFloor(rl.measureText("COLLISION!", 20), @as(i32, 2)), 97 | screenUpperLimit / 2 - 10, 98 | 20, 99 | .black, 100 | ); 101 | 102 | // Draw collision area 103 | rl.drawText(rl.textFormat("Collision Area: %i", .{@as(i32, @intFromFloat(boxCollision.width * boxCollision.height))}), @divFloor(rl.getScreenWidth(), 2) - 100, screenUpperLimit + 10, 20, .black); 104 | } 105 | 106 | // Draw help instructions 107 | rl.drawText("Press SPACE to PAUSE/RESUME", 20, screenHeight - 35, 20, .light_gray); 108 | 109 | rl.drawFPS(10, 10); 110 | 111 | rl.clearBackground(.ray_white); 112 | //---------------------------------------------------------------------------------- 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /examples/shapes/colors_palette.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const rl = @import("raylib"); 3 | 4 | const maxColorCount = 21; // Number of colors available 5 | 6 | pub fn getAlpha(state: bool) f32 { 7 | if (state) { 8 | return 0.6; 9 | } 10 | return 1.0; 11 | } 12 | 13 | pub fn main() anyerror!void { 14 | // Initialization 15 | //-------------------------------------------------------------------------------------- 16 | const screenWidth = 800; 17 | const screenHeight = 450; 18 | 19 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [shapes] example - colors palette"); 20 | defer rl.closeWindow(); // Close window and OpenGL context 21 | 22 | const colors = [maxColorCount]rl.Color{ 23 | .dark_gray, 24 | .maroon, 25 | .orange, 26 | .dark_green, 27 | .dark_blue, 28 | .dark_purple, 29 | .dark_brown, 30 | .gray, 31 | .red, 32 | .gold, 33 | .lime, 34 | .blue, 35 | .violet, 36 | .brown, 37 | .light_gray, 38 | .pink, 39 | .yellow, 40 | .green, 41 | .sky_blue, 42 | .purple, 43 | .beige, 44 | }; 45 | 46 | const colorNames = [maxColorCount][:0]const u8{ 47 | "DARKGRAY", 48 | "MAROON", 49 | "ORANGE", 50 | "DARKGREEN", 51 | "DARKBLUE", 52 | "DARKPURPLE", 53 | "DARKBROWN", 54 | "GRAY", 55 | "RED", 56 | "GOLD", 57 | "LIME", 58 | "BLUE", 59 | "VIOLET", 60 | "BROWN", 61 | "LIGHTGRAY", 62 | "PINK", 63 | "YELLOW", 64 | "GREEN", 65 | "SKYBLUE", 66 | "PURPLE", 67 | "BEIGE", 68 | }; 69 | 70 | var colorsRecs = std.mem.zeroes([maxColorCount]rl.Rectangle); 71 | 72 | var i: u8 = 0; 73 | while (i < maxColorCount) : (i += 1) { 74 | colorsRecs[i].x = 20.0 + 100.0 * @as(f32, @floatFromInt(i % 7)) + 10.0 * @as(f32, @floatFromInt(i % 7)); 75 | colorsRecs[i].y = 80.0 + 100.0 * @as(f32, @floatFromInt(i / 7)) + 10.0 * @as(f32, @floatFromInt(i / 7)); 76 | colorsRecs[i].width = 100.0; 77 | colorsRecs[i].height = 100.0; 78 | } 79 | 80 | var colorState: [maxColorCount]bool = std.mem.zeroes([maxColorCount]bool); 81 | 82 | var mousePoint = rl.Vector2{ .x = 0.0, .y = 0.0 }; 83 | 84 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 85 | //-------------------------------------------------------------------------------------- 86 | 87 | // Main game loop 88 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 89 | // Update 90 | //---------------------------------------------------------------------------------- 91 | mousePoint = rl.getMousePosition(); 92 | 93 | i = 0; 94 | while (i < maxColorCount) : (i += 1) { 95 | if (rl.checkCollisionPointRec(mousePoint, colorsRecs[i])) { 96 | colorState[i] = true; 97 | } else { 98 | colorState[i] = false; 99 | } 100 | } 101 | //---------------------------------------------------------------------------------- 102 | 103 | // Draw 104 | //---------------------------------------------------------------------------------- 105 | rl.beginDrawing(); 106 | defer rl.endDrawing(); 107 | 108 | rl.clearBackground(.ray_white); 109 | 110 | rl.drawText("raylib colors palette", 28, 42, 20, .black); 111 | rl.drawText("press SPACE to see all colors", rl.getScreenWidth() - 180, rl.getScreenHeight() - 40, 10, .gray); 112 | 113 | i = 0; 114 | while (i < maxColorCount) : (i += 1) { 115 | rl.drawRectangleRec(colorsRecs[i], .fade(colors[i], getAlpha(colorState[i]))); 116 | 117 | if (rl.isKeyDown(.space) or colorState[i]) { 118 | rl.drawRectangle(@intFromFloat(colorsRecs[i].x), @as(i32, @intFromFloat(colorsRecs[i].y)) + @as(i32, @intFromFloat(colorsRecs[i].height)) - 26, @as(i32, @intFromFloat(colorsRecs[i].width)), 20, .black); 119 | rl.drawRectangleLinesEx(colorsRecs[i], 6, .fade(.black, 0.3)); 120 | 121 | rl.drawText(colorNames[i], @as(i32, @intFromFloat(colorsRecs[i].x)) + @as(i32, @intFromFloat(colorsRecs[i].width)) - rl.measureText(colorNames[i], 10) - 12, @as(i32, @intFromFloat(colorsRecs[i].y)) + @as(i32, @intFromFloat(colorsRecs[i].height)) - 20, 10, colors[i]); 122 | } 123 | } 124 | //---------------------------------------------------------------------------------- 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /examples/shapes/draw_circle_sector.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const math = std.math; 3 | const rl = @import("raylib"); 4 | const rgui = @import("raygui"); 5 | 6 | fn labelFmt(segments: f32, minSegments: f32) [*c]const u8 { 7 | if (segments >= minSegments) return "MANUAL"; 8 | return "AUTO"; 9 | } 10 | 11 | fn colorFmt(segments: f32, minSegments: f32) rl.Color { 12 | if (segments >= minSegments) return .maroon; 13 | return .dark_gray; 14 | } 15 | 16 | pub fn main() anyerror!void { 17 | // Initialization 18 | //-------------------------------------------------------------------------------------- 19 | const screenWidth = 800; 20 | const screenHeight = 450; 21 | 22 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [shapes] example - draw circle sector"); 23 | defer rl.closeWindow(); // Close window and OpenGL context 24 | 25 | const center = rl.Vector2{ .x = @as(f32, @floatFromInt(rl.getScreenWidth() - 300)) / 2.0, .y = @as(f32, @floatFromInt(rl.getScreenHeight())) / 2.0 }; 26 | 27 | var outerRadius: f32 = 180.0; 28 | var startAngle: f32 = 0.0; 29 | var endAngle: f32 = 180.0; 30 | var segments: f32 = 10.0; 31 | var minSegments: f32 = 4; 32 | 33 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 34 | //-------------------------------------------------------------------------------------- 35 | 36 | // Main game loop 37 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 38 | // Update 39 | //---------------------------------------------------------------------------------- 40 | // NOTE: All variables update happens inside GUI control functions 41 | //---------------------------------------------------------------------------------- 42 | 43 | // Draw 44 | //---------------------------------------------------------------------------------- 45 | rl.beginDrawing(); 46 | defer rl.endDrawing(); 47 | 48 | rl.clearBackground(.ray_white); 49 | 50 | rl.drawLine(500, 0, 500, rl.getScreenHeight(), .fade(.light_gray, 0.6)); 51 | rl.drawRectangle(500, 0, rl.getScreenWidth() - 500, rl.getScreenHeight(), .fade(.light_gray, 0.3)); 52 | 53 | rl.drawCircleSector(center, outerRadius, startAngle, endAngle, @as(i32, @intFromFloat(segments)), .fade(.maroon, 0.3)); 54 | rl.drawCircleSectorLines(center, outerRadius, startAngle, endAngle, @as(i32, @intFromFloat(segments)), .fade(.maroon, 0.6)); 55 | 56 | // Draw GUI controls 57 | _ = rgui.guiSliderBar(rl.Rectangle{ .x = 600, .y = 40, .width = 120, .height = 20 }, "StartAngle", rl.textFormat("%.2", .{startAngle}), &startAngle, 0, 720); 58 | _ = rgui.guiSliderBar(rl.Rectangle{ .x = 600, .y = 70, .width = 120, .height = 20 }, "EndAngle", rl.textFormat("%.2", .{endAngle}), &endAngle, 0, 720); 59 | 60 | _ = rgui.guiSliderBar(rl.Rectangle{ .x = 600, .y = 140, .width = 120, .height = 20 }, "Radius", rl.textFormat("%.2", .{outerRadius}), &outerRadius, 0, 200); 61 | _ = rgui.guiSliderBar(rl.Rectangle{ .x = 600, .y = 170, .width = 120, .height = 20 }, "Segments", rl.textFormat("%.2", .{segments}), &segments, 0, 100); 62 | 63 | minSegments = math.trunc(math.ceil((endAngle - startAngle) / 90)); 64 | rl.drawText(rl.textFormat("MODE: %s", .{labelFmt(segments, minSegments)}), 600, 200, 10, colorFmt(segments, minSegments)); 65 | 66 | rl.drawFPS(10, 10); 67 | //---------------------------------------------------------------------------------- 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /examples/shapes/draw_rectangle_rounded.zig: -------------------------------------------------------------------------------- 1 | const rl = @import("raylib"); 2 | const rgui = @import("raygui"); 3 | 4 | fn labelFmt(segments: f32) [*c]const u8 { 5 | if (segments >= 4) return "MANUAL"; 6 | return "AUTO"; 7 | } 8 | 9 | fn colorFmt(segments: f32) rl.Color { 10 | if (segments >= 4) return .maroon; 11 | return .dark_gray; 12 | } 13 | 14 | pub fn main() anyerror!void { 15 | // Initialization 16 | //-------------------------------------------------------------------------------------- 17 | const screenWidth = 800; 18 | const screenHeight = 450; 19 | 20 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [shapes] example - draw rectangle rounded"); 21 | defer rl.closeWindow(); // Close window and OpenGL context 22 | 23 | var roundness: f32 = 0.2; 24 | var width: f32 = 200.0; 25 | var height: f32 = 100.0; 26 | var segments: f32 = 0.0; 27 | var lineThick: f32 = 1.0; 28 | 29 | var drawRect: bool = false; 30 | var drawRoundedRect: bool = true; 31 | var drawRoundedLines: bool = false; 32 | 33 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 34 | //-------------------------------------------------------------------------------------- 35 | 36 | // Main game loop 37 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 38 | // Update 39 | //---------------------------------------------------------------------------------- 40 | const rec = rl.Rectangle{ .x = (@as(f32, @floatFromInt(rl.getScreenWidth())) - width - 250) / 2.0, .y = (@as(f32, @floatFromInt(rl.getScreenHeight())) - height) / 2.0, .width = width, .height = height }; 41 | //---------------------------------------------------------------------------------- 42 | 43 | // Draw 44 | //---------------------------------------------------------------------------------- 45 | rl.beginDrawing(); 46 | defer rl.endDrawing(); 47 | 48 | rl.clearBackground(.ray_white); 49 | 50 | rl.drawLine(560, 0, 560, rl.getScreenHeight(), .fade(.light_gray, 0.6)); 51 | rl.drawRectangle(560, 0, rl.getScreenWidth() - 500, rl.getScreenHeight(), .fade(.light_gray, 0.3)); 52 | 53 | if (drawRect) rl.drawRectangleRec(rec, .fade(.gold, 0.6)); 54 | if (drawRoundedRect) rl.drawRectangleRounded(rec, roundness, @as(i32, @intFromFloat(segments)), .fade(.maroon, 0.2)); 55 | if (drawRoundedLines) rl.drawRectangleRoundedLinesEx(rec, roundness, @as(i32, @intFromFloat(segments)), lineThick, .fade(.maroon, 0.4)); 56 | 57 | // Draw GUI controls 58 | _ = rgui.guiSliderBar(rl.Rectangle{ .x = 640, .y = 40, .width = 105, .height = 20 }, "Width", rl.textFormat("%.2", .{width}), &width, 0, @as(f32, @floatFromInt(rl.getScreenWidth() - 300))); 59 | _ = rgui.guiSliderBar(rl.Rectangle{ .x = 640, .y = 70, .width = 105, .height = 20 }, "Height", rl.textFormat("%.2", .{height}), &height, 0, @as(f32, @floatFromInt(rl.getScreenHeight() - 50))); 60 | _ = rgui.guiSliderBar(rl.Rectangle{ .x = 640, .y = 140, .width = 105, .height = 20 }, "Roundness", rl.textFormat("%.2", .{roundness}), &roundness, 0.0, 1.0); 61 | _ = rgui.guiSliderBar(rl.Rectangle{ .x = 640, .y = 170, .width = 105, .height = 20 }, "Thickness", rl.textFormat("%.2", .{lineThick}), &lineThick, 0, 20); 62 | _ = rgui.guiSliderBar(rl.Rectangle{ .x = 640, .y = 240, .width = 105, .height = 20 }, "Segments", rl.textFormat("%.2", .{segments}), &segments, 0, 60); 63 | 64 | _ = rgui.guiCheckBox(rl.Rectangle{ .x = 640, .y = 320, .width = 20, .height = 20 }, "DrawRoundedRect", &drawRoundedRect); 65 | _ = rgui.guiCheckBox(rl.Rectangle{ .x = 640, .y = 350, .width = 20, .height = 20 }, "DrawRoundedLines", &drawRoundedLines); 66 | _ = rgui.guiCheckBox(rl.Rectangle{ .x = 640, .y = 380, .width = 20, .height = 20 }, "DrawRect", &drawRect); 67 | 68 | rl.drawText(rl.textFormat("MODE: %s", .{labelFmt(segments)}), 640, 280, 10, colorFmt(segments)); 69 | 70 | rl.drawFPS(10, 10); 71 | //---------------------------------------------------------------------------------- 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /examples/shapes/draw_ring.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const math = std.math; 3 | const rl = @import("raylib"); 4 | const rgui = @import("raygui"); 5 | 6 | fn labelFmt(segments: f32, minSegments: f32) [*c]const u8 { 7 | if (segments >= minSegments) return "MANUAL"; 8 | return "AUTO"; 9 | } 10 | 11 | fn colorFmt(segments: f32, minSegments: f32) rl.Color { 12 | if (segments >= minSegments) return .maroon; 13 | return .dark_gray; 14 | } 15 | 16 | pub fn main() anyerror!void { 17 | // Initialization 18 | //-------------------------------------------------------------------------------------- 19 | const screenWidth = 800; 20 | const screenHeight = 450; 21 | 22 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [shapes] example - draw ring"); 23 | defer rl.closeWindow(); // Close window and OpenGL context 24 | 25 | const center = rl.Vector2{ .x = @as(f32, @floatFromInt(rl.getScreenWidth() - 300)) / 2.0, .y = @as(f32, @floatFromInt(rl.getScreenHeight())) / 2.0 }; 26 | 27 | var innerRadius: f32 = 80.0; 28 | var outerRadius: f32 = 190.0; 29 | 30 | var startAngle: f32 = 0.0; 31 | var endAngle: f32 = 360.0; 32 | var segments: f32 = 0.0; 33 | 34 | var drawRing = true; 35 | var drawRingLines = false; 36 | var drawCircleLines = false; 37 | 38 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 39 | //-------------------------------------------------------------------------------------- 40 | 41 | // Main game loop 42 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 43 | // Update 44 | //---------------------------------------------------------------------------------- 45 | // NOTE: All variables update happens inside GUI control functions 46 | //---------------------------------------------------------------------------------- 47 | 48 | // Draw 49 | //---------------------------------------------------------------------------------- 50 | rl.beginDrawing(); 51 | defer rl.endDrawing(); 52 | 53 | rl.clearBackground(.ray_white); 54 | 55 | rl.drawLine(500, 0, 500, rl.getScreenHeight(), .fade(.light_gray, 0.6)); 56 | rl.drawRectangle(500, 0, rl.getScreenWidth() - 500, rl.getScreenHeight(), .fade(.light_gray, 0.3)); 57 | 58 | if (drawRing) rl.drawRing(center, innerRadius, outerRadius, startAngle, endAngle, @intFromFloat(segments), .fade(.maroon, 0.3)); 59 | if (drawRingLines) rl.drawRingLines(center, innerRadius, outerRadius, startAngle, endAngle, @intFromFloat(segments), .fade(.black, 0.4)); 60 | if (drawCircleLines) rl.drawCircleSectorLines(center, outerRadius, startAngle, endAngle, @intFromFloat(segments), .fade(.black, 0.4)); 61 | 62 | // Draw GUI controls 63 | //------------------------------------------------------------------------------ 64 | _ = rgui.guiSliderBar(rl.Rectangle{ .x = 600, .y = 40, .width = 120, .height = 20 }, "StartAngle", rl.textFormat("%.2", .{startAngle}), &startAngle, -450, 450); 65 | _ = rgui.guiSliderBar(rl.Rectangle{ .x = 600, .y = 70, .width = 120, .height = 20 }, "EndAngle", rl.textFormat("%.2", .{endAngle}), &endAngle, -450, 450); 66 | 67 | _ = rgui.guiSliderBar(rl.Rectangle{ .x = 600, .y = 140, .width = 120, .height = 20 }, "InnerRadius", rl.textFormat("%.2", .{innerRadius}), &innerRadius, 0, 100); 68 | _ = rgui.guiSliderBar(rl.Rectangle{ .x = 600, .y = 170, .width = 120, .height = 20 }, "OuterRadius", rl.textFormat("%.2", .{outerRadius}), &outerRadius, 0, 200); 69 | 70 | _ = rgui.guiSliderBar(rl.Rectangle{ .x = 600, .y = 240, .width = 120, .height = 20 }, "Segments", rl.textFormat("%.2", .{segments}), &segments, 0, 100); 71 | 72 | _ = rgui.guiCheckBox(rl.Rectangle{ .x = 600, .y = 320, .width = 20, .height = 20 }, "Draw Ring", &drawRing); 73 | _ = rgui.guiCheckBox(rl.Rectangle{ .x = 600, .y = 350, .width = 20, .height = 20 }, "Draw RingLines", &drawRingLines); 74 | _ = rgui.guiCheckBox(rl.Rectangle{ .x = 600, .y = 380, .width = 20, .height = 20 }, "Draw CircleLines", &drawCircleLines); 75 | //------------------------------------------------------------------------------ 76 | 77 | const minSegments: f32 = math.ceil((endAngle - startAngle) / 90); 78 | rl.drawText(rl.textFormat("MODE: %s", .{labelFmt(segments, minSegments)}), 600, 270, 10, colorFmt(segments, minSegments)); 79 | 80 | rl.drawFPS(10, 10); 81 | //---------------------------------------------------------------------------------- 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /examples/shapes/following_eyes.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const math = std.math; 3 | const rl = @import("raylib"); 4 | 5 | pub fn main() anyerror!void { 6 | // Initialization 7 | //-------------------------------------------------------------------------------------- 8 | const screenWidth = 800; 9 | const screenHeight = 450; 10 | 11 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [shapes] example - following eyes"); 12 | defer rl.closeWindow(); // Close window and OpenGL context 13 | 14 | const scleraLeftPosition = rl.Vector2{ .x = @as(f32, @floatFromInt(rl.getScreenWidth())) / 2.0 - 100.0, .y = @as(f32, @floatFromInt(rl.getScreenHeight())) / 2.0 }; 15 | const scleraRightPosition = rl.Vector2{ .x = @as(f32, @floatFromInt(rl.getScreenWidth())) / 2.0 + 100.0, .y = @as(f32, @floatFromInt(rl.getScreenHeight())) / 2.0 }; 16 | const scleraRadius: i32 = 80; 17 | 18 | var irisLeftPosition = rl.Vector2{ .x = @as(f32, @floatFromInt(rl.getScreenWidth())) / 2.0 - 100.0, .y = @as(f32, @floatFromInt(rl.getScreenHeight())) / 2.0 }; 19 | var irisRightPosition = rl.Vector2{ .x = @as(f32, @floatFromInt(rl.getScreenWidth())) / 2.0 + 100.0, .y = @as(f32, @floatFromInt(rl.getScreenHeight())) / 2.0 }; 20 | const irisRadius: i32 = 24; 21 | 22 | var angle: f32 = 0.0; 23 | var dx: f32 = 0.0; 24 | var dy: f32 = 0.0; 25 | var dxx: f32 = 0.0; 26 | var dyy: f32 = 0.0; 27 | 28 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 29 | //-------------------------------------------------------------------------------------- 30 | 31 | // Main game loop 32 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 33 | // Update 34 | //---------------------------------------------------------------------------------- 35 | irisLeftPosition = rl.getMousePosition(); 36 | irisRightPosition = rl.getMousePosition(); 37 | 38 | // Check not inside the left eye sclera 39 | if (!rl.checkCollisionPointCircle(irisLeftPosition, scleraLeftPosition, scleraRadius - irisRadius)) { 40 | dx = irisLeftPosition.x - scleraLeftPosition.x; 41 | dy = irisLeftPosition.y - scleraLeftPosition.y; 42 | 43 | angle = math.atan2(dy, dx); 44 | 45 | dxx = (scleraRadius - irisRadius) * math.cos(angle); 46 | dyy = (scleraRadius - irisRadius) * math.sin(angle); 47 | 48 | irisLeftPosition.x = scleraLeftPosition.x + dxx; 49 | irisLeftPosition.y = scleraLeftPosition.y + dyy; 50 | } 51 | 52 | // Check not inside the right eye sclera 53 | if (!rl.checkCollisionPointCircle(irisRightPosition, scleraRightPosition, scleraRadius - irisRadius)) { 54 | dx = irisRightPosition.x - scleraRightPosition.x; 55 | dy = irisRightPosition.y - scleraRightPosition.y; 56 | 57 | angle = math.atan2(dy, dx); 58 | 59 | dxx = (scleraRadius - irisRadius) * math.cos(angle); 60 | dyy = (scleraRadius - irisRadius) * math.sin(angle); 61 | 62 | irisRightPosition.x = scleraRightPosition.x + dxx; 63 | irisRightPosition.y = scleraRightPosition.y + dyy; 64 | } 65 | //---------------------------------------------------------------------------------- 66 | 67 | // Draw 68 | //---------------------------------------------------------------------------------- 69 | rl.beginDrawing(); 70 | defer rl.endDrawing(); 71 | 72 | rl.drawCircleV(scleraLeftPosition, scleraRadius, .light_gray); 73 | rl.drawCircleV(irisLeftPosition, irisRadius, .brown); 74 | rl.drawCircleV(irisLeftPosition, 10, .black); 75 | 76 | rl.drawCircleV(scleraRightPosition, scleraRadius, .light_gray); 77 | rl.drawCircleV(irisRightPosition, irisRadius, .dark_green); 78 | rl.drawCircleV(irisRightPosition, 10, .black); 79 | 80 | rl.drawFPS(10, 10); 81 | 82 | rl.clearBackground(.ray_white); 83 | //---------------------------------------------------------------------------------- 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /examples/shapes/lines_bezier.zig: -------------------------------------------------------------------------------- 1 | const rl = @import("raylib"); 2 | 3 | fn collisionFmt(isColliding: bool) f32 { 4 | if (isColliding) return 14.0; 5 | return 8.0; 6 | } 7 | 8 | fn movingFmt(isMoving: bool) rl.Color { 9 | if (isMoving) return .red; 10 | return .blue; 11 | } 12 | 13 | pub fn main() anyerror!void { 14 | // Initialization 15 | //-------------------------------------------------------------------------------------- 16 | const screenWidth = 800; 17 | const screenHeight = 450; 18 | 19 | //rl.setConfigFlags(@enumFromInt(rl.ConfigFlags.flag_msaa_4x_hint)); 20 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [shapes] example - cubic-bezier lines"); 21 | defer rl.closeWindow(); // Close window and OpenGL context 22 | 23 | var startPoint = rl.Vector2{ .x = 30, .y = 30 }; 24 | var endPoint = rl.Vector2{ .x = screenWidth - 30, .y = screenHeight - 30 }; 25 | var moveStartPoint = false; 26 | var moveEndPoint = false; 27 | 28 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 29 | //-------------------------------------------------------------------------------------- 30 | 31 | // Main game loop 32 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 33 | // Update 34 | //---------------------------------------------------------------------------------- 35 | const mouse: rl.Vector2 = rl.getMousePosition(); 36 | 37 | if (rl.checkCollisionPointCircle(mouse, startPoint, 10.0) and rl.isMouseButtonDown(.left)) { 38 | moveStartPoint = true; 39 | } else if (rl.checkCollisionPointCircle(mouse, endPoint, 10.0) and rl.isMouseButtonDown(.left)) { 40 | moveEndPoint = true; 41 | } 42 | 43 | if (moveStartPoint) { 44 | startPoint = mouse; 45 | if (rl.isMouseButtonReleased(.left)) { 46 | moveStartPoint = false; 47 | } 48 | } 49 | 50 | if (moveEndPoint) { 51 | endPoint = mouse; 52 | if (rl.isMouseButtonReleased(.left)) { 53 | moveEndPoint = false; 54 | } 55 | } 56 | //---------------------------------------------------------------------------------- 57 | 58 | // Draw 59 | //---------------------------------------------------------------------------------- 60 | rl.beginDrawing(); 61 | defer rl.endDrawing(); 62 | 63 | rl.clearBackground(.ray_white); 64 | 65 | rl.drawText("MOVE START-END POINTS WITH MOUSE", 15, 20, 20, .gray); 66 | 67 | // Draw line Cubic Bezier, in-out interpolation (easing), no control points 68 | rl.drawLineBezier(startPoint, endPoint, 4.0, .blue); 69 | 70 | // Draw start-end spline circles with some details 71 | rl.drawCircleV(startPoint, collisionFmt(rl.checkCollisionPointCircle(mouse, startPoint, 10.0)), movingFmt(moveStartPoint)); 72 | rl.drawCircleV(endPoint, collisionFmt(rl.checkCollisionPointCircle(mouse, endPoint, 10.0)), movingFmt(moveEndPoint)); 73 | //---------------------------------------------------------------------------------- 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /examples/shapes/logo_raylib.zig: -------------------------------------------------------------------------------- 1 | // raylib-zig (c) Nikolas Wipper 2023 2 | 3 | const rl = @import("raylib"); 4 | 5 | pub fn main() anyerror!void { 6 | // Initialization 7 | //-------------------------------------------------------------------------------------- 8 | const screenWidth = 800; 9 | const screenHeight = 450; 10 | 11 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [shapes] example - raylib logo using shapes"); 12 | defer rl.closeWindow(); // Close window and OpenGL context 13 | 14 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 15 | //-------------------------------------------------------------------------------------- 16 | 17 | const raylib_zig = rl.Color.init(247, 164, 29, 255); 18 | 19 | // Main game loop 20 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 21 | // Update 22 | //---------------------------------------------------------------------------------- 23 | // TODO: Update your variables here 24 | //---------------------------------------------------------------------------------- 25 | 26 | // Draw 27 | //---------------------------------------------------------------------------------- 28 | rl.beginDrawing(); 29 | defer rl.endDrawing(); 30 | 31 | rl.clearBackground(.ray_white); 32 | 33 | rl.drawRectangle(screenWidth / 2 - 128, screenHeight / 2 - 128, 256, 256, raylib_zig); 34 | rl.drawRectangle(screenWidth / 2 - 112, screenHeight / 2 - 112, 224, 224, .ray_white); 35 | rl.drawText("raylib-zig", screenWidth / 2 - 96, screenHeight / 2 + 57, 41, raylib_zig); 36 | 37 | rl.drawText("this is NOT a texture!", 350, 370, 10, .gray); 38 | //---------------------------------------------------------------------------------- 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /examples/shapes/logo_raylib_anim.zig: -------------------------------------------------------------------------------- 1 | const rl = @import("raylib"); 2 | 3 | pub fn main() anyerror!void { 4 | // Initialization 5 | //-------------------------------------------------------------------------------------- 6 | const screenWidth = 800; 7 | const screenHeight = 450; 8 | 9 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [shapes] example - raylib logo animation"); 10 | defer rl.closeWindow(); // Close window and OpenGL context 11 | 12 | const logoPositionX = (screenWidth / 2) - 128; 13 | const logoPositionY = (screenHeight / 2) - 128; 14 | 15 | var framesCounter: u8 = 0; 16 | var lettersCount: u8 = 0; 17 | 18 | var topSideRecWidth: i32 = 16; 19 | var leftSideRecHeight: i32 = 16; 20 | 21 | var bottomSideRecWidth: i32 = 16; 22 | var rightSideRecHeight: i32 = 16; 23 | 24 | var state: u8 = 0; 25 | var alpha: f32 = 1.0; 26 | 27 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 28 | //-------------------------------------------------------------------------------------- 29 | 30 | // Main game loop 31 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 32 | // Update 33 | //---------------------------------------------------------------------------------- 34 | if (state == 0) { 35 | framesCounter += 1; 36 | if (framesCounter == 120) { 37 | state = 1; 38 | framesCounter = 0; 39 | } 40 | } else if (state == 1) { 41 | topSideRecWidth += 4; 42 | leftSideRecHeight += 4; 43 | 44 | if (topSideRecWidth == 256) state = 2; 45 | } else if (state == 2) // State 2: Bottom and right bars growing 46 | { 47 | bottomSideRecWidth += 4; 48 | rightSideRecHeight += 4; 49 | 50 | if (bottomSideRecWidth == 256) state = 3; 51 | } else if (state == 3) // State 3: Letters appearing (one by one) 52 | { 53 | framesCounter += 1; 54 | 55 | if (@mod(framesCounter, 12) == 0) // Every 12 frames, one more letter! 56 | { 57 | lettersCount += 1; 58 | framesCounter = 0; 59 | } 60 | 61 | if (lettersCount >= 10) // When all letters have appeared, just fade out everything 62 | { 63 | alpha -= 0.02; 64 | 65 | if (alpha <= 0.0) { 66 | alpha = 0.0; 67 | state = 4; 68 | } 69 | } 70 | } else if (state == 4) // State 4: Reset and Replay 71 | { 72 | if (rl.isKeyPressed(.r)) { 73 | framesCounter = 0; 74 | lettersCount = 0; 75 | 76 | topSideRecWidth = 16; 77 | leftSideRecHeight = 16; 78 | 79 | bottomSideRecWidth = 16; 80 | rightSideRecHeight = 16; 81 | 82 | alpha = 1.0; 83 | state = 0; // Return to State 0 84 | } 85 | } 86 | //---------------------------------------------------------------------------------- 87 | 88 | // Draw 89 | //---------------------------------------------------------------------------------- 90 | rl.beginDrawing(); 91 | defer rl.endDrawing(); 92 | 93 | rl.clearBackground(.ray_white); 94 | 95 | if (state == 0) { 96 | if (@mod(framesCounter, @as(u8, 15)) == 0) rl.drawRectangle(logoPositionX, logoPositionY, 16, 16, .black); 97 | } else if (state == 1) { 98 | rl.drawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, .black); 99 | rl.drawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, .black); 100 | } else if (state == 2) { 101 | rl.drawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, .black); 102 | rl.drawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, .black); 103 | 104 | rl.drawRectangle(logoPositionX + 240, logoPositionY, 16, rightSideRecHeight, .black); 105 | rl.drawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, .black); 106 | } else if (state == 3) { 107 | rl.drawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, .fade(.black, alpha)); 108 | rl.drawRectangle(logoPositionX, logoPositionY + 16, 16, leftSideRecHeight - 32, .fade(.black, alpha)); 109 | 110 | rl.drawRectangle(logoPositionX + 240, logoPositionY + 16, 16, rightSideRecHeight - 32, .fade(.black, alpha)); 111 | rl.drawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, .fade(.black, alpha)); 112 | 113 | rl.drawRectangle( 114 | (@divFloor(rl.getScreenWidth(), @as(i32, 2))) - 112, 115 | (@divFloor(rl.getScreenHeight(), @as(i32, 2))) - 112, 116 | 224, 117 | 224, 118 | .fade(.ray_white, alpha), 119 | ); 120 | 121 | rl.drawText(rl.textSubtext("raylib", 0, lettersCount), @divFloor(rl.getScreenWidth(), @as(i32, 2)) - 44, @divFloor(rl.getScreenHeight(), @as(i32, 2)) + 48, 50, .fade(.black, alpha)); 122 | } else if (state == 4) { 123 | rl.drawText("[R] REPLAY", 340, 200, 20, .gray); 124 | } 125 | 126 | //---------------------------------------------------------------------------------- 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /examples/shapes/rectangle_scaling.zig: -------------------------------------------------------------------------------- 1 | const rl = @import("raylib"); 2 | 3 | const mouseScaleMarkSize = 12; 4 | 5 | pub fn main() anyerror!void { 6 | // Initialization 7 | //-------------------------------------------------------------------------------------- 8 | const screenWidth = 800; 9 | const screenHeight = 450; 10 | 11 | rl.initWindow(screenWidth, screenHeight, "raylib-zig [shapes] example - rectangle scaling mouse"); 12 | defer rl.closeWindow(); // Close window and OpenGL context 13 | 14 | var rec: rl.Rectangle = rl.Rectangle{ .x = 100, .y = 100, .width = 200, .height = 80 }; 15 | var mousePosition: rl.Vector2 = rl.Vector2{ .x = 0, .y = 0 }; 16 | 17 | var mouseScaleReady: bool = false; 18 | var mouseScaleMode: bool = false; 19 | 20 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 21 | //-------------------------------------------------------------------------------------- 22 | 23 | // Main game loop 24 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 25 | // Update 26 | //---------------------------------------------------------------------------------- 27 | mousePosition = rl.getMousePosition(); 28 | 29 | if (rl.checkCollisionPointRec(mousePosition, rl.Rectangle{ .x = (rec.x + rec.width) - mouseScaleMarkSize, .y = (rec.y + rec.height) - mouseScaleMarkSize, .width = mouseScaleMarkSize, .height = mouseScaleMarkSize })) { 30 | mouseScaleReady = true; 31 | if (rl.isMouseButtonPressed(.left)) { 32 | mouseScaleMode = true; 33 | } 34 | } else { 35 | mouseScaleReady = false; 36 | } 37 | 38 | if (mouseScaleMode) { 39 | mouseScaleReady = true; 40 | 41 | rec.width = (mousePosition.x - rec.x); 42 | rec.height = (mousePosition.y - rec.y); 43 | 44 | // Check minimum rec size 45 | if (rec.width < mouseScaleMarkSize) { 46 | rec.width = mouseScaleMarkSize; 47 | } 48 | if (rec.height < mouseScaleMarkSize) { 49 | rec.height = mouseScaleMarkSize; 50 | } 51 | 52 | // Check maximum rec size 53 | if (rec.width > (@as(f32, @floatFromInt(rl.getScreenWidth())) - rec.x)) { 54 | rec.width = @as(f32, @floatFromInt(rl.getScreenWidth())) - rec.x; 55 | } 56 | if (rec.height > (@as(f32, @floatFromInt(rl.getScreenHeight())) - rec.y)) { 57 | rec.height = @as(f32, @floatFromInt(rl.getScreenHeight())) - rec.y; 58 | } 59 | 60 | if (rl.isMouseButtonReleased(.left)) { 61 | mouseScaleMode = false; 62 | } 63 | } 64 | //---------------------------------------------------------------------------------- 65 | 66 | // Draw 67 | //---------------------------------------------------------------------------------- 68 | rl.beginDrawing(); 69 | defer rl.endDrawing(); 70 | 71 | rl.clearBackground(.ray_white); 72 | 73 | rl.drawText("Scale rectangle dragging from bottom-right corner!", 10, 10, 20, .gray); 74 | 75 | rl.drawRectangleRec(rec, .fade(.green, 0.5)); 76 | 77 | if (mouseScaleReady) { 78 | rl.drawRectangleLinesEx(rec, 1, .red); 79 | rl.drawTriangle(rl.Vector2{ .x = rec.x + rec.width - mouseScaleMarkSize, .y = rec.y + rec.height }, rl.Vector2{ .x = rec.x + rec.width, .y = rec.y + rec.height }, rl.Vector2{ .x = rec.x + rec.width, .y = rec.y + rec.height - mouseScaleMarkSize }, .red); 80 | } 81 | //---------------------------------------------------------------------------------- 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /examples/text/text_format_text.zig: -------------------------------------------------------------------------------- 1 | // A raylib port of https://github.com/raysan5/raylib/blob/master/examples/text/text_format_text.c 2 | 3 | const rl = @import("raylib"); 4 | const std = @import("std"); 5 | 6 | //------------------------------------------------------------------------------------ 7 | // Program main entry point 8 | //------------------------------------------------------------------------------------ 9 | pub fn main() anyerror!void { 10 | // Initialization 11 | //-------------------------------------------------------------------------------------- 12 | const screenWidth = 800; 13 | const screenHeight = 450; 14 | 15 | rl.initWindow(screenWidth, screenHeight, "raylib [text] example - text formatting"); 16 | defer rl.closeWindow(); // Close window and OpenGL context 17 | 18 | // Set as 'const' for demonstration purposes, but would need to be 'var' once you actually update them to real values. 19 | const score: i32 = 100020; 20 | const hiscore: i32 = 200450; 21 | const lives: i32 = 5; 22 | 23 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 24 | //-------------------------------------------------------------------------------------- 25 | 26 | // Main game loop 27 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 28 | // Update 29 | //---------------------------------------------------------------------------------- 30 | // TODO: Update your variables here 31 | //---------------------------------------------------------------------------------- 32 | 33 | // Draw 34 | //---------------------------------------------------------------------------------- 35 | rl.beginDrawing(); 36 | defer rl.endDrawing(); 37 | 38 | rl.clearBackground(.white); 39 | 40 | rl.drawText(rl.textFormat("Score: %08i", .{score}), 200, 80, 20, .red); 41 | 42 | rl.drawText(rl.textFormat("HiScore: %08i", .{hiscore}), 200, 120, 20, .green); 43 | 44 | rl.drawText(rl.textFormat("Lives: %02i", .{lives}), 200, 160, 40, .blue); 45 | 46 | rl.drawText(rl.textFormat("Elapsed Time: %02.02f ms", .{rl.getFrameTime() * 1000}), 200, 220, 20, .black); 47 | //---------------------------------------------------------------------------------- 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /examples/text/text_raylib_fonts.zig: -------------------------------------------------------------------------------- 1 | const rl = @import("raylib"); 2 | const Color = rl.Color; 3 | 4 | const MAX_FONTS = 8; 5 | 6 | //------------------------------------------------------------------------------------ 7 | // Program main entry point 8 | //------------------------------------------------------------------------------------ 9 | pub fn main() !void { 10 | // Initialization 11 | //-------------------------------------------------------------------------------------- 12 | const screenWidth = 800; 13 | const screenHeight = 450; 14 | 15 | rl.initWindow(screenWidth, screenHeight, "raylib [text] example - raylib fonts"); 16 | defer rl.closeWindow(); // Close window and OpenGL context 17 | 18 | // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) 19 | var fonts: [MAX_FONTS]rl.Font = undefined; 20 | 21 | fonts[0] = try rl.loadFont("resources/text/fonts/alagard.png"); 22 | fonts[1] = try rl.loadFont("resources/text/fonts/pixelplay.png"); 23 | fonts[2] = try rl.loadFont("resources/text/fonts/mecha.png"); 24 | fonts[3] = try rl.loadFont("resources/text/fonts/setback.png"); 25 | fonts[4] = try rl.loadFont("resources/text/fonts/romulus.png"); 26 | fonts[5] = try rl.loadFont("resources/text/fonts/pixantiqua.png"); 27 | fonts[6] = try rl.loadFont("resources/text/fonts/alpha_beta.png"); 28 | fonts[7] = try rl.loadFont("resources/text/fonts/jupiter_crash.png"); 29 | 30 | // Fonts unloading 31 | defer for (fonts) |font| { 32 | rl.unloadFont(font); 33 | }; 34 | 35 | const messages = [MAX_FONTS][:0]const u8{ 36 | "ALAGARD FONT designed by Hewett Tsoi", 37 | "PIXELPLAY FONT designed by Aleksander Shevchuk", 38 | "MECHA FONT designed by Captain Falcon", 39 | "SETBACK FONT designed by Brian Kent (AEnigma)", 40 | "ROMULUS FONT designed by Hewett Tsoi", 41 | "PIXANTIQUA FONT designed by Gerhard Grossmann", 42 | "ALPHA_BETA FONT designed by Brian Kent (AEnigma)", 43 | "JUPITER_CRASH FONT designed by Brian Kent (AEnigma)", 44 | }; 45 | 46 | const spacings = [_]i32{ 2, 4, 8, 4, 3, 4, 4, 1 }; 47 | 48 | var positions: [MAX_FONTS]rl.Vector2 = undefined; 49 | for (0..MAX_FONTS) |i| { 50 | const font_base_size = @as(f32, @floatFromInt(fonts[i].baseSize)); 51 | positions[i].x = screenWidth / 2.0 - rl.measureTextEx(fonts[i], messages[i], font_base_size * 2.0, @floatFromInt(spacings[i])).x / 2.0; 52 | positions[i].y = 60.0 + font_base_size + 45.0 * @as(f32, @floatFromInt(i)); 53 | } 54 | 55 | // Small Y position corrections 56 | positions[3].y += 8; 57 | positions[4].y += 2; 58 | positions[7].y -= 8; 59 | 60 | const colors = [MAX_FONTS]Color{ Color.maroon, Color.orange, Color.dark_green, Color.dark_blue, Color.dark_purple, Color.lime, Color.gold, Color.red }; 61 | 62 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 63 | //-------------------------------------------------------------------------------------- 64 | 65 | // Main game loop 66 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 67 | // Update 68 | //---------------------------------------------------------------------------------- 69 | // TODO: Update your variables here 70 | //---------------------------------------------------------------------------------- 71 | 72 | // Draw 73 | //---------------------------------------------------------------------------------- 74 | rl.beginDrawing(); 75 | 76 | rl.clearBackground(Color.white); 77 | 78 | rl.drawText("free fonts included with raylib", 250, 20, 20, Color.dark_gray); 79 | rl.drawLine(220, 50, 590, 50, Color.dark_gray); 80 | 81 | for (0..MAX_FONTS) |i| { 82 | const font_base_size = @as(f32, @floatFromInt(fonts[i].baseSize)); 83 | rl.drawTextEx(fonts[i], messages[i], positions[i], font_base_size * 2.0, @floatFromInt(spacings[i]), colors[i]); 84 | } 85 | 86 | rl.endDrawing(); 87 | //---------------------------------------------------------------------------------- 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /examples/text/text_writing_anim.zig: -------------------------------------------------------------------------------- 1 | const rl = @import("raylib"); 2 | const Color = rl.Color; 3 | 4 | //------------------------------------------------------------------------------------ 5 | // Program main entry point 6 | //------------------------------------------------------------------------------------ 7 | pub fn main() void { 8 | // Initialization 9 | //-------------------------------------------------------------------------------------- 10 | const screenWidth = 800; 11 | const screenHeight = 450; 12 | 13 | rl.initWindow(screenWidth, screenHeight, "raylib [text] example - text writing anim"); 14 | defer rl.closeWindow(); // Close window and OpenGL context 15 | 16 | const message = "This sample illustrates a text writing\nanimation effect! Check it out! ;)"; 17 | 18 | var framesCounter: i32 = 0; 19 | 20 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 21 | //-------------------------------------------------------------------------------------- 22 | 23 | // Main game loop 24 | while (!rl.windowShouldClose()) // Detect window close button or ESC key 25 | { 26 | // Update 27 | //---------------------------------------------------------------------------------- 28 | framesCounter += if (rl.isKeyDown(.space)) 8 else 1; 29 | 30 | if (rl.isKeyPressed(.enter)) framesCounter = 0; 31 | //---------------------------------------------------------------------------------- 32 | // Draw 33 | //---------------------------------------------------------------------------------- 34 | rl.beginDrawing(); 35 | 36 | rl.clearBackground(Color.white); 37 | 38 | rl.drawText(rl.textSubtext(message, 0, @divFloor(framesCounter, 10)), 210, 160, 20, Color.maroon); 39 | 40 | rl.drawText("PRESS [ENTER] to RESTART!", 240, 260, 20, Color.light_gray); 41 | rl.drawText("HOLD [SPACE] to SPEED UP!", 239, 300, 20, Color.light_gray); 42 | 43 | rl.endDrawing(); 44 | //---------------------------------------------------------------------------------- 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /examples/textures/sprite_anim.zig: -------------------------------------------------------------------------------- 1 | // Port of https://github.com/raysan5/raylib/blob/master/examples/textures/textures_sprite_anim.c to zig 2 | 3 | const std = @import("std"); 4 | const rl = @import("raylib"); 5 | 6 | const MAX_FRAME_SPEED = 15; 7 | const MIN_FRAME_SPEED = 1; 8 | 9 | pub fn main() anyerror!void { 10 | // Initialization 11 | //-------------------------------------------------------------------------------------- 12 | const screenWidth = 800; 13 | const screenHeight = 450; 14 | 15 | rl.initAudioDevice(); // Initialize audio device 16 | rl.initWindow(screenWidth, screenHeight, "raylib [texture] example - sprite anim"); 17 | defer rl.closeWindow(); // Close window and OpenGL context 18 | 19 | // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) 20 | const scarfy = try rl.Texture.init("resources/textures/scarfy.png"); // Texture loading 21 | defer rl.unloadTexture(scarfy); // Texture unloading 22 | 23 | const position = rl.Vector2.init(350.0, 280.0); 24 | var frameRec = rl.Rectangle.init( 25 | 0, 26 | 0, 27 | @as(f32, @floatFromInt(@divFloor(scarfy.width, 6))), 28 | @as(f32, @floatFromInt(scarfy.height)), 29 | ); 30 | var currentFrame: u8 = 0; 31 | 32 | var framesCounter: u8 = 0; 33 | var framesSpeed: u8 = 8; // Number of spritesheet frames shown by second 34 | 35 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 36 | //-------------------------------------------------------------------------------------- 37 | 38 | // Main game loop 39 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 40 | // Update 41 | //---------------------------------------------------------------------------------- 42 | framesCounter += 1; 43 | 44 | if (framesCounter >= (60 / framesSpeed)) { 45 | framesCounter = 0; 46 | currentFrame += 1; 47 | 48 | if (currentFrame > 5) currentFrame = 0; 49 | 50 | frameRec.x = @as(f32, @floatFromInt(currentFrame)) * @as(f32, @floatFromInt(@divFloor(scarfy.width, 6))); 51 | } 52 | 53 | // Control frames speed 54 | if (rl.isKeyPressed(.right)) { 55 | framesSpeed += 1; 56 | } else if (rl.isKeyPressed(.left)) { 57 | framesSpeed -= 1; 58 | } 59 | 60 | if (framesSpeed > MAX_FRAME_SPEED) { 61 | framesSpeed = MAX_FRAME_SPEED; 62 | } else if (framesSpeed < MIN_FRAME_SPEED) { 63 | framesSpeed = MIN_FRAME_SPEED; 64 | } 65 | 66 | //---------------------------------------------------------------------------------- 67 | 68 | // Draw 69 | //---------------------------------------------------------------------------------- 70 | rl.beginDrawing(); 71 | defer rl.endDrawing(); 72 | 73 | rl.clearBackground(.ray_white); 74 | 75 | rl.drawTexture(scarfy, 15, 40, .white); 76 | rl.drawRectangleLines(15, 40, scarfy.width, scarfy.height, .lime); 77 | rl.drawRectangleLines( 78 | 15 + @as(i32, @intFromFloat(frameRec.x)), 79 | 40 + @as(i32, @intFromFloat(frameRec.y)), 80 | @as(i32, @intFromFloat(frameRec.width)), 81 | @as(i32, @intFromFloat(frameRec.height)), 82 | .red, 83 | ); 84 | 85 | rl.drawText("FRAME SPEED: ", 165, 210, 10, .dark_gray); 86 | rl.drawText(rl.textFormat("%02i FPS", .{framesSpeed}), 575, 210, 10, .dark_gray); 87 | rl.drawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, .dark_gray); 88 | 89 | for ([_]u32{0} ** MAX_FRAME_SPEED, 0..) |_, i| { 90 | if (i < framesSpeed) { 91 | rl.drawRectangle(250 + 21 * @as(i32, @intCast(i)), 205, 20, 20, .red); 92 | } 93 | rl.drawRectangleLines(250 + 21 * @as(i32, @intCast(i)), 205, 20, 20, .maroon); 94 | } 95 | 96 | scarfy.drawRec(frameRec, position, .white); // Draw part of the texture 97 | 98 | rl.drawText( 99 | "(c) Scarfy sprite by Eiden Marsal", 100 | screenWidth - 200, 101 | screenHeight - 20, 102 | 10, 103 | .gray, 104 | ); 105 | //---------------------------------------------------------------------------------- 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /examples/textures/textures_background_scrolling.zig: -------------------------------------------------------------------------------- 1 | //! # raylib-zig [textures] example - background scrolling 2 | //! 3 | //! Example licensed under an unmodified zlib/libpng license, which is an 4 | //! OSI-certified, BSD-like license that allows static linking with closed 5 | //! source software 6 | //! 7 | //! Copyright (c) Nikolas Wipper 2024 8 | 9 | const rl = @import("raylib"); 10 | 11 | const screen_width = 800; 12 | const screen_height = 450; 13 | 14 | pub fn main() anyerror!void { 15 | 16 | // Initialization 17 | //-------------------------------------------------------------------------------------- 18 | rl.initWindow(screen_width, screen_height, "raylib [textures] example - background scrolling"); 19 | defer rl.closeWindow(); // Close window and OpenGL context 20 | 21 | // NOTE: Be careful, background width must be equal or bigger than screen width 22 | // if not, texture should be draw more than two times for scrolling effect 23 | const background = try rl.loadTexture("resources/textures/cyberpunk_street_background.png"); 24 | const midground = try rl.loadTexture("resources/textures/cyberpunk_street_midground.png"); 25 | const foreground = try rl.loadTexture("resources/textures/cyberpunk_street_foreground.png"); 26 | defer rl.unloadTexture(background); // Unload background texture 27 | defer rl.unloadTexture(midground); // Unload midground texture 28 | defer rl.unloadTexture(foreground); // Unload foreground texture 29 | 30 | var scrolling_back: f32 = 0; 31 | var scrolling_mid: f32 = 0; 32 | var scrolling_fore: f32 = 0; 33 | 34 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 35 | //-------------------------------------------------------------------------------------- 36 | 37 | // Main game loop 38 | while (!rl.windowShouldClose()) { // Detect window close button or ESC key 39 | // Update 40 | //---------------------------------------------------------------------------------- 41 | scrolling_back -= 0.1; 42 | scrolling_mid -= 0.5; 43 | scrolling_fore -= 1.0; 44 | 45 | // NOTE: Texture is scaled twice its size, so it sould be considered on scrolling 46 | if (scrolling_back <= @as(f32, @floatFromInt(-background.width * 2))) scrolling_back = 0; 47 | if (scrolling_mid <= @as(f32, @floatFromInt(-midground.width * 2))) scrolling_mid = 0; 48 | if (scrolling_fore <= @as(f32, @floatFromInt(-foreground.width * 2))) scrolling_fore = 0; 49 | //---------------------------------------------------------------------------------- 50 | 51 | // Draw 52 | //---------------------------------------------------------------------------------- 53 | { 54 | rl.beginDrawing(); 55 | defer rl.endDrawing(); 56 | 57 | rl.clearBackground(rl.getColor(0x052c46ff)); 58 | // Draw background image twice 59 | // NOTE: Texture is scaled twice its size 60 | rl.drawTextureEx( 61 | background, 62 | .init(scrolling_back, 20.0), 63 | 0.0, 64 | 2.0, 65 | .white, 66 | ); 67 | rl.drawTextureEx( 68 | background, 69 | .init(@as(f32, @floatFromInt(background.width * 2)) + scrolling_back, 20), 70 | 0.0, 71 | 2.0, 72 | .white, 73 | ); 74 | 75 | // Draw midground image twice 76 | rl.drawTextureEx( 77 | midground, 78 | .init(scrolling_mid, 20.0), 79 | 0.0, 80 | 2.0, 81 | .white, 82 | ); 83 | rl.drawTextureEx( 84 | midground, 85 | .init(@as(f32, @floatFromInt(midground.width * 2)) + scrolling_mid, 20), 86 | 0.0, 87 | 2.0, 88 | .white, 89 | ); 90 | 91 | // Draw foreground image twice 92 | rl.drawTextureEx( 93 | foreground, 94 | .init(scrolling_fore, 70.0), 95 | 0.0, 96 | 2.0, 97 | .white, 98 | ); 99 | rl.drawTextureEx( 100 | foreground, 101 | .init(@as(f32, @floatFromInt(foreground.width * 2)) + scrolling_fore, 70), 102 | 0.0, 103 | 2.0, 104 | .white, 105 | ); 106 | 107 | rl.drawText( 108 | "BACKGROUND SCROLLING & PARALLAX", 109 | 10, 110 | 10, 111 | 20, 112 | .red, 113 | ); 114 | rl.drawText( 115 | "(c) Cyberpunk Street Environment by Luis Zuno (@ansimuz)", 116 | screen_width - 330, 117 | screen_height - 20, 118 | 10, 119 | .ray_white, 120 | ); 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /examples/textures/textures_image_loading.zig: -------------------------------------------------------------------------------- 1 | // raylib-zig (c) Nikolas Wipper 2023 2 | // 3 | // raylib-zig [textures] example - image loading 4 | // 5 | // Example licensed under an unmodified zlib/libpng license, which is an 6 | // OSI-certified, BSD-like license that allows static linking with closed 7 | // source software 8 | 9 | const rl = @import("raylib"); 10 | const Color = rl.Color; 11 | const screenWidth = 800; 12 | const screenHeight = 450; 13 | 14 | //-------------------------------------------------------------------------------------- 15 | // Program entry point 16 | //-------------------------------------------------------------------------------------- 17 | pub fn main() anyerror!void { 18 | //Initialization 19 | //-------------------------------------------------------------------------------------- 20 | rl.initWindow( 21 | screenWidth, 22 | screenHeight, 23 | "raylib [textures] example - image loading", 24 | ); 25 | 26 | // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) 27 | 28 | const image = try rl.loadImage("logo/logo.png"); // Loaded in CPU memory (RAM) 29 | const texture = try rl.loadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM) 30 | // Once image has been converted to texture and uploaded to VRAM, 31 | // it can be unloaded from RAM 32 | rl.unloadImage(image); 33 | 34 | // De-Initialization 35 | //-------------------------------------------------------------------------------------- 36 | defer rl.closeWindow(); // Close window and OpenGL context 37 | defer rl.unloadTexture(texture); // Texture unloading 38 | //-------------------------------------------------------------------------------------- 39 | 40 | rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second 41 | while (!rl.windowShouldClose()) { 42 | // Update 43 | //-------------------------------------------------------------------------------------- 44 | // TODO: Update your variables here 45 | //-------------------------------------------------------------------------------------- 46 | 47 | // Draw 48 | //-------------------------------------------------------------------------------------- 49 | rl.beginDrawing(); 50 | rl.clearBackground(Color.white); 51 | rl.drawTexture( 52 | texture, 53 | screenWidth / 2 - @divFloor(texture.width, 2), 54 | screenHeight / 2 - @divFloor(texture.height, 2), 55 | Color.white, 56 | ); 57 | rl.drawText( 58 | "this IS a texture loaded from an image!", 59 | 300, 60 | 370, 61 | 10, 62 | Color.gray, 63 | ); 64 | rl.endDrawing(); 65 | //-------------------------------------------------------------------------------------- 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /lib/preludes/raygui-ext-prelude.zig: -------------------------------------------------------------------------------- 1 | // raylib-zig (c) Nikolas Wipper 2024 2 | 3 | const rl = @import("raylib-zig"); 4 | const rgui = @import("raygui.zig"); 5 | -------------------------------------------------------------------------------- /lib/preludes/raylib-ext-prelude.zig: -------------------------------------------------------------------------------- 1 | // raylib-zig (c) Nikolas Wipper 2023 2 | 3 | const rl = @import("raylib.zig"); 4 | -------------------------------------------------------------------------------- /lib/preludes/raymath-ext-prelude.zig: -------------------------------------------------------------------------------- 1 | // raylib-zig (c) Nikolas Wipper 2023 2 | 3 | const rl = @import("raylib.zig"); 4 | const rlm = @import("raymath.zig"); 5 | -------------------------------------------------------------------------------- /lib/preludes/raymath-prelude.zig: -------------------------------------------------------------------------------- 1 | // raylib-zig (c) Nikolas Wipper 2023 2 | 3 | const rl = @import("raylib.zig"); 4 | const std = @import("std"); 5 | 6 | pub const cdef = @import("raymath-ext.zig"); 7 | 8 | test { 9 | std.testing.refAllDeclsRecursive(@This()); 10 | } 11 | 12 | const Matrix = rl.Matrix; 13 | const Quaternion = rl.Quaternion; 14 | const Vector2 = rl.Vector2; 15 | const Vector3 = rl.Vector3; 16 | const Vector4 = rl.Vector4; 17 | 18 | pub const float3 = extern struct { 19 | v: [3]f32, 20 | }; 21 | 22 | pub const float16 = extern struct { 23 | v: [16]f32, 24 | }; 25 | -------------------------------------------------------------------------------- /lib/preludes/rlgl-ext-prelude.zig: -------------------------------------------------------------------------------- 1 | // raylib-zig (c) Nikolas Wipper 2024 2 | 3 | const rl = @import("raylib.zig"); 4 | const rlgl = @import("rlgl.zig"); 5 | -------------------------------------------------------------------------------- /lib/preludes/rlgl-prelude.zig: -------------------------------------------------------------------------------- 1 | // raylib-zig (c) Nikolas Wipper 2024 2 | 3 | const rl = @import("raylib.zig"); 4 | const std = @import("std"); 5 | 6 | pub const cdef = @import("rlgl-ext.zig"); 7 | 8 | test { 9 | std.testing.refAllDeclsRecursive(@This()); 10 | } 11 | 12 | const Matrix = rl.Matrix; 13 | 14 | pub const rlVertexBuffer = extern struct { 15 | elementCount: c_int, 16 | vertices: [*c]f32, 17 | texcoords: [*c]f32, 18 | normals: [*c]f32, 19 | colors: [*c]u8, 20 | indices: [*c]c_ushort, 21 | vaoId: c_uint, 22 | vboId: [5]c_uint, 23 | }; 24 | 25 | pub const rlDrawCall = extern struct { 26 | mode: c_int, 27 | vertexCount: c_int, 28 | vertexAlignment: c_int, 29 | textureId: c_uint, 30 | }; 31 | 32 | pub const rlRenderBatch = extern struct { 33 | bufferCount: c_int, 34 | currentBuffer: c_int, 35 | vertexBuffer: [*c]rlVertexBuffer, 36 | draws: [*c]rlDrawCall, 37 | drawCounter: c_int, 38 | currentDepth: f32, 39 | }; 40 | 41 | pub const rlGlVersion = enum(c_int) { 42 | rl_opengl_11 = 1, 43 | rl_opengl_21 = 2, 44 | rl_opengl_33 = 3, 45 | rl_opengl_43 = 4, 46 | rl_opengl_es_20 = 5, 47 | rl_opengl_es_30 = 6, 48 | }; 49 | 50 | pub const rlTraceLogLevel = enum(c_int) { 51 | rl_log_all = 0, 52 | rl_log_trace = 1, 53 | rl_log_debug = 2, 54 | rl_log_info = 3, 55 | rl_log_warning = 4, 56 | rl_log_error = 5, 57 | rl_log_fatal = 6, 58 | rl_log_none = 7, 59 | }; 60 | 61 | pub const rlPixelFormat = enum(c_int) { 62 | rl_pixelformat_uncompressed_grayscale = 1, 63 | rl_pixelformat_uncompressed_gray_alpha = 2, 64 | rl_pixelformat_uncompressed_r5g6b5 = 3, 65 | rl_pixelformat_uncompressed_r8g8b8 = 4, 66 | rl_pixelformat_uncompressed_r5g5b5a1 = 5, 67 | rl_pixelformat_uncompressed_r4g4b4a4 = 6, 68 | rl_pixelformat_uncompressed_r8g8b8a8 = 7, 69 | rl_pixelformat_uncompressed_r32 = 8, 70 | rl_pixelformat_uncompressed_r32g32b32 = 9, 71 | rl_pixelformat_uncompressed_r32g32b32a32 = 10, 72 | rl_pixelformat_uncompressed_r16 = 11, 73 | rl_pixelformat_uncompressed_r16g16b16 = 12, 74 | rl_pixelformat_uncompressed_r16g16b16a16 = 13, 75 | rl_pixelformat_compressed_dxt1_rgb = 14, 76 | rl_pixelformat_compressed_dxt1_rgba = 15, 77 | rl_pixelformat_compressed_dxt3_rgba = 16, 78 | rl_pixelformat_compressed_dxt5_rgba = 17, 79 | rl_pixelformat_compressed_etc1_rgb = 18, 80 | rl_pixelformat_compressed_etc2_rgb = 19, 81 | rl_pixelformat_compressed_etc2_eac_rgba = 20, 82 | rl_pixelformat_compressed_pvrt_rgb = 21, 83 | rl_pixelformat_compressed_pvrt_rgba = 22, 84 | rl_pixelformat_compressed_astc_4x4_rgba = 23, 85 | rl_pixelformat_compressed_astc_8x8_rgba = 24, 86 | }; 87 | 88 | pub const rlTextureFilter = enum(c_int) { 89 | rl_texture_filter_point = 0, 90 | rl_texture_filter_bilinear = 1, 91 | rl_texture_filter_trilinear = 2, 92 | rl_texture_filter_anisotropic_4x = 3, 93 | rl_texture_filter_anisotropic_8x = 4, 94 | rl_texture_filter_anisotropic_16x = 5, 95 | }; 96 | 97 | pub const rlBlendMode = enum(c_int) { 98 | rl_blend_alpha = 0, 99 | rl_blend_additive = 1, 100 | rl_blend_multiplied = 2, 101 | rl_blend_add_colors = 3, 102 | rl_blend_subtract_colors = 4, 103 | rl_blend_alpha_premultiply = 5, 104 | rl_blend_custom = 6, 105 | rl_blend_custom_separate = 7, 106 | }; 107 | 108 | pub const rlShaderLocationIndex = enum(c_uint) { 109 | rl_shader_loc_vertex_position = 0, 110 | rl_shader_loc_vertex_texcoord01 = 1, 111 | rl_shader_loc_vertex_texcoord02 = 2, 112 | rl_shader_loc_vertex_normal = 3, 113 | rl_shader_loc_vertex_tangent = 4, 114 | rl_shader_loc_vertex_color = 5, 115 | rl_shader_loc_matrix_mvp = 6, 116 | rl_shader_loc_matrix_view = 7, 117 | rl_shader_loc_matrix_projection = 8, 118 | rl_shader_loc_matrix_model = 9, 119 | rl_shader_loc_matrix_normal = 10, 120 | rl_shader_loc_vector_view = 11, 121 | rl_shader_loc_color_diffuse = 12, 122 | rl_shader_loc_color_specular = 13, 123 | rl_shader_loc_color_ambient = 14, 124 | rl_shader_loc_map_albedo = 15, 125 | rl_shader_loc_map_metalness = 16, 126 | rl_shader_loc_map_normal = 17, 127 | rl_shader_loc_map_roughness = 18, 128 | rl_shader_loc_map_occlusion = 19, 129 | rl_shader_loc_map_emission = 20, 130 | rl_shader_loc_map_height = 21, 131 | rl_shader_loc_map_cubemap = 22, 132 | rl_shader_loc_map_irradiance = 23, 133 | rl_shader_loc_map_prefilter = 24, 134 | rl_shader_loc_map_brdf = 25, 135 | }; 136 | 137 | pub const rlShaderUniformDataType = enum(c_uint) { 138 | rl_shader_uniform_float = 0, 139 | rl_shader_uniform_vec2 = 1, 140 | rl_shader_uniform_vec3 = 2, 141 | rl_shader_uniform_vec4 = 3, 142 | rl_shader_uniform_int = 4, 143 | rl_shader_uniform_ivec2 = 5, 144 | rl_shader_uniform_ivec3 = 6, 145 | rl_shader_uniform_ivec4 = 7, 146 | rl_shader_uniform_uint = 8, 147 | rl_shader_uniform_uivec2 = 9, 148 | rl_shader_uniform_uivec3 = 10, 149 | rl_shader_uniform_uivec4 = 11, 150 | rl_shader_uniform_sampler2d = 12, 151 | }; 152 | 153 | pub const rlShaderAttributeDataType = enum(c_uint) { 154 | rl_shader_attrib_float = 0, 155 | rl_shader_attrib_vec2 = 1, 156 | rl_shader_attrib_vec3 = 2, 157 | rl_shader_attrib_vec4 = 3, 158 | }; 159 | 160 | pub const rlFramebufferAttachType = enum(c_uint) { 161 | rl_attachment_color_channel0 = 0, 162 | rl_attachment_color_channel1 = 1, 163 | rl_attachment_color_channel2 = 2, 164 | rl_attachment_color_channel3 = 3, 165 | rl_attachment_color_channel4 = 4, 166 | rl_attachment_color_channel5 = 5, 167 | rl_attachment_color_channel6 = 6, 168 | rl_attachment_color_channel7 = 7, 169 | rl_attachment_depth = 100, 170 | rl_attachment_stencil = 200, 171 | }; 172 | 173 | pub const rlFramebufferAttachTextureType = enum(c_uint) { 174 | rl_attachment_cubemap_positive_x = 0, 175 | rl_attachment_cubemap_negative_x = 1, 176 | rl_attachment_cubemap_positive_y = 2, 177 | rl_attachment_cubemap_negative_y = 3, 178 | rl_attachment_cubemap_positive_z = 4, 179 | rl_attachment_cubemap_negative_z = 5, 180 | rl_attachment_texture2d = 100, 181 | rl_attachment_renderbuffer = 200, 182 | }; 183 | 184 | pub const rlCullMode = enum(c_uint) { 185 | rl_cull_face_front = 0, 186 | rl_cull_face_back = 1, 187 | }; 188 | 189 | pub const rl_default_batch_buffer_elements = @as(i32, 8192); 190 | pub const rl_default_batch_buffers = @as(i32, 1); 191 | pub const rl_default_batch_drawcalls = @as(i32, 256); 192 | pub const rl_default_batch_max_texture_units = @as(i32, 4); 193 | pub const rl_max_matrix_stack_size = @as(i32, 32); 194 | pub const rl_max_shader_locations = @as(i32, 32); 195 | pub const rl_cull_distance_near = @as(f64, 0.01); 196 | pub const rl_cull_distance_far = @as(f64, 1000.0); 197 | pub const rl_texture_wrap_s = @as(i32, 0x2802); 198 | pub const rl_texture_wrap_t = @as(i32, 0x2803); 199 | pub const rl_texture_mag_filter = @as(i32, 0x2800); 200 | pub const rl_texture_min_filter = @as(i32, 0x2801); 201 | pub const rl_texture_filter_nearest = @as(i32, 0x2600); 202 | pub const rl_texture_filter_linear = @as(i32, 0x2601); 203 | pub const rl_texture_filter_mip_nearest = @as(i32, 0x2700); 204 | pub const rl_texture_filter_nearest_mip_linear = @as(i32, 0x2702); 205 | pub const rl_texture_filter_linear_mip_nearest = @as(i32, 0x2701); 206 | pub const rl_texture_filter_mip_linear = @as(i32, 0x2703); 207 | pub const rl_texture_filter_anisotropic = @as(i32, 0x3000); 208 | pub const rl_texture_mipmap_bias_ratio = @as(i32, 0x4000); 209 | pub const rl_texture_wrap_repeat = @as(i32, 0x2901); 210 | pub const rl_texture_wrap_clamp = @as(i32, 0x812f); 211 | pub const rl_texture_wrap_mirror_repeat = @as(i32, 0x8370); 212 | pub const rl_texture_wrap_mirror_clamp = @as(i32, 0x8742); 213 | pub const rl_modelview = @as(i32, 0x1700); 214 | pub const rl_projection = @as(i32, 0x1701); 215 | pub const rl_texture = @as(i32, 0x1702); 216 | pub const rl_lines = @as(i32, 0x0001); 217 | pub const rl_triangles = @as(i32, 0x0004); 218 | pub const rl_quads = @as(i32, 0x0007); 219 | pub const rl_unsigned_byte = @as(i32, 0x1401); 220 | pub const rl_float = @as(i32, 0x1406); 221 | pub const rl_stream_draw = @as(i32, 0x88e0); 222 | pub const rl_stream_read = @as(i32, 0x88e1); 223 | pub const rl_stream_copy = @as(i32, 0x88e2); 224 | pub const rl_static_draw = @as(i32, 0x88e4); 225 | pub const rl_static_read = @as(i32, 0x88e5); 226 | pub const rl_static_copy = @as(i32, 0x88e6); 227 | pub const rl_dynamic_draw = @as(i32, 0x88e8); 228 | pub const rl_dynamic_read = @as(i32, 0x88e9); 229 | pub const rl_dynamic_copy = @as(i32, 0x88ea); 230 | pub const rl_fragment_shader = @as(i32, 0x8b30); 231 | pub const rl_vertex_shader = @as(i32, 0x8b31); 232 | pub const rl_compute_shader = @as(i32, 0x91b9); 233 | pub const rl_zero = @as(i32, 0); 234 | pub const rl_one = @as(i32, 1); 235 | pub const rl_src_color = @as(i32, 0x0300); 236 | pub const rl_one_minus_src_color = @as(i32, 0x0301); 237 | pub const rl_src_alpha = @as(i32, 0x0302); 238 | pub const rl_one_minus_src_alpha = @as(i32, 0x0303); 239 | pub const rl_dst_alpha = @as(i32, 0x0304); 240 | pub const rl_one_minus_dst_alpha = @as(i32, 0x0305); 241 | pub const rl_dst_color = @as(i32, 0x0306); 242 | pub const rl_one_minus_dst_color = @as(i32, 0x0307); 243 | pub const rl_src_alpha_saturate = @as(i32, 0x0308); 244 | pub const rl_constant_color = @as(i32, 0x8001); 245 | pub const rl_one_minus_constant_color = @as(i32, 0x8002); 246 | pub const rl_constant_alpha = @as(i32, 0x8003); 247 | pub const rl_one_minus_constant_alpha = @as(i32, 0x8004); 248 | pub const rl_func_add = @as(i32, 0x8006); 249 | pub const rl_min = @as(i32, 0x8007); 250 | pub const rl_max = @as(i32, 0x8008); 251 | pub const rl_func_subtract = @as(i32, 0x800a); 252 | pub const rl_func_reverse_subtract = @as(i32, 0x800b); 253 | pub const rl_blend_equation = @as(i32, 0x8009); 254 | pub const rl_blend_equation_rgb = @as(i32, 0x8009); 255 | pub const rl_blend_equation_alpha = @as(i32, 0x883d); 256 | pub const rl_blend_dst_rgb = @as(i32, 0x80c8); 257 | pub const rl_blend_src_rgb = @as(i32, 0x80c9); 258 | pub const rl_blend_dst_alpha = @as(i32, 0x80ca); 259 | pub const rl_blend_src_alpha = @as(i32, 0x80cb); 260 | pub const rl_blend_color = @as(i32, 0x8005); 261 | pub const rl_read_framebuffer = @as(i32, 0x8ca8); 262 | pub const rl_draw_framebuffer = @as(i32, 0x8ca9); 263 | pub const rl_default_shader_attrib_location_position = @as(i32, 0); 264 | pub const rl_default_shader_attrib_location_texcoord = @as(i32, 1); 265 | pub const rl_default_shader_attrib_location_normal = @as(i32, 2); 266 | pub const rl_default_shader_attrib_location_color = @as(i32, 3); 267 | pub const rl_default_shader_attrib_location_tangent = @as(i32, 4); 268 | pub const rl_default_shader_attrib_location_texcoord2 = @as(i32, 5); 269 | pub const rl_default_shader_attrib_location_indices = @as(i32, 6); 270 | pub const rl_default_shader_attrib_location_boneids = @as(i32, 7); 271 | pub const rl_default_shader_attrib_location_boneweights = @as(i32, 5); 272 | pub const rl_default_shader_attrib_location_instance_tx = @as(i32, 9); 273 | -------------------------------------------------------------------------------- /lib/raygui-ext.zig: -------------------------------------------------------------------------------- 1 | // raylib-zig (c) Nikolas Wipper 2024 2 | 3 | const rl = @import("raylib-zig"); 4 | const rgui = @import("raygui.zig"); 5 | 6 | pub extern "c" fn GuiEnable() void; 7 | pub extern "c" fn GuiDisable() void; 8 | pub extern "c" fn GuiLock() void; 9 | pub extern "c" fn GuiUnlock() void; 10 | pub extern "c" fn GuiIsLocked() bool; 11 | pub extern "c" fn GuiSetAlpha(alpha: f32) void; 12 | pub extern "c" fn GuiSetState(state: c_int) void; 13 | pub extern "c" fn GuiGetState() c_int; 14 | pub extern "c" fn GuiSetFont(font: rl.Font) void; 15 | pub extern "c" fn GuiGetFont() rl.Font; 16 | pub extern "c" fn GuiSetStyle(control: rgui.Control, property: c_int, value: c_int) void; 17 | pub extern "c" fn GuiGetStyle(control: rgui.Control, property: c_int) c_int; 18 | pub extern "c" fn GuiLoadStyle(fileName: [*c]const u8) void; 19 | pub extern "c" fn GuiLoadStyleDefault() void; 20 | pub extern "c" fn GuiEnableTooltip() void; 21 | pub extern "c" fn GuiDisableTooltip() void; 22 | pub extern "c" fn GuiSetTooltip(tooltip: [*c]const u8) void; 23 | pub extern "c" fn GuiIconText(iconId: c_int, text: [*c]const u8) [*c]const u8; 24 | pub extern "c" fn GuiSetIconScale(scale: c_int) void; 25 | pub extern "c" fn GuiGetIcons() [*c]c_uint; 26 | pub extern "c" fn GuiLoadIcons(fileName: [*c]const u8, loadIconsName: bool) [*c][*c]u8; 27 | pub extern "c" fn GuiDrawIcon(iconId: c_int, posX: c_int, posY: c_int, pixelSize: c_int, color: rl.Color) void; 28 | pub extern "c" fn GuiWindowBox(bounds: rl.Rectangle, title: [*c]const u8) c_int; 29 | pub extern "c" fn GuiGroupBox(bounds: rl.Rectangle, text: [*c]const u8) c_int; 30 | pub extern "c" fn GuiLine(bounds: rl.Rectangle, text: [*c]const u8) c_int; 31 | pub extern "c" fn GuiPanel(bounds: rl.Rectangle, text: [*c]const u8) c_int; 32 | pub extern "c" fn GuiTabBar(bounds: rl.Rectangle, text: [*c][*c]const u8, count: c_int, active: [*c]c_int) c_int; 33 | pub extern "c" fn GuiScrollPanel(bounds: rl.Rectangle, text: [*c]const u8, content: rl.Rectangle, scroll: [*c]rl.Vector2, view: [*c]rl.Rectangle) c_int; 34 | pub extern "c" fn GuiLabel(bounds: rl.Rectangle, text: [*c]const u8) c_int; 35 | pub extern "c" fn GuiButton(bounds: rl.Rectangle, text: [*c]const u8) c_int; 36 | pub extern "c" fn GuiLabelButton(bounds: rl.Rectangle, text: [*c]const u8) c_int; 37 | pub extern "c" fn GuiToggle(bounds: rl.Rectangle, text: [*c]const u8, active: [*c]bool) c_int; 38 | pub extern "c" fn GuiToggleGroup(bounds: rl.Rectangle, text: [*c]const u8, active: [*c]c_int) c_int; 39 | pub extern "c" fn GuiToggleSlider(bounds: rl.Rectangle, text: [*c]const u8, active: [*c]c_int) c_int; 40 | pub extern "c" fn GuiCheckBox(bounds: rl.Rectangle, text: [*c]const u8, checked: [*c]bool) c_int; 41 | pub extern "c" fn GuiComboBox(bounds: rl.Rectangle, text: [*c]const u8, active: [*c]c_int) c_int; 42 | pub extern "c" fn GuiDropdownBox(bounds: rl.Rectangle, text: [*c]const u8, active: [*c]c_int, editMode: bool) c_int; 43 | pub extern "c" fn GuiSpinner(bounds: rl.Rectangle, text: [*c]const u8, value: [*c]c_int, minValue: c_int, maxValue: c_int, editMode: bool) c_int; 44 | pub extern "c" fn GuiValueBox(bounds: rl.Rectangle, text: [*c]const u8, value: [*c]c_int, minValue: c_int, maxValue: c_int, editMode: bool) c_int; 45 | pub extern "c" fn GuiValueBoxFloat(bounds: rl.Rectangle, text: [*c]const u8, textValue: [*c]u8, value: [*c]f32, editMode: bool) c_int; 46 | pub extern "c" fn GuiTextBox(bounds: rl.Rectangle, text: [*c]u8, textSize: c_int, editMode: bool) c_int; 47 | pub extern "c" fn GuiSlider(bounds: rl.Rectangle, textLeft: [*c]const u8, textRight: [*c]const u8, value: [*c]f32, minValue: f32, maxValue: f32) c_int; 48 | pub extern "c" fn GuiSliderPro(bounds: rl.Rectangle, textLeft: [*c]const u8, textRight: [*c]const u8, value: [*c]f32, minValue: f32, maxValue: f32, sliderWidth: c_int) c_int; 49 | pub extern "c" fn GuiSliderBar(bounds: rl.Rectangle, textLeft: [*c]const u8, textRight: [*c]const u8, value: [*c]f32, minValue: f32, maxValue: f32) c_int; 50 | pub extern "c" fn GuiProgressBar(bounds: rl.Rectangle, textLeft: [*c]const u8, textRight: [*c]const u8, value: [*c]f32, minValue: f32, maxValue: f32) c_int; 51 | pub extern "c" fn GuiStatusBar(bounds: rl.Rectangle, text: [*c]const u8) c_int; 52 | pub extern "c" fn GuiDummyRec(bounds: rl.Rectangle, text: [*c]const u8) c_int; 53 | pub extern "c" fn GuiGrid(bounds: rl.Rectangle, text: [*c]const u8, spacing: f32, subdivs: c_int, mouseCell: [*c]rl.Vector2) c_int; 54 | pub extern "c" fn GuiListView(bounds: rl.Rectangle, text: [*c]const u8, scrollIndex: [*c]c_int, active: [*c]c_int) c_int; 55 | pub extern "c" fn GuiListViewEx(bounds: rl.Rectangle, text: [*c][*c]const u8, count: c_int, scrollIndex: [*c]c_int, active: [*c]c_int, focus: [*c]c_int) c_int; 56 | pub extern "c" fn GuiMessageBox(bounds: rl.Rectangle, title: [*c]const u8, message: [*c]const u8, buttons: [*c]const u8) c_int; 57 | pub extern "c" fn GuiTextInputBox(bounds: rl.Rectangle, title: [*c]const u8, message: [*c]const u8, buttons: [*c]const u8, text: [*c]u8, textMaxSize: c_int, secretViewActive: [*c]bool) c_int; 58 | pub extern "c" fn GuiColorPicker(bounds: rl.Rectangle, text: [*c]const u8, color: [*c]rl.Color) c_int; 59 | pub extern "c" fn GuiColorPanel(bounds: rl.Rectangle, text: [*c]const u8, color: [*c]rl.Color) c_int; 60 | pub extern "c" fn GuiColorBarAlpha(bounds: rl.Rectangle, text: [*c]const u8, alpha: [*c]f32) c_int; 61 | pub extern "c" fn GuiColorBarHue(bounds: rl.Rectangle, text: [*c]const u8, value: [*c]f32) c_int; 62 | pub extern "c" fn GuiColorPickerHSV(bounds: rl.Rectangle, text: [*c]const u8, colorHsv: [*c]rl.Vector3) c_int; 63 | pub extern "c" fn GuiColorPanelHSV(bounds: rl.Rectangle, text: [*c]const u8, colorHsv: [*c]rl.Vector3) c_int; 64 | -------------------------------------------------------------------------------- /lib/raymath-ext.zig: -------------------------------------------------------------------------------- 1 | // raylib-zig (c) Nikolas Wipper 2023 2 | 3 | const rl = @import("raylib.zig"); 4 | const rlm = @import("raymath.zig"); 5 | 6 | pub extern "c" fn Clamp(value: f32, min: f32, max: f32) f32; 7 | pub extern "c" fn Lerp(start: f32, end: f32, amount: f32) f32; 8 | pub extern "c" fn Normalize(value: f32, start: f32, end: f32) f32; 9 | pub extern "c" fn Remap(value: f32, inputStart: f32, inputEnd: f32, outputStart: f32, outputEnd: f32) f32; 10 | pub extern "c" fn Wrap(value: f32, min: f32, max: f32) f32; 11 | pub extern "c" fn FloatEquals(x: f32, y: f32) c_int; 12 | pub extern "c" fn Vector2Zero() rl.Vector2; 13 | pub extern "c" fn Vector2One() rl.Vector2; 14 | pub extern "c" fn Vector2Add(v1: rl.Vector2, v2: rl.Vector2) rl.Vector2; 15 | pub extern "c" fn Vector2AddValue(v: rl.Vector2, add: f32) rl.Vector2; 16 | pub extern "c" fn Vector2Subtract(v1: rl.Vector2, v2: rl.Vector2) rl.Vector2; 17 | pub extern "c" fn Vector2SubtractValue(v: rl.Vector2, sub: f32) rl.Vector2; 18 | pub extern "c" fn Vector2Length(v: rl.Vector2) f32; 19 | pub extern "c" fn Vector2LengthSqr(v: rl.Vector2) f32; 20 | pub extern "c" fn Vector2DotProduct(v1: rl.Vector2, v2: rl.Vector2) f32; 21 | pub extern "c" fn Vector2CrossProduct(v1: rl.Vector2, v2: rl.Vector2) f32; 22 | pub extern "c" fn Vector2Distance(v1: rl.Vector2, v2: rl.Vector2) f32; 23 | pub extern "c" fn Vector2DistanceSqr(v1: rl.Vector2, v2: rl.Vector2) f32; 24 | pub extern "c" fn Vector2Angle(v1: rl.Vector2, v2: rl.Vector2) f32; 25 | pub extern "c" fn Vector2LineAngle(start: rl.Vector2, end: rl.Vector2) f32; 26 | pub extern "c" fn Vector2Scale(v: rl.Vector2, scale: f32) rl.Vector2; 27 | pub extern "c" fn Vector2Multiply(v1: rl.Vector2, v2: rl.Vector2) rl.Vector2; 28 | pub extern "c" fn Vector2Negate(v: rl.Vector2) rl.Vector2; 29 | pub extern "c" fn Vector2Divide(v1: rl.Vector2, v2: rl.Vector2) rl.Vector2; 30 | pub extern "c" fn Vector2Normalize(v: rl.Vector2) rl.Vector2; 31 | pub extern "c" fn Vector2Transform(v: rl.Vector2, mat: rl.Matrix) rl.Vector2; 32 | pub extern "c" fn Vector2Lerp(v1: rl.Vector2, v2: rl.Vector2, amount: f32) rl.Vector2; 33 | pub extern "c" fn Vector2Reflect(v: rl.Vector2, normal: rl.Vector2) rl.Vector2; 34 | pub extern "c" fn Vector2Min(v1: rl.Vector2, v2: rl.Vector2) rl.Vector2; 35 | pub extern "c" fn Vector2Max(v1: rl.Vector2, v2: rl.Vector2) rl.Vector2; 36 | pub extern "c" fn Vector2Rotate(v: rl.Vector2, angle: f32) rl.Vector2; 37 | pub extern "c" fn Vector2MoveTowards(v: rl.Vector2, target: rl.Vector2, maxDistance: f32) rl.Vector2; 38 | pub extern "c" fn Vector2Invert(v: rl.Vector2) rl.Vector2; 39 | pub extern "c" fn Vector2Clamp(v: rl.Vector2, min: rl.Vector2, max: rl.Vector2) rl.Vector2; 40 | pub extern "c" fn Vector2ClampValue(v: rl.Vector2, min: f32, max: f32) rl.Vector2; 41 | pub extern "c" fn Vector2Equals(p: rl.Vector2, q: rl.Vector2) c_int; 42 | pub extern "c" fn Vector2Refract(v: rl.Vector2, n: rl.Vector2, r: f32) rl.Vector2; 43 | pub extern "c" fn Vector3Zero() rl.Vector3; 44 | pub extern "c" fn Vector3One() rl.Vector3; 45 | pub extern "c" fn Vector3Add(v1: rl.Vector3, v2: rl.Vector3) rl.Vector3; 46 | pub extern "c" fn Vector3AddValue(v: rl.Vector3, add: f32) rl.Vector3; 47 | pub extern "c" fn Vector3Subtract(v1: rl.Vector3, v2: rl.Vector3) rl.Vector3; 48 | pub extern "c" fn Vector3SubtractValue(v: rl.Vector3, sub: f32) rl.Vector3; 49 | pub extern "c" fn Vector3Scale(v: rl.Vector3, scalar: f32) rl.Vector3; 50 | pub extern "c" fn Vector3Multiply(v1: rl.Vector3, v2: rl.Vector3) rl.Vector3; 51 | pub extern "c" fn Vector3CrossProduct(v1: rl.Vector3, v2: rl.Vector3) rl.Vector3; 52 | pub extern "c" fn Vector3Perpendicular(v: rl.Vector3) rl.Vector3; 53 | pub extern "c" fn Vector3Length(v: rl.Vector3) f32; 54 | pub extern "c" fn Vector3LengthSqr(v: rl.Vector3) f32; 55 | pub extern "c" fn Vector3DotProduct(v1: rl.Vector3, v2: rl.Vector3) f32; 56 | pub extern "c" fn Vector3Distance(v1: rl.Vector3, v2: rl.Vector3) f32; 57 | pub extern "c" fn Vector3DistanceSqr(v1: rl.Vector3, v2: rl.Vector3) f32; 58 | pub extern "c" fn Vector3Angle(v1: rl.Vector3, v2: rl.Vector3) f32; 59 | pub extern "c" fn Vector3Negate(v: rl.Vector3) rl.Vector3; 60 | pub extern "c" fn Vector3Divide(v1: rl.Vector3, v2: rl.Vector3) rl.Vector3; 61 | pub extern "c" fn Vector3Normalize(v: rl.Vector3) rl.Vector3; 62 | pub extern "c" fn Vector3Project(v1: rl.Vector3, v2: rl.Vector3) rl.Vector3; 63 | pub extern "c" fn Vector3Reject(v1: rl.Vector3, v2: rl.Vector3) rl.Vector3; 64 | pub extern "c" fn Vector3OrthoNormalize(v1: [*c]rl.Vector3, v2: [*c]rl.Vector3) void; 65 | pub extern "c" fn Vector3Transform(v: rl.Vector3, mat: rl.Matrix) rl.Vector3; 66 | pub extern "c" fn Vector3RotateByQuaternion(v: rl.Vector3, q: rl.Quaternion) rl.Vector3; 67 | pub extern "c" fn Vector3RotateByAxisAngle(v: rl.Vector3, axis: rl.Vector3, angle: f32) rl.Vector3; 68 | pub extern "c" fn Vector3MoveTowards(v: rl.Vector3, target: rl.Vector3, maxDistance: f32) rl.Vector3; 69 | pub extern "c" fn Vector3Lerp(v1: rl.Vector3, v2: rl.Vector3, amount: f32) rl.Vector3; 70 | pub extern "c" fn Vector3CubicHermite(v1: rl.Vector3, tangent1: rl.Vector3, v2: rl.Vector3, tangent2: rl.Vector3, amount: f32) rl.Vector3; 71 | pub extern "c" fn Vector3Reflect(v: rl.Vector3, normal: rl.Vector3) rl.Vector3; 72 | pub extern "c" fn Vector3Min(v1: rl.Vector3, v2: rl.Vector3) rl.Vector3; 73 | pub extern "c" fn Vector3Max(v1: rl.Vector3, v2: rl.Vector3) rl.Vector3; 74 | pub extern "c" fn Vector3Barycenter(p: rl.Vector3, a: rl.Vector3, b: rl.Vector3, c: rl.Vector3) rl.Vector3; 75 | pub extern "c" fn Vector3Unproject(source: rl.Vector3, projection: rl.Matrix, view: rl.Matrix) rl.Vector3; 76 | pub extern "c" fn Vector3ToFloatV(v: rl.Vector3) rlm.float3; 77 | pub extern "c" fn Vector3Invert(v: rl.Vector3) rl.Vector3; 78 | pub extern "c" fn Vector3Clamp(v: rl.Vector3, min: rl.Vector3, max: rl.Vector3) rl.Vector3; 79 | pub extern "c" fn Vector3ClampValue(v: rl.Vector3, min: f32, max: f32) rl.Vector3; 80 | pub extern "c" fn Vector3Equals(p: rl.Vector3, q: rl.Vector3) c_int; 81 | pub extern "c" fn Vector3Refract(v: rl.Vector3, n: rl.Vector3, r: f32) rl.Vector3; 82 | pub extern "c" fn Vector4Zero() rl.Vector4; 83 | pub extern "c" fn Vector4One() rl.Vector4; 84 | pub extern "c" fn Vector4Add(v1: rl.Vector4, v2: rl.Vector4) rl.Vector4; 85 | pub extern "c" fn Vector4AddValue(v: rl.Vector4, add: f32) rl.Vector4; 86 | pub extern "c" fn Vector4Subtract(v1: rl.Vector4, v2: rl.Vector4) rl.Vector4; 87 | pub extern "c" fn Vector4SubtractValue(v: rl.Vector4, add: f32) rl.Vector4; 88 | pub extern "c" fn Vector4Length(v: rl.Vector4) f32; 89 | pub extern "c" fn Vector4LengthSqr(v: rl.Vector4) f32; 90 | pub extern "c" fn Vector4DotProduct(v1: rl.Vector4, v2: rl.Vector4) f32; 91 | pub extern "c" fn Vector4Distance(v1: rl.Vector4, v2: rl.Vector4) f32; 92 | pub extern "c" fn Vector4DistanceSqr(v1: rl.Vector4, v2: rl.Vector4) f32; 93 | pub extern "c" fn Vector4Scale(v: rl.Vector4, scale: f32) rl.Vector4; 94 | pub extern "c" fn Vector4Multiply(v1: rl.Vector4, v2: rl.Vector4) rl.Vector4; 95 | pub extern "c" fn Vector4Negate(v: rl.Vector4) rl.Vector4; 96 | pub extern "c" fn Vector4Divide(v1: rl.Vector4, v2: rl.Vector4) rl.Vector4; 97 | pub extern "c" fn Vector4Normalize(v: rl.Vector4) rl.Vector4; 98 | pub extern "c" fn Vector4Min(v1: rl.Vector4, v2: rl.Vector4) rl.Vector4; 99 | pub extern "c" fn Vector4Max(v1: rl.Vector4, v2: rl.Vector4) rl.Vector4; 100 | pub extern "c" fn Vector4Lerp(v1: rl.Vector4, v2: rl.Vector4, amount: f32) rl.Vector4; 101 | pub extern "c" fn Vector4MoveTowards(v: rl.Vector4, target: rl.Vector4, maxDistance: f32) rl.Vector4; 102 | pub extern "c" fn Vector4Invert(v: rl.Vector4) rl.Vector4; 103 | pub extern "c" fn Vector4Equals(p: rl.Vector4, q: rl.Vector4) c_int; 104 | pub extern "c" fn MatrixDeterminant(mat: rl.Matrix) f32; 105 | pub extern "c" fn MatrixTrace(mat: rl.Matrix) f32; 106 | pub extern "c" fn MatrixTranspose(mat: rl.Matrix) rl.Matrix; 107 | pub extern "c" fn MatrixInvert(mat: rl.Matrix) rl.Matrix; 108 | pub extern "c" fn MatrixIdentity() rl.Matrix; 109 | pub extern "c" fn MatrixAdd(left: rl.Matrix, right: rl.Matrix) rl.Matrix; 110 | pub extern "c" fn MatrixSubtract(left: rl.Matrix, right: rl.Matrix) rl.Matrix; 111 | pub extern "c" fn MatrixMultiply(left: rl.Matrix, right: rl.Matrix) rl.Matrix; 112 | pub extern "c" fn MatrixTranslate(x: f32, y: f32, z: f32) rl.Matrix; 113 | pub extern "c" fn MatrixRotate(axis: rl.Vector3, angle: f32) rl.Matrix; 114 | pub extern "c" fn MatrixRotateX(angle: f32) rl.Matrix; 115 | pub extern "c" fn MatrixRotateY(angle: f32) rl.Matrix; 116 | pub extern "c" fn MatrixRotateZ(angle: f32) rl.Matrix; 117 | pub extern "c" fn MatrixRotateXYZ(angle: rl.Vector3) rl.Matrix; 118 | pub extern "c" fn MatrixRotateZYX(angle: rl.Vector3) rl.Matrix; 119 | pub extern "c" fn MatrixScale(x: f32, y: f32, z: f32) rl.Matrix; 120 | pub extern "c" fn MatrixFrustum(left: f64, right: f64, bottom: f64, top: f64, nearPlane: f64, farPlane: f64) rl.Matrix; 121 | pub extern "c" fn MatrixPerspective(fovY: f64, aspect: f64, nearPlane: f64, farPlane: f64) rl.Matrix; 122 | pub extern "c" fn MatrixOrtho(left: f64, right: f64, bottom: f64, top: f64, nearPlane: f64, farPlane: f64) rl.Matrix; 123 | pub extern "c" fn MatrixLookAt(eye: rl.Vector3, target: rl.Vector3, up: rl.Vector3) rl.Matrix; 124 | pub extern "c" fn MatrixToFloatV(mat: rl.Matrix) rlm.float16; 125 | pub extern "c" fn QuaternionAdd(q1: rl.Quaternion, q2: rl.Quaternion) rl.Quaternion; 126 | pub extern "c" fn QuaternionAddValue(q: rl.Quaternion, add: f32) rl.Quaternion; 127 | pub extern "c" fn QuaternionSubtract(q1: rl.Quaternion, q2: rl.Quaternion) rl.Quaternion; 128 | pub extern "c" fn QuaternionSubtractValue(q: rl.Quaternion, sub: f32) rl.Quaternion; 129 | pub extern "c" fn QuaternionIdentity() rl.Quaternion; 130 | pub extern "c" fn QuaternionLength(q: rl.Quaternion) f32; 131 | pub extern "c" fn QuaternionNormalize(q: rl.Quaternion) rl.Quaternion; 132 | pub extern "c" fn QuaternionInvert(q: rl.Quaternion) rl.Quaternion; 133 | pub extern "c" fn QuaternionMultiply(q1: rl.Quaternion, q2: rl.Quaternion) rl.Quaternion; 134 | pub extern "c" fn QuaternionScale(q: rl.Quaternion, mul: f32) rl.Quaternion; 135 | pub extern "c" fn QuaternionDivide(q1: rl.Quaternion, q2: rl.Quaternion) rl.Quaternion; 136 | pub extern "c" fn QuaternionLerp(q1: rl.Quaternion, q2: rl.Quaternion, amount: f32) rl.Quaternion; 137 | pub extern "c" fn QuaternionNlerp(q1: rl.Quaternion, q2: rl.Quaternion, amount: f32) rl.Quaternion; 138 | pub extern "c" fn QuaternionSlerp(q1: rl.Quaternion, q2: rl.Quaternion, amount: f32) rl.Quaternion; 139 | pub extern "c" fn QuaternionCubicHermiteSpline(q1: rl.Quaternion, outTangent1: rl.Quaternion, q2: rl.Quaternion, inTangent2: rl.Quaternion, t: f32) rl.Quaternion; 140 | pub extern "c" fn QuaternionFromVector3ToVector3(from: rl.Vector3, to: rl.Vector3) rl.Quaternion; 141 | pub extern "c" fn QuaternionFromMatrix(mat: rl.Matrix) rl.Quaternion; 142 | pub extern "c" fn QuaternionToMatrix(q: rl.Quaternion) rl.Matrix; 143 | pub extern "c" fn QuaternionFromAxisAngle(axis: rl.Vector3, angle: f32) rl.Quaternion; 144 | pub extern "c" fn QuaternionToAxisAngle(q: rl.Quaternion, outAxis: [*c]rl.Vector3, outAngle: [*c]f32) void; 145 | pub extern "c" fn QuaternionFromEuler(pitch: f32, yaw: f32, roll: f32) rl.Quaternion; 146 | pub extern "c" fn QuaternionToEuler(q: rl.Quaternion) rl.Vector3; 147 | pub extern "c" fn QuaternionTransform(q: rl.Quaternion, mat: rl.Matrix) rl.Quaternion; 148 | pub extern "c" fn QuaternionEquals(p: rl.Quaternion, q: rl.Quaternion) c_int; 149 | pub extern "c" fn MatrixDecompose(mat: rl.Matrix, translation: [*c]rl.Vector3, rotation: [*c]rl.Quaternion, scale: [*c]rl.Vector3) void; 150 | -------------------------------------------------------------------------------- /lib/rlgl-ext.zig: -------------------------------------------------------------------------------- 1 | // raylib-zig (c) Nikolas Wipper 2024 2 | 3 | const rl = @import("raylib.zig"); 4 | const rlgl = @import("rlgl.zig"); 5 | 6 | pub extern "c" fn rlMatrixMode(mode: c_int) void; 7 | pub extern "c" fn rlPushMatrix() void; 8 | pub extern "c" fn rlPopMatrix() void; 9 | pub extern "c" fn rlLoadIdentity() void; 10 | pub extern "c" fn rlTranslatef(x: f32, y: f32, z: f32) void; 11 | pub extern "c" fn rlRotatef(angle: f32, x: f32, y: f32, z: f32) void; 12 | pub extern "c" fn rlScalef(x: f32, y: f32, z: f32) void; 13 | pub extern "c" fn rlMultMatrixf(matf: [*c]const f32) void; 14 | pub extern "c" fn rlFrustum(left: f64, right: f64, bottom: f64, top: f64, znear: f64, zfar: f64) void; 15 | pub extern "c" fn rlOrtho(left: f64, right: f64, bottom: f64, top: f64, znear: f64, zfar: f64) void; 16 | pub extern "c" fn rlViewport(x: c_int, y: c_int, width: c_int, height: c_int) void; 17 | pub extern "c" fn rlSetClipPlanes(nearPlane: f64, farPlane: f64) void; 18 | pub extern "c" fn rlGetCullDistanceNear() f64; 19 | pub extern "c" fn rlGetCullDistanceFar() f64; 20 | pub extern "c" fn rlBegin(mode: c_int) void; 21 | pub extern "c" fn rlEnd() void; 22 | pub extern "c" fn rlVertex2i(x: c_int, y: c_int) void; 23 | pub extern "c" fn rlVertex2f(x: f32, y: f32) void; 24 | pub extern "c" fn rlVertex3f(x: f32, y: f32, z: f32) void; 25 | pub extern "c" fn rlTexCoord2f(x: f32, y: f32) void; 26 | pub extern "c" fn rlNormal3f(x: f32, y: f32, z: f32) void; 27 | pub extern "c" fn rlColor4ub(r: u8, g: u8, b: u8, a: u8) void; 28 | pub extern "c" fn rlColor3f(x: f32, y: f32, z: f32) void; 29 | pub extern "c" fn rlColor4f(x: f32, y: f32, z: f32, w: f32) void; 30 | pub extern "c" fn rlEnableVertexArray(vaoId: c_uint) bool; 31 | pub extern "c" fn rlDisableVertexArray() void; 32 | pub extern "c" fn rlEnableVertexBuffer(id: c_uint) void; 33 | pub extern "c" fn rlDisableVertexBuffer() void; 34 | pub extern "c" fn rlEnableVertexBufferElement(id: c_uint) void; 35 | pub extern "c" fn rlDisableVertexBufferElement() void; 36 | pub extern "c" fn rlEnableVertexAttribute(index: c_uint) void; 37 | pub extern "c" fn rlDisableVertexAttribute(index: c_uint) void; 38 | pub extern "c" fn rlEnableStatePointer(vertexAttribType: c_int, buffer: ?*anyopaque) void; 39 | pub extern "c" fn rlDisableStatePointer(vertexAttribType: c_int) void; 40 | pub extern "c" fn rlActiveTextureSlot(slot: c_int) void; 41 | pub extern "c" fn rlEnableTexture(id: c_uint) void; 42 | pub extern "c" fn rlDisableTexture() void; 43 | pub extern "c" fn rlEnableTextureCubemap(id: c_uint) void; 44 | pub extern "c" fn rlDisableTextureCubemap() void; 45 | pub extern "c" fn rlTextureParameters(id: c_uint, param: c_int, value: c_int) void; 46 | pub extern "c" fn rlCubemapParameters(id: c_uint, param: c_int, value: c_int) void; 47 | pub extern "c" fn rlEnableShader(id: c_uint) void; 48 | pub extern "c" fn rlDisableShader() void; 49 | pub extern "c" fn rlEnableFramebuffer(id: c_uint) void; 50 | pub extern "c" fn rlDisableFramebuffer() void; 51 | pub extern "c" fn rlGetActiveFramebuffer() c_uint; 52 | pub extern "c" fn rlActiveDrawBuffers(count: c_int) void; 53 | pub extern "c" fn rlBlitFramebuffer(srcX: c_int, srcY: c_int, srcWidth: c_int, srcHeight: c_int, dstX: c_int, dstY: c_int, dstWidth: c_int, dstHeight: c_int, bufferMask: c_int) void; 54 | pub extern "c" fn rlBindFramebuffer(target: c_uint, framebuffer: c_uint) void; 55 | pub extern "c" fn rlEnableColorBlend() void; 56 | pub extern "c" fn rlDisableColorBlend() void; 57 | pub extern "c" fn rlEnableDepthTest() void; 58 | pub extern "c" fn rlDisableDepthTest() void; 59 | pub extern "c" fn rlEnableDepthMask() void; 60 | pub extern "c" fn rlDisableDepthMask() void; 61 | pub extern "c" fn rlEnableBackfaceCulling() void; 62 | pub extern "c" fn rlDisableBackfaceCulling() void; 63 | pub extern "c" fn rlColorMask(r: bool, g: bool, b: bool, a: bool) void; 64 | pub extern "c" fn rlSetCullFace(mode: c_int) void; 65 | pub extern "c" fn rlEnableScissorTest() void; 66 | pub extern "c" fn rlDisableScissorTest() void; 67 | pub extern "c" fn rlScissor(x: c_int, y: c_int, width: c_int, height: c_int) void; 68 | pub extern "c" fn rlEnablePointMode() void; 69 | pub extern "c" fn rlDisablePointMode() void; 70 | pub extern "c" fn rlEnableWireMode() void; 71 | pub extern "c" fn rlDisableWireMode() void; 72 | pub extern "c" fn rlSetLineWidth(width: f32) void; 73 | pub extern "c" fn rlGetLineWidth() f32; 74 | pub extern "c" fn rlEnableSmoothLines() void; 75 | pub extern "c" fn rlDisableSmoothLines() void; 76 | pub extern "c" fn rlEnableStereoRender() void; 77 | pub extern "c" fn rlDisableStereoRender() void; 78 | pub extern "c" fn rlIsStereoRenderEnabled() bool; 79 | pub extern "c" fn rlClearColor(r: u8, g: u8, b: u8, a: u8) void; 80 | pub extern "c" fn rlClearScreenBuffers() void; 81 | pub extern "c" fn rlCheckErrors() void; 82 | pub extern "c" fn rlSetBlendMode(mode: c_int) void; 83 | pub extern "c" fn rlSetBlendFactors(glSrcFactor: c_int, glDstFactor: c_int, glEquation: c_int) void; 84 | pub extern "c" fn rlSetBlendFactorsSeparate(glSrcRGB: c_int, glDstRGB: c_int, glSrcAlpha: c_int, glDstAlpha: c_int, glEqRGB: c_int, glEqAlpha: c_int) void; 85 | pub extern "c" fn rlglInit(width: c_int, height: c_int) void; 86 | pub extern "c" fn rlglClose() void; 87 | pub extern "c" fn rlLoadExtensions(loader: *anyopaque) void; 88 | pub extern "c" fn rlGetVersion() c_int; 89 | pub extern "c" fn rlSetFramebufferWidth(width: c_int) void; 90 | pub extern "c" fn rlGetFramebufferWidth() c_int; 91 | pub extern "c" fn rlSetFramebufferHeight(height: c_int) void; 92 | pub extern "c" fn rlGetFramebufferHeight() c_int; 93 | pub extern "c" fn rlGetTextureIdDefault() c_uint; 94 | pub extern "c" fn rlGetShaderIdDefault() c_uint; 95 | pub extern "c" fn rlGetShaderLocsDefault() [*c]c_int; 96 | pub extern "c" fn rlLoadRenderBatch(numBuffers: c_int, bufferElements: c_int) rlgl.rlRenderBatch; 97 | pub extern "c" fn rlUnloadRenderBatch(batch: rlgl.rlRenderBatch) void; 98 | pub extern "c" fn rlDrawRenderBatch(batch: [*c]rlgl.rlRenderBatch) void; 99 | pub extern "c" fn rlSetRenderBatchActive(batch: [*c]rlgl.rlRenderBatch) void; 100 | pub extern "c" fn rlDrawRenderBatchActive() void; 101 | pub extern "c" fn rlCheckRenderBatchLimit(vCount: c_int) bool; 102 | pub extern "c" fn rlSetTexture(id: c_uint) void; 103 | pub extern "c" fn rlLoadVertexArray() c_uint; 104 | pub extern "c" fn rlLoadVertexBuffer(buffer: *const anyopaque, size: c_int, dynamic: bool) c_uint; 105 | pub extern "c" fn rlLoadVertexBufferElement(buffer: *const anyopaque, size: c_int, dynamic: bool) c_uint; 106 | pub extern "c" fn rlUpdateVertexBuffer(bufferId: c_uint, data: *const anyopaque, dataSize: c_int, offset: c_int) void; 107 | pub extern "c" fn rlUpdateVertexBufferElements(id: c_uint, data: *const anyopaque, dataSize: c_int, offset: c_int) void; 108 | pub extern "c" fn rlUnloadVertexArray(vaoId: c_uint) void; 109 | pub extern "c" fn rlUnloadVertexBuffer(vboId: c_uint) void; 110 | pub extern "c" fn rlSetVertexAttribute(index: c_uint, compSize: c_int, ty: c_int, normalized: bool, stride: c_int, offset: c_int) void; 111 | pub extern "c" fn rlSetVertexAttributeDivisor(index: c_uint, divisor: c_int) void; 112 | pub extern "c" fn rlSetVertexAttributeDefault(locIndex: c_int, value: *const anyopaque, attribType: c_int, count: c_int) void; 113 | pub extern "c" fn rlDrawVertexArray(offset: c_int, count: c_int) void; 114 | pub extern "c" fn rlDrawVertexArrayElements(offset: c_int, count: c_int, buffer: ?*const anyopaque) void; 115 | pub extern "c" fn rlDrawVertexArrayInstanced(offset: c_int, count: c_int, instances: c_int) void; 116 | pub extern "c" fn rlDrawVertexArrayElementsInstanced(offset: c_int, count: c_int, buffer: ?*const anyopaque, instances: c_int) void; 117 | pub extern "c" fn rlLoadTexture(data: ?*const anyopaque, width: c_int, height: c_int, format: c_int, mipmapCount: c_int) c_uint; 118 | pub extern "c" fn rlLoadTextureDepth(width: c_int, height: c_int, useRenderBuffer: bool) c_uint; 119 | pub extern "c" fn rlLoadTextureCubemap(data: ?*const anyopaque, size: c_int, format: c_int, mipmapCount: c_int) c_uint; 120 | pub extern "c" fn rlUpdateTexture(id: c_uint, offsetX: c_int, offsetY: c_int, width: c_int, height: c_int, format: c_int, data: *const anyopaque) void; 121 | pub extern "c" fn rlGetGlTextureFormats(format: c_int, glInternalFormat: [*c]c_uint, glFormat: [*c]c_uint, glType: [*c]c_uint) void; 122 | pub extern "c" fn rlGetPixelFormatName(format: c_uint) [*c]const u8; 123 | pub extern "c" fn rlUnloadTexture(id: c_uint) void; 124 | pub extern "c" fn rlGenTextureMipmaps(id: c_uint, width: c_int, height: c_int, format: c_int, mipmaps: [*c]c_int) void; 125 | pub extern "c" fn rlReadTexturePixels(id: c_uint, width: c_int, height: c_int, format: c_int) *anyopaque; 126 | pub extern "c" fn rlReadScreenPixels(width: c_int, height: c_int) [*c]u8; 127 | pub extern "c" fn rlLoadFramebuffer() c_uint; 128 | pub extern "c" fn rlFramebufferAttach(fboId: c_uint, texId: c_uint, attachType: c_int, texType: c_int, mipLevel: c_int) void; 129 | pub extern "c" fn rlFramebufferComplete(id: c_uint) bool; 130 | pub extern "c" fn rlUnloadFramebuffer(id: c_uint) void; 131 | pub extern "c" fn rlLoadShaderCode(vsCode: [*c]const u8, fsCode: [*c]const u8) c_uint; 132 | pub extern "c" fn rlCompileShader(shaderCode: [*c]const u8, ty: c_int) c_uint; 133 | pub extern "c" fn rlLoadShaderProgram(vShaderId: c_uint, fShaderId: c_uint) c_uint; 134 | pub extern "c" fn rlUnloadShaderProgram(id: c_uint) void; 135 | pub extern "c" fn rlGetLocationUniform(shaderId: c_uint, uniformName: [*c]const u8) c_int; 136 | pub extern "c" fn rlGetLocationAttrib(shaderId: c_uint, attribName: [*c]const u8) c_int; 137 | pub extern "c" fn rlSetUniform(locIndex: c_int, value: *const anyopaque, uniformType: c_int, count: c_int) void; 138 | pub extern "c" fn rlSetUniformMatrix(locIndex: c_int, mat: rl.Matrix) void; 139 | pub extern "c" fn rlSetUniformMatrices(locIndex: c_int, mat: [*c]const rl.Matrix, count: c_int) void; 140 | pub extern "c" fn rlSetUniformSampler(locIndex: c_int, textureId: c_uint) void; 141 | pub extern "c" fn rlSetShader(id: c_uint, locs: [*c]c_int) void; 142 | pub extern "c" fn rlLoadComputeShaderProgram(shaderId: c_uint) c_uint; 143 | pub extern "c" fn rlComputeShaderDispatch(groupX: c_uint, groupY: c_uint, groupZ: c_uint) void; 144 | pub extern "c" fn rlLoadShaderBuffer(size: c_uint, data: ?*const anyopaque, usageHint: c_int) c_uint; 145 | pub extern "c" fn rlUnloadShaderBuffer(ssboId: c_uint) void; 146 | pub extern "c" fn rlUpdateShaderBuffer(id: c_uint, data: *const anyopaque, dataSize: c_uint, offset: c_uint) void; 147 | pub extern "c" fn rlBindShaderBuffer(id: c_uint, index: c_uint) void; 148 | pub extern "c" fn rlReadShaderBuffer(id: c_uint, dest: *anyopaque, count: c_uint, offset: c_uint) void; 149 | pub extern "c" fn rlCopyShaderBuffer(destId: c_uint, srcId: c_uint, destOffset: c_uint, srcOffset: c_uint, count: c_uint) void; 150 | pub extern "c" fn rlGetShaderBufferSize(id: c_uint) c_uint; 151 | pub extern "c" fn rlBindImageTexture(id: c_uint, index: c_uint, format: c_int, readonly: bool) void; 152 | pub extern "c" fn rlGetMatrixModelview() rl.Matrix; 153 | pub extern "c" fn rlGetMatrixProjection() rl.Matrix; 154 | pub extern "c" fn rlGetMatrixTransform() rl.Matrix; 155 | pub extern "c" fn rlGetMatrixProjectionStereo(eye: c_int) rl.Matrix; 156 | pub extern "c" fn rlGetMatrixViewOffsetStereo(eye: c_int) rl.Matrix; 157 | pub extern "c" fn rlSetMatrixProjection(proj: rl.Matrix) void; 158 | pub extern "c" fn rlSetMatrixModelview(view: rl.Matrix) void; 159 | pub extern "c" fn rlSetMatrixProjectionStereo(right: rl.Matrix, left: rl.Matrix) void; 160 | pub extern "c" fn rlSetMatrixViewOffsetStereo(right: rl.Matrix, left: rl.Matrix) void; 161 | pub extern "c" fn rlLoadDrawCube() void; 162 | pub extern "c" fn rlLoadDrawQuad() void; 163 | -------------------------------------------------------------------------------- /logo/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Not-Nik/raylib-zig/3bf08a304cfe2baf839705063ff999b8d8bc8c54/logo/logo.png -------------------------------------------------------------------------------- /project_setup.ps1: -------------------------------------------------------------------------------- 1 | if ($args.Count -ne 1) { 2 | $PROJECT_NAME = 'Project' 3 | } else { 4 | $PROJECT_NAME = $args[0] 5 | } 6 | 7 | New-Item -Name $PROJECT_NAME -ItemType Directory -ErrorAction Stop 8 | Set-Location -Path $PROJECT_NAME -ErrorAction Stop 9 | 10 | Write-Output "Generating project files..." 11 | 12 | zig init 13 | Remove-Item "build.zig", "src\root.zig" 14 | 15 | $BUILD_DOT_ZIG = @" 16 | const std = @import("std"); 17 | const rlz = @import("raylib_zig"); 18 | 19 | pub fn build(b: *std.Build) !void { 20 | const target = b.standardTargetOptions(.{}); 21 | const optimize = b.standardOptimizeOption(.{}); 22 | 23 | const raylib_dep = b.dependency("raylib_zig", .{ 24 | .target = target, 25 | .optimize = optimize, 26 | }); 27 | 28 | const raylib = raylib_dep.module("raylib"); 29 | const raylib_artifact = raylib_dep.artifact("raylib"); 30 | 31 | //web exports are completely separate 32 | if (target.query.os_tag == .emscripten) { 33 | const exe_lib = try rlz.emcc.compileForEmscripten(b, "$PROJECT_NAME", "src/main.zig", target, optimize); 34 | 35 | exe_lib.linkLibrary(raylib_artifact); 36 | exe_lib.root_module.addImport("raylib", raylib); 37 | 38 | // Note that raylib itself is not actually added to the exe_lib output file, so it also needs to be linked with emscripten. 39 | const link_step = try rlz.emcc.linkWithEmscripten(b, &[_]*std.Build.Step.Compile{ exe_lib, raylib_artifact }); 40 | //this lets your program access files like "resources/my-image.png": 41 | link_step.addArg("--embed-file"); 42 | link_step.addArg("resources/"); 43 | 44 | b.getInstallStep().dependOn(&link_step.step); 45 | const run_step = try rlz.emcc.emscriptenRunStep(b); 46 | run_step.step.dependOn(&link_step.step); 47 | const run_option = b.step("run", "Run $PROJECT_NAME"); 48 | run_option.dependOn(&run_step.step); 49 | return; 50 | } 51 | 52 | const exe = b.addExecutable(.{ .name = "$PROJECT_NAME", .root_source_file = b.path("src/main.zig"), .optimize = optimize, .target = target }); 53 | 54 | exe.linkLibrary(raylib_artifact); 55 | exe.root_module.addImport("raylib", raylib); 56 | 57 | const run_cmd = b.addRunArtifact(exe); 58 | const run_step = b.step("run", "Run $PROJECT_NAME"); 59 | run_step.dependOn(&run_cmd.step); 60 | 61 | b.installArtifact(exe); 62 | } 63 | "@ 64 | 65 | New-Item -Name "build.zig" -ItemType "file" -Value $BUILD_DOT_ZIG -Force 66 | 67 | zig fetch --save git+https://github.com/Not-Nik/raylib-zig#devel 68 | 69 | New-Item -Name "resources" -ItemType "directory" 70 | New-Item -Name "resources/placeholder.txt" -ItemType "file" -Value "" -Force 71 | 72 | Copy-Item -Path "../examples/core/basic_window.zig" -Destination "src/main.zig" 73 | -------------------------------------------------------------------------------- /project_setup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ "$#" -ne 1 ]; then 4 | PROJECT_NAME='Project' 5 | else 6 | PROJECT_NAME=$1 7 | fi 8 | 9 | mkdir "$PROJECT_NAME" && cd "$PROJECT_NAME" || exit 10 | touch build.zig 11 | echo "Generating project files..." 12 | 13 | zig init 14 | rm build.zig 15 | rm src/root.zig 16 | 17 | echo 'const std = @import("std"); 18 | const rlz = @import("raylib_zig"); 19 | 20 | pub fn build(b: *std.Build) !void { 21 | const target = b.standardTargetOptions(.{}); 22 | const optimize = b.standardOptimizeOption(.{}); 23 | 24 | const raylib_dep = b.dependency("raylib_zig", .{ 25 | .target = target, 26 | .optimize = optimize, 27 | }); 28 | 29 | const raylib = raylib_dep.module("raylib"); 30 | const raylib_artifact = raylib_dep.artifact("raylib"); 31 | 32 | //web exports are completely separate 33 | if (target.query.os_tag == .emscripten) { 34 | const exe_lib = try rlz.emcc.compileForEmscripten(b, "'$PROJECT_NAME'", "src/main.zig", target, optimize); 35 | 36 | exe_lib.linkLibrary(raylib_artifact); 37 | exe_lib.root_module.addImport("raylib", raylib); 38 | 39 | // Note that raylib itself is not actually added to the exe_lib output file, so it also needs to be linked with emscripten. 40 | const link_step = try rlz.emcc.linkWithEmscripten(b, &[_]*std.Build.Step.Compile{ exe_lib, raylib_artifact }); 41 | //this lets your program access files like "resources/my-image.png": 42 | link_step.addArg("--embed-file"); 43 | link_step.addArg("resources/"); 44 | 45 | b.getInstallStep().dependOn(&link_step.step); 46 | const run_step = try rlz.emcc.emscriptenRunStep(b); 47 | run_step.step.dependOn(&link_step.step); 48 | const run_option = b.step("run", "Run '$PROJECT_NAME'"); 49 | run_option.dependOn(&run_step.step); 50 | return; 51 | } 52 | 53 | const exe = b.addExecutable(.{ .name = "'$PROJECT_NAME'", .root_source_file = b.path("src/main.zig"), .optimize = optimize, .target = target }); 54 | 55 | exe.linkLibrary(raylib_artifact); 56 | exe.root_module.addImport("raylib", raylib); 57 | 58 | const run_cmd = b.addRunArtifact(exe); 59 | const run_step = b.step("run", "Run '$PROJECT_NAME'"); 60 | run_step.dependOn(&run_cmd.step); 61 | 62 | b.installArtifact(exe); 63 | }' >> build.zig 64 | 65 | zig fetch --save git+https://github.com/Not-Nik/raylib-zig#devel 66 | 67 | mkdir resources 68 | touch resources/placeholder.txt 69 | 70 | cp ../examples/core/basic_window.zig src/main.zig 71 | -------------------------------------------------------------------------------- /resources/audio/country.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Not-Nik/raylib-zig/3bf08a304cfe2baf839705063ff999b8d8bc8c54/resources/audio/country.mp3 -------------------------------------------------------------------------------- /resources/audio/mini1111.xm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Not-Nik/raylib-zig/3bf08a304cfe2baf839705063ff999b8d8bc8c54/resources/audio/mini1111.xm -------------------------------------------------------------------------------- /resources/audio/sound.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Not-Nik/raylib-zig/3bf08a304cfe2baf839705063ff999b8d8bc8c54/resources/audio/sound.wav -------------------------------------------------------------------------------- /resources/audio/target.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Not-Nik/raylib-zig/3bf08a304cfe2baf839705063ff999b8d8bc8c54/resources/audio/target.ogg -------------------------------------------------------------------------------- /resources/shaders/glsl330/outline.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | uniform vec2 textureSize; 12 | uniform float outlineSize; 13 | uniform vec4 outlineColor; 14 | 15 | // Output fragment color 16 | out vec4 finalColor; 17 | 18 | void main() 19 | { 20 | vec4 texel = texture(texture0, fragTexCoord); // Get texel color 21 | vec2 texelScale = vec2(0.0); 22 | texelScale.x = outlineSize/textureSize.x; 23 | texelScale.y = outlineSize/textureSize.y; 24 | 25 | // We sample four corner texels, but only for the alpha channel (this is for the outline) 26 | vec4 corners = vec4(0.0); 27 | corners.x = texture(texture0, fragTexCoord + vec2(texelScale.x, texelScale.y)).a; 28 | corners.y = texture(texture0, fragTexCoord + vec2(texelScale.x, -texelScale.y)).a; 29 | corners.z = texture(texture0, fragTexCoord + vec2(-texelScale.x, texelScale.y)).a; 30 | corners.w = texture(texture0, fragTexCoord + vec2(-texelScale.x, -texelScale.y)).a; 31 | 32 | float outline = min(dot(corners, vec4(1.0)), 1.0); 33 | vec4 color = mix(vec4(0.0), outlineColor, outline); 34 | finalColor = mix(color, texel, texel.a); 35 | } -------------------------------------------------------------------------------- /resources/text/fonts/alagard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Not-Nik/raylib-zig/3bf08a304cfe2baf839705063ff999b8d8bc8c54/resources/text/fonts/alagard.png -------------------------------------------------------------------------------- /resources/text/fonts/alpha_beta.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Not-Nik/raylib-zig/3bf08a304cfe2baf839705063ff999b8d8bc8c54/resources/text/fonts/alpha_beta.png -------------------------------------------------------------------------------- /resources/text/fonts/jupiter_crash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Not-Nik/raylib-zig/3bf08a304cfe2baf839705063ff999b8d8bc8c54/resources/text/fonts/jupiter_crash.png -------------------------------------------------------------------------------- /resources/text/fonts/mecha.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Not-Nik/raylib-zig/3bf08a304cfe2baf839705063ff999b8d8bc8c54/resources/text/fonts/mecha.png -------------------------------------------------------------------------------- /resources/text/fonts/pixantiqua.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Not-Nik/raylib-zig/3bf08a304cfe2baf839705063ff999b8d8bc8c54/resources/text/fonts/pixantiqua.png -------------------------------------------------------------------------------- /resources/text/fonts/pixelplay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Not-Nik/raylib-zig/3bf08a304cfe2baf839705063ff999b8d8bc8c54/resources/text/fonts/pixelplay.png -------------------------------------------------------------------------------- /resources/text/fonts/romulus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Not-Nik/raylib-zig/3bf08a304cfe2baf839705063ff999b8d8bc8c54/resources/text/fonts/romulus.png -------------------------------------------------------------------------------- /resources/text/fonts/setback.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Not-Nik/raylib-zig/3bf08a304cfe2baf839705063ff999b8d8bc8c54/resources/text/fonts/setback.png -------------------------------------------------------------------------------- /resources/textures/cyberpunk_street_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Not-Nik/raylib-zig/3bf08a304cfe2baf839705063ff999b8d8bc8c54/resources/textures/cyberpunk_street_background.png -------------------------------------------------------------------------------- /resources/textures/cyberpunk_street_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Not-Nik/raylib-zig/3bf08a304cfe2baf839705063ff999b8d8bc8c54/resources/textures/cyberpunk_street_foreground.png -------------------------------------------------------------------------------- /resources/textures/cyberpunk_street_midground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Not-Nik/raylib-zig/3bf08a304cfe2baf839705063ff999b8d8bc8c54/resources/textures/cyberpunk_street_midground.png -------------------------------------------------------------------------------- /resources/textures/fudesumi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Not-Nik/raylib-zig/3bf08a304cfe2baf839705063ff999b8d8bc8c54/resources/textures/fudesumi.png -------------------------------------------------------------------------------- /resources/textures/scarfy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Not-Nik/raylib-zig/3bf08a304cfe2baf839705063ff999b8d8bc8c54/resources/textures/scarfy.png --------------------------------------------------------------------------------