mirror of
https://github.com/Not-Nik/raylib-zig.git
synced 2025-09-09 12:07:27 +00:00
Some work on the examples
This commit is contained in:
parent
ffe8091bc4
commit
42671d0195
@ -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).
|
||||
|
||||
|
@ -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",
|
||||
|
@ -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)
|
@ -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;
|
||||
@ -19,14 +13,13 @@ pub fn main() anyerror!void
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - 2d camera");
|
||||
|
||||
var player = rl.Rectangle { .x = 400, .y = 280, .width = 40, .height = 40 };
|
||||
var player = rl.Rectangle{ .x = 400, .y = 280, .width = 40, .height = 40 };
|
||||
var buildings: [MAX_BUILDINGS]rl.Rectangle = undefined;
|
||||
var buildColors: [MAX_BUILDINGS]rl.Color = undefined;
|
||||
|
||||
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,13 +27,12 @@ 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 {
|
||||
.target = rl.Vector2 { .x = player.x + 20, .y = player.y + 20 },
|
||||
.offset = rl.Vector2 { .x = screenWidth/2, .y = screenHeight/2 },
|
||||
var camera = rl.Camera2D{
|
||||
.target = rl.Vector2{ .x = player.x + 20, .y = player.y + 20 },
|
||||
.offset = rl.Vector2{ .x = screenWidth / 2, .y = screenHeight / 2 },
|
||||
.rotation = 0,
|
||||
.zoom = 1,
|
||||
};
|
||||
@ -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.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,21 +83,20 @@ 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]);
|
||||
}
|
||||
|
||||
rl.DrawRectangleRec(player, rl.RED);
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
@ -110,8 +105,8 @@ pub fn main() anyerror!void
|
||||
rl.DrawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, rl.RED);
|
||||
rl.DrawRectangle(0, screenHeight - 5, screenWidth, 5, rl.RED);
|
||||
|
||||
rl.DrawRectangle( 10, 10, 250, 113, rl.Fade(rl.SKYBLUE, 0.5));
|
||||
rl.DrawRectangleLines( 10, 10, 250, 113, rl.BLUE);
|
||||
rl.DrawRectangle(10, 10, 250, 113, rl.Fade(rl.SKYBLUE, 0.5));
|
||||
rl.DrawRectangleLines(10, 10, 250, 113, rl.BLUE);
|
||||
|
||||
rl.DrawText("Free 2d camera controls:", 20, 20, 10, rl.BLACK);
|
||||
rl.DrawText("- Right/Left to move Offset", 40, 40, 10, rl.DARKGRAY);
|
||||
|
83
examples/core/3d_camera_first_person.zig
Normal file
83
examples/core/3d_camera_first_person.zig
Normal 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
|
||||
//--------------------------------------------------------------------------------------
|
||||
}
|
@ -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");
|
||||
|
||||
|
@ -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");
|
||||
|
||||
@ -15,20 +10,28 @@ pub fn main() anyerror!void {
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - keyboard input");
|
||||
|
||||
var ballPosition = rl.Vector2 { .x = screenWidth/2, .y = screenHeight/2 };
|
||||
var ballPosition = rl.Vector2{ .x = screenWidth / 2, .y = screenHeight / 2 };
|
||||
|
||||
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
|
||||
{
|
||||
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
|
||||
|
@ -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;
|
||||
@ -16,24 +10,27 @@ pub fn main() anyerror!void
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - mouse input");
|
||||
|
||||
var ballPosition = rl.Vector2 { .x = -100.0, .y = -100.0 };
|
||||
var ballPosition = rl.Vector2{ .x = -100.0, .y = -100.0 };
|
||||
var ballColor = rl.DARKBLUE;
|
||||
|
||||
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
|
||||
{
|
||||
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
|
||||
//--------------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
@ -36,7 +29,7 @@ pub fn main() anyerror!void
|
||||
|
||||
rl.ClearBackground(rl.WHITE);
|
||||
|
||||
rl.DrawRectangle(screenWidth/2 - 40, @floatToInt(c_int, boxPositionY), 80, 80, rl.MAROON);
|
||||
rl.DrawRectangle(screenWidth / 2 - 40, @floatToInt(c_int, boxPositionY), 80, 80, rl.MAROON);
|
||||
|
||||
rl.DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, rl.GRAY);
|
||||
rl.DrawText(rl.TextFormat("Box position Y: %03i", @floatToInt(c_int, boxPositionY)), 10, 40, 20, rl.LIGHTGRAY);
|
||||
@ -50,4 +43,3 @@ pub fn main() anyerror!void
|
||||
rl.CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
@ -16,33 +10,46 @@ pub fn main() anyerror!void
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
|
||||
|
||||
var ballPosition = rl.Vector2 { .x = -100.0, .y = -100.0 };
|
||||
var ballPosition = rl.Vector2{ .x = -100.0, .y = -100.0 };
|
||||
var ballColor = rl.BEIGE;
|
||||
|
||||
var touchCounter: f32 = 0;
|
||||
var touchPosition = rl.Vector2 { .x = 0.0, .y = 0.0 };
|
||||
var touchPosition = rl.Vector2{ .x = 0.0, .y = 0.0 };
|
||||
|
||||
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
|
||||
{
|
||||
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
|
||||
@ -51,13 +58,13 @@ 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|
|
||||
{
|
||||
const nums = [_]i32{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
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);
|
||||
@ -65,7 +72,7 @@ pub fn main() anyerror!void
|
||||
}
|
||||
|
||||
// Draw the normal mouse location
|
||||
rl.DrawCircleV(ballPosition, 30 + (touchCounter*3), ballColor);
|
||||
rl.DrawCircleV(ballPosition, 30 + (touchCounter * 3), ballColor);
|
||||
|
||||
rl.DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, rl.DARKGRAY);
|
||||
rl.DrawText("touch the screen at multiple locations to get multiple balls", 10, 30, 20, rl.DARKGRAY);
|
||||
@ -79,4 +86,3 @@ pub fn main() anyerror!void
|
||||
rl.CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
|
||||
@ -21,7 +20,7 @@ pub fn main() anyerror!void {
|
||||
|
||||
var outlineSize: f32 = 2.0;
|
||||
const outlineColor = [4]f32{ 1.0, 0.0, 0.0, 1.0 }; // Normalized RED color
|
||||
const textureSize = rl.Vector2{ .x=@intToFloat(f32, texture.width), .y=@intToFloat(f32,texture.height) };
|
||||
const textureSize = rl.Vector2{ .x = @intToFloat(f32, texture.width), .y = @intToFloat(f32, texture.height) };
|
||||
|
||||
// Get shader locations
|
||||
const outlineSizeLoc = rl.GetShaderLocation(shdrOutline, "outlineSize");
|
||||
@ -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();
|
||||
@ -55,7 +53,7 @@ pub fn main() anyerror!void {
|
||||
|
||||
rl.BeginShaderMode(shdrOutline);
|
||||
|
||||
rl.DrawTexture(texture, @divFloor(rl.GetScreenWidth(),2) - @divFloor(texture.width,2), -30, rl.WHITE);
|
||||
rl.DrawTexture(texture, @divFloor(rl.GetScreenWidth(), 2) - @divFloor(texture.width, 2), -30, rl.WHITE);
|
||||
|
||||
rl.EndShaderMode();
|
||||
|
||||
|
@ -19,39 +19,42 @@ pub fn main() anyerror!void {
|
||||
const scarfy: rl.Texture2D = rl.LoadTexture("resources/textures/scarfy.png"); // Texture loading
|
||||
|
||||
const position = rl.Vector2{ .x = 350.0, .y = 280.0 };
|
||||
var frameRec = rl.Rectangle{ .x = 0.0, .y = 0.0, .width = @intToFloat(f32, @divFloor(scarfy.width,6)), .height = @intToFloat(f32, scarfy.height) };
|
||||
var currentFrame:u8 = 0;
|
||||
var frameRec = rl.Rectangle{ .x = 0.0, .y = 0.0, .width = @intToFloat(f32, @divFloor(scarfy.width, 6)), .height = @intToFloat(f32, scarfy.height) };
|
||||
var currentFrame: u8 = 0;
|
||||
|
||||
var framesCounter:u8 = 0;
|
||||
var framesSpeed:u8 = 8; // Number of spritesheet frames shown by second
|
||||
var framesCounter: u8 = 0;
|
||||
var framesSpeed: u8 = 8; // Number of spritesheet frames shown by second
|
||||
|
||||
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
|
||||
{
|
||||
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;
|
||||
|
||||
if (currentFrame > 5) currentFrame = 0;
|
||||
|
||||
frameRec.x = @intToFloat(f32,currentFrame)*@intToFloat(f32,@divFloor(scarfy.width,6));
|
||||
frameRec.x = @intToFloat(f32, currentFrame) * @intToFloat(f32, @divFloor(scarfy.width, 6));
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
@ -63,15 +66,17 @@ pub fn main() anyerror!void {
|
||||
|
||||
rl.DrawTexture(scarfy, 15, 40, rl.WHITE);
|
||||
rl.DrawRectangleLines(15, 40, scarfy.width, scarfy.height, rl.LIME);
|
||||
rl.DrawRectangleLines(15 + @floatToInt(i32,frameRec.x), 40 + @floatToInt(i32, frameRec.y), @floatToInt(i32,frameRec.width), @floatToInt(i32,frameRec.height), rl.RED);
|
||||
rl.DrawRectangleLines(15 + @floatToInt(i32, frameRec.x), 40 + @floatToInt(i32, frameRec.y), @floatToInt(i32, frameRec.width), @floatToInt(i32, frameRec.height), rl.RED);
|
||||
|
||||
rl.DrawText("FRAME SPEED: ", 165, 210, 10, rl.DARKGRAY);
|
||||
rl.DrawText(rl.TextFormat("%02i FPS", framesSpeed), 575, 210, 10, rl.DARKGRAY);
|
||||
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);}
|
||||
rl.DrawRectangleLines(250 + 21*@intCast(c_int, i), 205, 20, 20, rl.MAROON);
|
||||
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);
|
||||
}
|
||||
|
||||
rl.DrawTextureRec(scarfy, frameRec, position, rl.WHITE); // Draw part of the texture
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user