Some work on the examples

This commit is contained in:
Not-Nik 2023-07-09 18:45:15 +02:00
parent ffe8091bc4
commit 42671d0195
No known key found for this signature in database
GPG Key ID: 08BB71E672DB3BFD
14 changed files with 349 additions and 287 deletions

View File

@ -2,11 +2,11 @@
# raylib-zig
Manually tweaked, auto generated [raylib](https://github.com/raysan5/raylib) bindings for zig.
Manually tweaked, auto-generated [raylib](https://github.com/raysan5/raylib) bindings for zig.
Bindings tested on raylib version 4.5.0-dev and Zig 0.10.1
Thanks to @jessrud, @mbcrocci, @franciscod, @AlxHnr, @Gertkeno, @Ivan-Velickovic, @alanoliveira, @rcorre and @sacredbirdman for their contributions to this binding.
Thanks to all the [contributors](https://github.com/Not-Nik/raylib-zig/graphs/contributors) for their help with this binding.
The binding currently only supports a subset of raylib. For more information read [here](#technical-restrictions).

View File

@ -50,6 +50,11 @@ pub fn build(b: *Builder) void {
.path = "examples/core/2d_camera.zig",
.desc = "Shows the functionality of a 2D camera",
},
.{
.name = "3d_camera_first_person",
.path = "examples/core/3d_camera_first_person.zig",
.desc = "Simple first person demo",
},
.{
.name = "sprite_anim",
.path = "examples/textures/sprite_anim.zig",

View File

@ -1,32 +0,0 @@
# Examples
Making raylib bindings in zig is pretty straight forward since zig has a built-in c parser, so I am now on a quest to port all the examples.
### category: core
Examples using raylib core platform functionality like window creation, inputs, drawing modes and system functionality.
| ## | example | developer |
|----|----------|:----------:|
| 01 | [core_basic_window](core/basic_window.zig) | ray
| 02 | [core_input_keys](core/input_keys.zig) | ray
| 04 | [core_input_mouse_wheel](core/input_mouse_wheel.zig) | ray
| 06 | [core_input_multitouch](core/input_multitouch.zig) | [Berni](https://github.com/Berni8k)
| 08 | [core_2d_camera](core/2d_camera.zig) | ray
### category: models
Examples using raylib models functionality, including models loading/generation and drawing, provided by raylib models module.
| ## | example | developer |
|----|----------|:----------:|
| 74 | [models_loading](models/models_loading.zig) | ray
### category: shaders
Examples using raylib shaders functionality, including shaders loading, parameters configuration and drawing using them (model shaders and postprocessing shaders). This
functionality is directly provided by raylib rlgl module.
| ## | example | developer |
|----|----------|:----------:|
| 74 | [shaders_basic_lighting](shaders/shaders_basic_lighting.zig) | [Chris Camacho](https://github.com/codifies)

View File

@ -1,17 +1,11 @@
//
// 2d_camera
// Zig version:
// Author: Nikolas Wipper
// Date: 2020-02-16
//
// raylib-zig (c) Nikolas Wipper 2023
const rl = @import("raylib");
const rlm = @import("raylib-math");
const MAX_BUILDINGS = 100;
pub fn main() anyerror!void
{
pub fn main() anyerror!void {
// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800;
@ -25,8 +19,7 @@ pub fn main() anyerror!void
var spacing: i32 = 0;
for (buildings) |_, i|
{
for (buildings) |_, i| {
buildings[i].width = @intToFloat(f32, rl.GetRandomValue(50, 200));
buildings[i].height = @intToFloat(f32, rl.GetRandomValue(100, 800));
buildings[i].y = screenHeight - 130 - buildings[i].height;
@ -34,8 +27,7 @@ pub fn main() anyerror!void
spacing += @floatToInt(i32, buildings[i].width);
buildColors[i] = rl.Color { .r = @intCast(u8, rl.GetRandomValue(200, 240)), .g = @intCast(u8, rl.GetRandomValue(200, 240)),
.b = @intCast(u8, rl.GetRandomValue(200, 250)), .a = 255 };
buildColors[i] = rl.Color{ .r = @intCast(u8, rl.GetRandomValue(200, 240)), .g = @intCast(u8, rl.GetRandomValue(200, 240)), .b = @intCast(u8, rl.GetRandomValue(200, 250)), .a = 255 };
}
var camera = rl.Camera2D{
@ -49,21 +41,26 @@ pub fn main() anyerror!void
//--------------------------------------------------------------------------------------
// Main game loop
while (!rl.WindowShouldClose()) // Detect window close button or ESC key
{
while (!rl.WindowShouldClose()) { // Detect window close button or ESC key
// Update
//----------------------------------------------------------------------------------
// Player movement
if (rl.IsKeyDown(rl.KeyboardKey.KEY_RIGHT)) { player.x += 2; }
else if (rl.IsKeyDown(rl.KeyboardKey.KEY_LEFT)) { player.x -= 2; }
if (rl.IsKeyDown(rl.KeyboardKey.KEY_RIGHT)) {
player.x += 2;
} else if (rl.IsKeyDown(rl.KeyboardKey.KEY_LEFT)) {
player.x -= 2;
}
// Camera target follows player
camera.target = rl.Vector2{ .x = player.x + 20, .y = player.y + 20 };
// Camera rotation controls
if (rl.IsKeyDown(rl.KeyboardKey.KEY_A)) { camera.rotation -= 1; }
else if (rl.IsKeyDown(rl.KeyboardKey.KEY_S)) { camera.rotation += 1; }
if (rl.IsKeyDown(rl.KeyboardKey.KEY_A)) {
camera.rotation -= 1;
} else if (rl.IsKeyDown(rl.KeyboardKey.KEY_S)) {
camera.rotation += 1;
}
// Limit camera rotation to 80 degrees (-40 to 40)
camera.rotation = rlm.Clamp(camera.rotation, -40, 40);
@ -74,8 +71,7 @@ pub fn main() anyerror!void
camera.zoom = rlm.Clamp(camera.zoom, 0.1, 3.0);
// Camera reset (zoom and rotation)
if (rl.IsKeyPressed(rl.KeyboardKey.KEY_R))
{
if (rl.IsKeyPressed(rl.KeyboardKey.KEY_R)) {
camera.zoom = 1.0;
camera.rotation = 0.0;
}
@ -87,12 +83,11 @@ pub fn main() anyerror!void
rl.ClearBackground(rl.RAYWHITE);
camera.Begin();
camera.begin();
rl.DrawRectangle(-6000, 320, 13000, 8000, rl.DARKGRAY);
for (buildings) |building, i|
{
for (buildings) |building, i| {
rl.DrawRectangleRec(building, buildColors[i]);
}
@ -101,7 +96,7 @@ pub fn main() anyerror!void
rl.DrawLine(@floatToInt(c_int, camera.target.x), -screenHeight * 10, @floatToInt(c_int, camera.target.x), screenHeight * 10, rl.GREEN);
rl.DrawLine(-screenWidth * 10, @floatToInt(c_int, camera.target.y), screenWidth * 10, @floatToInt(c_int, camera.target.y), rl.GREEN);
camera.End();
camera.end();
rl.DrawText("SCREEN AREA", 640, 10, 20, rl.RED);

View File

@ -0,0 +1,83 @@
// raylib-zig (c) Nikolas Wipper 2023
const rl = @import("raylib");
const rlm = @import("raylib-math");
const MAX_COLUMNS = 20;
pub fn main() anyerror!void {
// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800;
const screenHeight = 450;
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - 3d camera first person");
var camera = rl.Camera3D{
.position = rl.Vector3{ .x = 4, .y = 2, .z = 4 },
.target = rl.Vector3{ .x = 0, .y = 1.8, .z = 0 },
.up = rl.Vector3{ .x = 0, .y = 1, .z = 0 },
.fovy = 60,
.projection = rl.CameraProjection.CAMERA_PERSPECTIVE,
};
var heights: [MAX_COLUMNS]f32 = undefined;
var positions: [MAX_COLUMNS]rl.Vector3 = undefined;
var colors: [MAX_COLUMNS]rl.Color = undefined;
for (heights) |_, i| {
heights[i] = @intToFloat(f32, rl.GetRandomValue(1, 12));
positions[i] = rl.Vector3{ .x = @intToFloat(f32, rl.GetRandomValue(-15, 15)), .y = heights[i] / 2.0, .z = @intToFloat(f32, rl.GetRandomValue(-15, 15)) };
colors[i] = rl.Color{ .r = @intCast(u8, rl.GetRandomValue(20, 255)), .g = @intCast(u8, rl.GetRandomValue(10, 55)), .b = 30, .a = 255 };
}
camera.setMode(rl.CameraMode.CAMERA_FIRST_PERSON);
rl.SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!rl.WindowShouldClose()) { // Detect window close button or ESC key
// Update
//----------------------------------------------------------------------------------
camera.update();
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
rl.BeginDrawing();
rl.ClearBackground(rl.RAYWHITE);
camera.begin();
// Draw ground
rl.DrawPlane(rl.Vector3{ .x = 0.0, .y = 0.0, .z = 0.0 }, rl.Vector2{ .x = 32.0, .y = 32.0 }, rl.LIGHTGRAY);
rl.DrawCube(rl.Vector3{ .x = -16.0, .y = 2.5, .z = 0.0 }, 1.0, 5.0, 32.0, rl.BLUE); // Draw a blue wall
rl.DrawCube(rl.Vector3{ .x = 16.0, .y = 2.5, .z = 0.0 }, 1.0, 5.0, 32.0, rl.LIME); // Draw a green wall
rl.DrawCube(rl.Vector3{ .x = 0.0, .y = 2.5, .z = 16.0 }, 32.0, 5.0, 1.0, rl.GOLD); // Draw a yellow wall
// Draw some cubes around
for (heights) |height, i| {
rl.DrawCube(positions[i], 2.0, height, 2.0, colors[i]);
rl.DrawCubeWires(positions[i], 2.0, height, 2.0, rl.MAROON);
}
camera.end();
rl.DrawRectangle(10, 10, 220, 70, rl.Fade(rl.SKYBLUE, 0.5));
rl.DrawRectangleLines(10, 10, 220, 70, rl.BLUE);
rl.DrawText("First person camera default controls:", 20, 20, 10, rl.BLACK);
rl.DrawText("- Move with keys: W, A, S, D", 40, 40, 10, rl.DARKGRAY);
rl.DrawText("- Mouse move to look around", 40, 60, 10, rl.DARKGRAY);
rl.EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
rl.CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}

View File

@ -1,9 +1,4 @@
//
// basic_window
// Zig version: 0.6.0
// Author: Nikolas Wipper
// Date: 2020-02-15
//
// raylib-zig (c) Nikolas Wipper 2023
const rl = @import("raylib");

View File

@ -1,9 +1,4 @@
//
// input_keys
// Zig version:
// Author: Nikolas Wipper
// Date: 2020-02-16
//
// raylib-zig (c) Nikolas Wipper 2023
const rl = @import("raylib");
@ -21,14 +16,22 @@ pub fn main() anyerror!void {
//--------------------------------------------------------------------------------------
// Main game loop
while (!rl.WindowShouldClose()) // Detect window close button or ESC key
{
while (!rl.WindowShouldClose()) { // Detect window close button or ESC key
// Update
//----------------------------------------------------------------------------------
if (rl.IsKeyDown(rl.KeyboardKey.KEY_RIGHT)) { ballPosition.x += 2.0; }
if (rl.IsKeyDown(rl.KeyboardKey.KEY_LEFT)) { ballPosition.x -= 2.0; }
if (rl.IsKeyDown(rl.KeyboardKey.KEY_UP)) { ballPosition.y -= 2.0; }
if (rl.IsKeyDown(rl.KeyboardKey.KEY_DOWN)) { ballPosition.y += 2.0; }
if (rl.IsKeyDown(rl.KeyboardKey.KEY_RIGHT)) {
ballPosition.x += 2.0;
}
if (rl.IsKeyDown(rl.KeyboardKey.KEY_LEFT)) {
ballPosition.x -= 2.0;
}
if (rl.IsKeyDown(rl.KeyboardKey.KEY_UP)) {
ballPosition.y -= 2.0;
}
if (rl.IsKeyDown(rl.KeyboardKey.KEY_DOWN)) {
ballPosition.y += 2.0;
}
//----------------------------------------------------------------------------------
// Draw

View File

@ -1,14 +1,8 @@
//
// input_mouse
// Zig version:
// Author: Nikolas Wipper
// Date: 2020-02-16
//
// raylib-zig (c) Nikolas Wipper 2023
const rl = @import("raylib");
pub fn main() anyerror!void
{
pub fn main() anyerror!void {
// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800;
@ -23,17 +17,20 @@ pub fn main() anyerror!void
//--------------------------------------------------------------------------------------
// Main game loop
while (!rl.WindowShouldClose()) // Detect window close button or ESC key
{
while (!rl.WindowShouldClose()) { // Detect window close button or ESC key
// Update
//----------------------------------------------------------------------------------
ballPosition = rl.GetMousePosition();
ballPosition.x = @intToFloat(f32, rl.GetMouseX());
ballPosition.y = @intToFloat(f32, rl.GetMouseY());
if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_LEFT)) { ballColor = rl.MAROON; }
else if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_MIDDLE)) { ballColor = rl.LIME; }
else if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_RIGHT)) { ballColor = rl.DARKBLUE; }
if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_LEFT)) {
ballColor = rl.MAROON;
} else if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_MIDDLE)) {
ballColor = rl.LIME;
} else if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_RIGHT)) {
ballColor = rl.DARKBLUE;
}
//----------------------------------------------------------------------------------
// Draw
@ -56,4 +53,3 @@ pub fn main() anyerror!void
rl.CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}

View File

@ -1,14 +1,8 @@
//
// input_mouse_wheel
// Zig version:
// Author: Nikolas Wipper
// Date: 2020-02-16
//
// raylib-zig (c) Nikolas Wipper 2023
const rl = @import("raylib");
pub fn main() anyerror!void
{
pub fn main() anyerror!void {
// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800;
@ -23,8 +17,7 @@ pub fn main() anyerror!void
//--------------------------------------------------------------------------------------
// Main game loop
while (!rl.WindowShouldClose()) // Detect window close button or ESC key
{
while (!rl.WindowShouldClose()) { // Detect window close button or ESC key
// Update
//----------------------------------------------------------------------------------
boxPositionY -= (rl.GetMouseWheelMove() * scrollSpeed);
@ -50,4 +43,3 @@ pub fn main() anyerror!void
rl.CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}

View File

@ -1,14 +1,8 @@
//
// input_multitouch
// Zig version:
// Author: Nikolas Wipper
// Date: 2020-02-16
//
// raylib-zig (c) Nikolas Wipper 2023
const rl = @import("raylib");
pub fn main() anyerror!void
{
pub fn main() anyerror!void {
// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800;
@ -26,23 +20,36 @@ pub fn main() anyerror!void
//--------------------------------------------------------------------------------------
// Main game loop
while (!rl.WindowShouldClose()) // Detect window close button or ESC key
{
while (!rl.WindowShouldClose()) { // Detect window close button or ESC key
// Update
//----------------------------------------------------------------------------------
ballPosition = rl.GetMousePosition();
ballColor = rl.BEIGE;
if (rl.IsMouseButtonDown(rl.MouseButton.MOUSE_BUTTON_LEFT)) { ballColor = rl.MAROON; }
if (rl.IsMouseButtonDown(rl.MouseButton.MOUSE_BUTTON_MIDDLE)) { ballColor = rl.LIME; }
if (rl.IsMouseButtonDown(rl.MouseButton.MOUSE_BUTTON_RIGHT)) { ballColor = rl.DARKBLUE; }
if (rl.IsMouseButtonDown(rl.MouseButton.MOUSE_BUTTON_LEFT)) {
ballColor = rl.MAROON;
}
if (rl.IsMouseButtonDown(rl.MouseButton.MOUSE_BUTTON_MIDDLE)) {
ballColor = rl.LIME;
}
if (rl.IsMouseButtonDown(rl.MouseButton.MOUSE_BUTTON_RIGHT)) {
ballColor = rl.DARKBLUE;
}
if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_LEFT)) { touchCounter = 10; }
if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_MIDDLE)) { touchCounter = 10; }
if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_RIGHT)) { touchCounter = 10; }
if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_LEFT)) {
touchCounter = 10;
}
if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_MIDDLE)) {
touchCounter = 10;
}
if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_RIGHT)) {
touchCounter = 10;
}
if (touchCounter > 0) { touchCounter -= 1; }
if (touchCounter > 0) {
touchCounter -= 1;
}
//----------------------------------------------------------------------------------
// Draw
@ -52,12 +59,12 @@ pub fn main() anyerror!void
rl.ClearBackground(rl.RAYWHITE);
const nums = [_]i32{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
for (nums) |i|
{
for (nums) |i| {
touchPosition = rl.GetTouchPosition(i); // Get the touch point
if ((touchPosition.x >= 0) and (touchPosition.y >= 0)) // Make sure point is not (-1,-1) as this means there is no touch for it
{
// Make sure point is not (-1,-1) as this means there is no touch for it
if ((touchPosition.x >= 0) and (touchPosition.y >= 0)) {
// Draw circle and touch index number
rl.DrawCircleV(touchPosition, 34, rl.ORANGE);
rl.DrawText(rl.TextFormat("%d", i), @floatToInt(c_int, touchPosition.x) - 10, @floatToInt(c_int, touchPosition.y) - 70, 40, rl.BLACK);
@ -79,4 +86,3 @@ pub fn main() anyerror!void
rl.CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}

View File

@ -1,6 +1,5 @@
// A raylib port of https://github.com/raysan5/raylib/blob/master/examples/shaders/shaders_texture_outline.c
const rl = @import("raylib");
const std = @import("std");
@ -37,8 +36,7 @@ pub fn main() anyerror!void {
//--------------------------------------------------------------------------------------
// Main game loop
while (!rl.WindowShouldClose()) // Detect window close button or ESC key
{
while (!rl.WindowShouldClose()) { // Detect window close button or ESC key
// Update
//----------------------------------------------------------------------------------
outlineSize += rl.GetMouseWheelMove();

View File

@ -29,14 +29,12 @@ pub fn main() anyerror!void {
//--------------------------------------------------------------------------------------
// Main game loop
while (!rl.WindowShouldClose()) // Detect window close button or ESC key
{
while (!rl.WindowShouldClose()) { // Detect window close button or ESC key
// Update
//----------------------------------------------------------------------------------
framesCounter += 1;
if (framesCounter >= (60/framesSpeed))
{
if (framesCounter >= (60 / framesSpeed)) {
framesCounter = 0;
currentFrame += 1;
@ -46,12 +44,17 @@ pub fn main() anyerror!void {
}
// Control frames speed
if (rl.IsKeyPressed(rl.KeyboardKey.KEY_RIGHT)) {framesSpeed+=1;}
else if (rl.IsKeyPressed(rl.KeyboardKey.KEY_LEFT)) {framesSpeed-=1;}
if (framesSpeed > MAX_FRAME_SPEED) {framesSpeed = MAX_FRAME_SPEED;}
else if (framesSpeed < MIN_FRAME_SPEED) {framesSpeed = MIN_FRAME_SPEED;}
if (rl.IsKeyPressed(rl.KeyboardKey.KEY_RIGHT)) {
framesSpeed += 1;
} else if (rl.IsKeyPressed(rl.KeyboardKey.KEY_LEFT)) {
framesSpeed -= 1;
}
if (framesSpeed > MAX_FRAME_SPEED) {
framesSpeed = MAX_FRAME_SPEED;
} else if (framesSpeed < MIN_FRAME_SPEED) {
framesSpeed = MIN_FRAME_SPEED;
}
//----------------------------------------------------------------------------------
@ -70,7 +73,9 @@ pub fn main() anyerror!void {
rl.DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, rl.DARKGRAY);
for ([_]u32{0} ** MAX_FRAME_SPEED) |_, i| {
if (i < framesSpeed) {rl.DrawRectangle(250 + 21*@intCast(c_int, i), 205, 20, 20, rl.RED);}
if (i < framesSpeed) {
rl.DrawRectangle(250 + 21 * @intCast(c_int, i), 205, 20, 20, rl.RED);
}
rl.DrawRectangleLines(250 + 21 * @intCast(c_int, i), 205, 20, 20, rl.MAROON);
}

View File

@ -93,16 +93,16 @@ pub const Image = extern struct {
return rl.LoadImage(fileName);
}
pub fn initRaw(fileName: [*c]const u8, width: c_int, height: c_int, format: PixelFormat, headerSize: c_int) Image {
return rl.LoadImageRaw(fileName, width, height, format, headerSize);
pub fn initRaw(fileName: *const []u8, width: c_int, height: c_int, format: PixelFormat, headerSize: c_int) Image {
return rl.LoadImageRaw(@as([*c]const u8, fileName), width, height, format, headerSize);
}
pub fn initText(text: [*c]const u8, fontSize: c_int, color: Color) Image {
return rl.ImageText(text, fontSize, color);
pub fn initText(text: *const []u8, fontSize: c_int, color: Color) Image {
return rl.ImageText(@as([*c]const u8, text), fontSize, color);
}
pub fn initTextEx(font: Font, text: [*c]const u8, fontSize: f32, spacing: f32, tint: Color) Image {
return rl.ImageTextEx(font, text, fontSize, spacing, tint);
pub fn initTextEx(font: Font, text: *const []u8, fontSize: f32, spacing: f32, tint: Color) Image {
return rl.ImageTextEx(font, @as([*c]const u8, text), fontSize, spacing, tint);
}
pub fn copy(image: Image) Image {
@ -113,35 +113,35 @@ pub const Image = extern struct {
return rl.ImageFromImage(image, rec);
}
pub fn GenColor(width: c_int, height: c_int, color: Color) Image {
pub fn genColor(width: c_int, height: c_int, color: Color) Image {
return rl.GenImageColor(width, height, color);
}
pub fn GenGradientV(width: c_int, height: c_int, top: Color, bottom: Color) Image {
pub fn genGradientV(width: c_int, height: c_int, top: Color, bottom: Color) Image {
return rl.GenImageGradientV(width, height, top, bottom);
}
pub fn GenGradientH(width: c_int, height: c_int, left: Color, right: Color) Image {
pub fn genGradientH(width: c_int, height: c_int, left: Color, right: Color) Image {
return rl.GenImageGradientH(width, height, left, right);
}
pub fn GenGradientRadial(width: c_int, height: c_int, density: f32, inner: Color, outer: Color) Image {
pub fn genGradientRadial(width: c_int, height: c_int, density: f32, inner: Color, outer: Color) Image {
return rl.GenImageGradientRadial(width, height, density, inner, outer);
}
pub fn GenChecked(width: c_int, height: c_int, checksX: c_int, checksY: c_int, col1: Color, col2: Color) Image {
pub fn genChecked(width: c_int, height: c_int, checksX: c_int, checksY: c_int, col1: Color, col2: Color) Image {
return rl.GenImageChecked(width, height, checksX, checksY, col1, col2);
}
pub fn GenWhiteNoise(width: c_int, height: c_int, factor: f32) Image {
pub fn genWhiteNoise(width: c_int, height: c_int, factor: f32) Image {
return rl.GenImageWhiteNoise(width, height, factor);
}
pub fn GenCellular(width: c_int, height: c_int, tileSize: c_int) Image {
pub fn genCellular(width: c_int, height: c_int, tileSize: c_int) Image {
return rl.GenImageCellular(width, height, tileSize);
}
pub fn UseAsWindowIcon(self: Image) void {
pub fn useAsWindowIcon(self: Image) void {
rl.SetWindowIcon(self);
}
};
@ -161,11 +161,11 @@ pub const RenderTexture = extern struct {
texture: Texture,
depth: Texture,
pub fn Begin(self: RenderTexture2D) void {
pub fn begin(self: RenderTexture2D) void {
rl.BeginTextureMode(self);
}
pub fn End(_: RenderTexture2D) void {
pub fn end(_: RenderTexture2D) void {
rl.EndTextureMode();
}
};
@ -204,23 +204,23 @@ pub const Camera3D = extern struct {
fovy: f32,
projection: CameraProjection,
pub fn Begin(self: Camera3D) void {
pub fn begin(self: Camera3D) void {
rl.BeginMode3D(self);
}
pub fn Update(self: *Camera3D) void {
rl.UpdateCamera(self);
pub fn update(self: *Camera3D) void {
rl.UpdateCamera(@as([*c]Camera3D, self));
}
pub fn GetMatrix(self: Camera3D) Matrix {
pub fn getMatrix(self: Camera3D) Matrix {
return rl.GetCameraMatrix(self);
}
pub fn SetMode(self: Camera3D, mode: CameraMode) void {
pub fn setMode(self: Camera3D, mode: CameraMode) void {
rl.SetCameraMode(self, mode);
}
pub fn End(_: Camera3D) void {
pub fn end(_: Camera3D) void {
rl.EndMode3D();
}
};
@ -232,15 +232,15 @@ pub const Camera2D = extern struct {
rotation: f32,
zoom: f32,
pub fn Begin(self: Camera2D) void {
pub fn begin(self: Camera2D) void {
rl.BeginMode2D(self);
}
pub fn GetMatrix(self: Camera2D) Matrix {
pub fn getMatrix(self: Camera2D) Matrix {
return rl.GetCameraMatrix2D(self);
}
pub fn End(_: Camera2D) void {
pub fn end(_: Camera2D) void {
rl.EndMode2D();
}
};
@ -261,6 +261,14 @@ pub const Mesh = extern struct {
boneWeights: [*c]f32,
vaoId: c_uint,
vboId: [*c]c_uint,
pub fn draw(self: Mesh, material: Material, transform: Matrix) void {
rl.DrawMesh(self, material, transform);
}
pub fn drawInstanced(self: Mesh, material: Material, transforms: []const Matrix) void {
rl.DrawMeshInstanced(self, material, @as([*c]const Matrix, transforms), transforms.len);
}
};
pub const Shader = extern struct {

View File

@ -93,16 +93,16 @@ pub const Image = extern struct {
return rl.LoadImage(fileName);
}
pub fn initRaw(fileName: [*c]const u8, width: c_int, height: c_int, format: PixelFormat, headerSize: c_int) Image {
return rl.LoadImageRaw(fileName, width, height, format, headerSize);
pub fn initRaw(fileName: *const []u8, width: c_int, height: c_int, format: PixelFormat, headerSize: c_int) Image {
return rl.LoadImageRaw(@as([*c]const u8, fileName), width, height, format, headerSize);
}
pub fn initText(text: [*c]const u8, fontSize: c_int, color: Color) Image {
return rl.ImageText(text, fontSize, color);
pub fn initText(text: *const []u8, fontSize: c_int, color: Color) Image {
return rl.ImageText(@as([*c]const u8, text), fontSize, color);
}
pub fn initTextEx(font: Font, text: [*c]const u8, fontSize: f32, spacing: f32, tint: Color) Image {
return rl.ImageTextEx(font, text, fontSize, spacing, tint);
pub fn initTextEx(font: Font, text: *const []u8, fontSize: f32, spacing: f32, tint: Color) Image {
return rl.ImageTextEx(font, @as([*c]const u8, text), fontSize, spacing, tint);
}
pub fn copy(image: Image) Image {
@ -113,35 +113,35 @@ pub const Image = extern struct {
return rl.ImageFromImage(image, rec);
}
pub fn GenColor(width: c_int, height: c_int, color: Color) Image {
pub fn genColor(width: c_int, height: c_int, color: Color) Image {
return rl.GenImageColor(width, height, color);
}
pub fn GenGradientV(width: c_int, height: c_int, top: Color, bottom: Color) Image {
pub fn genGradientV(width: c_int, height: c_int, top: Color, bottom: Color) Image {
return rl.GenImageGradientV(width, height, top, bottom);
}
pub fn GenGradientH(width: c_int, height: c_int, left: Color, right: Color) Image {
pub fn genGradientH(width: c_int, height: c_int, left: Color, right: Color) Image {
return rl.GenImageGradientH(width, height, left, right);
}
pub fn GenGradientRadial(width: c_int, height: c_int, density: f32, inner: Color, outer: Color) Image {
pub fn genGradientRadial(width: c_int, height: c_int, density: f32, inner: Color, outer: Color) Image {
return rl.GenImageGradientRadial(width, height, density, inner, outer);
}
pub fn GenChecked(width: c_int, height: c_int, checksX: c_int, checksY: c_int, col1: Color, col2: Color) Image {
pub fn genChecked(width: c_int, height: c_int, checksX: c_int, checksY: c_int, col1: Color, col2: Color) Image {
return rl.GenImageChecked(width, height, checksX, checksY, col1, col2);
}
pub fn GenWhiteNoise(width: c_int, height: c_int, factor: f32) Image {
pub fn genWhiteNoise(width: c_int, height: c_int, factor: f32) Image {
return rl.GenImageWhiteNoise(width, height, factor);
}
pub fn GenCellular(width: c_int, height: c_int, tileSize: c_int) Image {
pub fn genCellular(width: c_int, height: c_int, tileSize: c_int) Image {
return rl.GenImageCellular(width, height, tileSize);
}
pub fn UseAsWindowIcon(self: Image) void {
pub fn useAsWindowIcon(self: Image) void {
rl.SetWindowIcon(self);
}
};
@ -161,11 +161,11 @@ pub const RenderTexture = extern struct {
texture: Texture,
depth: Texture,
pub fn Begin(self: RenderTexture2D) void {
pub fn begin(self: RenderTexture2D) void {
rl.BeginTextureMode(self);
}
pub fn End(_: RenderTexture2D) void {
pub fn end(_: RenderTexture2D) void {
rl.EndTextureMode();
}
};
@ -204,23 +204,23 @@ pub const Camera3D = extern struct {
fovy: f32,
projection: CameraProjection,
pub fn Begin(self: Camera3D) void {
pub fn begin(self: Camera3D) void {
rl.BeginMode3D(self);
}
pub fn Update(self: *Camera3D) void {
rl.UpdateCamera(self);
pub fn update(self: *Camera3D) void {
rl.UpdateCamera(@as([*c]Camera3D, self));
}
pub fn GetMatrix(self: Camera3D) Matrix {
pub fn getMatrix(self: Camera3D) Matrix {
return rl.GetCameraMatrix(self);
}
pub fn SetMode(self: Camera3D, mode: CameraMode) void {
pub fn setMode(self: Camera3D, mode: CameraMode) void {
rl.SetCameraMode(self, mode);
}
pub fn End(_: Camera3D) void {
pub fn end(_: Camera3D) void {
rl.EndMode3D();
}
};
@ -232,15 +232,15 @@ pub const Camera2D = extern struct {
rotation: f32,
zoom: f32,
pub fn Begin(self: Camera2D) void {
pub fn begin(self: Camera2D) void {
rl.BeginMode2D(self);
}
pub fn GetMatrix(self: Camera2D) Matrix {
pub fn getMatrix(self: Camera2D) Matrix {
return rl.GetCameraMatrix2D(self);
}
pub fn End(_: Camera2D) void {
pub fn end(_: Camera2D) void {
rl.EndMode2D();
}
};
@ -261,6 +261,14 @@ pub const Mesh = extern struct {
boneWeights: [*c]f32,
vaoId: c_uint,
vboId: [*c]c_uint,
pub fn draw(self: Mesh, material: Material, transform: Matrix) void {
rl.DrawMesh(self, material, transform);
}
pub fn drawInstanced(self: Mesh, material: Material, transforms: []const Matrix) void {
rl.DrawMeshInstanced(self, material, @as([*c]const Matrix, transforms), transforms.len);
}
};
pub const Shader = extern struct {