Unnamed: 0
int64 0
0
| repo_id
stringlengths 5
186
| file_path
stringlengths 15
223
| content
stringlengths 1
32.8M
⌀ |
---|---|---|---|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-38-shapes-following-eyes/main.zig | // build with `zig build-exe main.zig -lc -lraylib`
// This is a Zig version of a raylib example from
// https://github.com/raysan5/raylib/
// It is distributed under the same license as the original - unmodified zlib/libpng license
// Header from the original source code follows below:
///*******************************************************************************************
//*
//* raylib [shapes] example - following eyes
//*
//* Example originally created with raylib 2.5, last time updated with raylib 2.5
//*
//* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
//* BSD-like license that allows static linking with closed source software
//*
//* Copyright (c) 2013-2023 Ramon Santamaria (@raysan5)
//*
//********************************************************************************************/
const std = @import("std"); // fn std.math.atan2()
const builtin = @import("builtin"); // Not the same as std.builtin; zig_version, zig_version_string
const new_atan2 = builtin.zig_version.order(.{ .major = 0, .minor = 12, // comptime is redundant
.patch = 0, .pre = "dev.2139" }) == .gt;
const c = @cImport(
{
@cInclude("raylib.h");
});
pub fn main() void
{
const screen_width = 800;
const screen_height = 450;
c.InitWindow(screen_width, screen_height, "raylib [shapes] example - following eyes");
defer c.CloseWindow(); // Close window and OpenGL context
const sclera_left_pos = c.Vector2{ .x = @as(f32, @floatFromInt(c.GetScreenWidth())) / 2.0 - 100.0,
.y = @as(f32, @floatFromInt(c.GetScreenHeight())) / 2.0 };
const sclera_right_pos = c.Vector2{ .x = @as(f32, @floatFromInt(c.GetScreenWidth())) / 2.0 + 100.0,
.y = @as(f32, @floatFromInt(c.GetScreenHeight())) / 2.0 };
const sclera_radius = 80.0;
var iris_left_pos = c.Vector2{ .x = @as(f32, @floatFromInt(c.GetScreenWidth())) / 2.0 - 100.0,
.y = @as(f32, @floatFromInt(c.GetScreenHeight())) / 2.0 };
var iris_right_pos = c.Vector2{ .x = @as(f32, @floatFromInt(c.GetScreenWidth())) / 2.0 + 100.0,
.y = @as(f32, @floatFromInt(c.GetScreenHeight())) / 2.0 };
const iris_radius = 24.0;
var angle: f32 = 0.0;
var dx: f32 = 0.0;
var dy: f32 = 0.0;
var dxx: f32 = 0.0;
var dyy: f32 = 0.0;
c.SetTargetFPS(60);
while (!c.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
iris_left_pos = c.GetMousePosition();
iris_right_pos = c.GetMousePosition();
// Check not inside the left eye sclera
if (!c.CheckCollisionPointCircle(iris_left_pos, sclera_left_pos, sclera_radius - 20))
{
dx = iris_left_pos.x - sclera_left_pos.x;
dy = iris_left_pos.y - sclera_left_pos.y;
if (new_atan2) { angle = std.math.atan2(dy, dx); }
else { angle = std.math.atan2(f32, dy, dx); }
dxx = (sclera_radius - iris_radius) * @cos(angle);
dyy = (sclera_radius - iris_radius) * @sin(angle);
iris_left_pos.x = sclera_left_pos.x + dxx;
iris_left_pos.y = sclera_left_pos.y + dyy;
}
// Check not inside the right eye sclera
if (!c.CheckCollisionPointCircle(iris_right_pos, sclera_right_pos, sclera_radius - 20))
{
dx = iris_right_pos.x - sclera_right_pos.x;
dy = iris_right_pos.y - sclera_right_pos.y;
if (new_atan2) { angle = std.math.atan2(dy, dx); }
else { angle = std.math.atan2(f32, dy, dx); }
dxx = (sclera_radius - iris_radius) * @cos(angle);
dyy = (sclera_radius - iris_radius) * @sin(angle);
iris_right_pos.x = sclera_right_pos.x + dxx;
iris_right_pos.y = sclera_right_pos.y + dyy;
}
//----------------------------------------------------------------------------------
// Draw
//---------------------------------------------------------------------------------
c.BeginDrawing();
defer c.EndDrawing();
c.ClearBackground(c.RAYWHITE);
c.DrawCircleV(sclera_left_pos, sclera_radius, c.LIGHTGRAY);
c.DrawCircleV(iris_left_pos, iris_radius, c.BROWN);
c.DrawCircleV(iris_left_pos, 10, c.BLACK);
c.DrawCircleV(sclera_right_pos, sclera_radius, c.LIGHTGRAY);
c.DrawCircleV(iris_right_pos, iris_radius, c.DARKGREEN);
c.DrawCircleV(iris_right_pos, 10, c.BLACK);
c.DrawFPS(10, 10);
//---------------------------------------------------------------------------------
}
}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-38-shapes-following-eyes/build.sh | #!/bin/sh
tmp_raylib_include_path=''
tmp_raylib_external_include_path=''
tmp_raylib_lib_path=''
tmp_raylib_zig_build_mode=''
# No command line arguments => use local variables
if [ $# -eq 0 ]; then
echo
echo 'Using locally defined build variables and paths'
# Set the paths here if you invoke this build.sh manually
tmp_raylib_path='~/ray'
tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include"
tmp_raylib_external_include_path="${tmp_raylib_path}/src/external"
tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib"
# One of:
# -O Debug
# -O ReleaseFast
# -O ReleaseSafe
# -O ReleaseSmall
tmp_raylib_zig_build_mode='-O ReleaseSmall'
else
# Using variables set in ../build_example.sh
tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH
tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH
tmp_raylib_lib_path=$RAYLIB_LIB_PATH
tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE
fi
tmp_raylib_include_arg=''
if [ -n "$tmp_raylib_include_path" ]; then # Not empty
tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}"
fi
if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty
tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}"
fi
#echo 'tmp_raylib_include_arg = '
#echo "$tmp_raylib_include_arg"
tmp_raylib_lib_arg=''
if [ -n "$tmp_raylib_lib_path" ]; then # Not empty
tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib"
else
tmp_raylib_lib_arg='-lc -lraylib'
fi
#echo 'tmp_raylib_lib_arg = '
#echo "$tmp_raylib_lib_arg"
echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}"
zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-38-shapes-following-eyes/build.bat | @echo off
REM First parameter not set = build.bat launched manually
if "%~1"=="" (
echo.
echo Using locally defined build variables and paths
setlocal enableDelayedExpansion
REM These values are used if you invoke this build.bat file manualy.
REM If you use build_example.bat in the root folder, values set in that file are used.
SET RAYLIB_PATH=D:\libs\raylib-4.5.0
SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include
SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external
SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib
REM One of:
REM -O Debug
REM -O ReleaseFast
REM -O ReleaseSafe
REM -O ReleaseSmall
SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall
)
REM echo RAYLIB_PATH: %RAYLIB_PATH%
REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH%
REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH%
REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH%
REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE%
@echo on
zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc
@echo off
REM End local variables scope if not called from the main script
if "%~1"=="" (
endlocal & (
SET RAYLIB_PATH=%RAYLIB_PATH%
SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH%
SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH%
SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH%
SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE%
)
)
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-38-shapes-following-eyes/clean.bat | del main.exe
del main.exe.obj
del main.pdb
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-14b-core-3d-picking-(2-cubes)/clean.sh | rm ./main
rm ./main.o
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-14b-core-3d-picking-(2-cubes)/main.zig | // build with `zig build-exe main.zig -lc -lraylib`
// This is a Zig version of a raylib example from
// https://github.com/raysan5/raylib/
// It is distributed under the same license as the original - unmodified zlib/libpng license
// This version adds a second cube for you to pick.
// Camera controls are also different. Use A and D to rotate the camera around the cubes.
// For the version that sticks to the original C example, see version 14a.
// Header from the original source code follows below:
///*******************************************************************************************
//*
//* raylib [core] example - Picking in 3d mode
//*
//* Example originally created with raylib 1.3, last time updated with raylib 4.0
//*
//* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
//* BSD-like license that allows static linking with closed source software
//*
//* Copyright (c) 2015-2023 Ramon Santamaria (@raysan5)
//*
//********************************************************************************************/
const std = @import("std"); // std.mem.zeroes()
const c = @cImport(
{
@cInclude("raylib.h");
});
pub fn main() void
{
const screen_width = 800;
const screen_height = 450;
const mouse_wheel_speed = 1.0;
const fovy_perspective = 45.0;
const width_orthographic = 10.0;
c.InitWindow(screen_width, screen_height, "raylib [core] example - 3d picking");
defer c.CloseWindow(); // Close window and OpenGL context
// Define the camera to look into our 3d world
var camera = c.Camera3D
{
.position = .{ .x = 10.0, .y = 10.0, .z = 10.0 }, // Camera position
.target = .{ .x = 0.0, .y = 0.0, .z = 0.0 }, // Camera looking at point
.up = .{ .x = 0.0, .y = 1.0, .z = 0.0 }, // Camera up vector (rotation towards target)
.fovy = 45.0, // Camera field-of-view Y
.projection = c.CAMERA_PERSPECTIVE // Camera mode type
};
//const cam_radius_squared = 10.0 * 10.0;
var cam_angle: f32 = 0.0;
var cam_dist: f32 = 10.0;
// Really init the camera
UpdateCam(&camera, cam_angle, cam_dist);
const cube_pos_arr = [_]c.Vector3
{
.{.x = 0.0, .y = 1.0, .z = 0.0},
.{.x = 1.0, .y = 2.0, .z = -0.5},
};
const cube_size_arr = [_]c.Vector3{ .{.x = 2.0, .y = 2.0, .z = 2.0} } ** 2;
var ray = c.Ray{ .position = .{ .x = 0.0, .y = 0.0, .z = 0.0 },
.direction = .{ .x = 0.0, .y = 0.0, .z = 0.0 } }; // Picking line ray
// Mimicking the original C code's { 0 }, just as an example on how.
// Explicit initialization of individual fields is better, even if more verbose.
var collision = comptime std.mem.zeroes(c.RayCollision); // Ray collision hit info
c.SetTargetFPS(60);
var collision_box_idx: ?usize = null;
while (!c.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// -- Toggle camera controls --
// Switch camera projection
if (c.IsKeyPressed(c.KEY_KP_5) or c.IsKeyPressed(c.KEY_P))
{
if (camera.projection == c.CAMERA_PERSPECTIVE)
{
camera.fovy = width_orthographic;
camera.projection = c.CAMERA_ORTHOGRAPHIC;
}
else
{
camera.fovy = fovy_perspective;
camera.projection = c.CAMERA_PERSPECTIVE;
}
}
const mouse_mov = c.GetMouseWheelMove();
if (mouse_mov != 0.0)
{
cam_dist -= mouse_mov * mouse_wheel_speed;
if (cam_dist <= 0.5)
cam_dist = 0.5;
UpdateCam(&camera, cam_angle, cam_dist);
}
if (c.IsKeyDown(c.KEY_D))
{
cam_angle += 1.0;
if (cam_angle >= 360.0)
cam_angle = 0.0;
UpdateCam(&camera, cam_angle, cam_dist);
}
if (c.IsKeyDown(c.KEY_A))
{
cam_angle -= 1.0;
if (cam_angle <= 0.0)
cam_angle = 360.0 - cam_angle;
UpdateCam(&camera, cam_angle, cam_dist);
}
if (c.IsMouseButtonPressed(c.MOUSE_BUTTON_LEFT))
{
ray = c.GetMouseRay(c.GetMousePosition(), camera);
// Check collision between ray and boxes
var min_hit_dist = std.math.floatMax(f32);
collision_box_idx = null;
for (cube_pos_arr, cube_size_arr, 0..) |cube_pos, cube_size, i|
{
collision = c.GetRayCollisionBox(ray,
.{ .min = .{ .x = cube_pos.x - cube_size.x/2.0, .y = cube_pos.y - cube_size.y/2.0, .z = cube_pos.z - cube_size.z/2.0 },
.max = .{ .x = cube_pos.x + cube_size.x/2.0, .y = cube_pos.y + cube_size.y/2.0, .z = cube_pos.z + cube_size.z/2.0 }});
if (collision.hit and collision.distance < min_hit_dist)
{
// New collision is closer to the camera than the previously found one
collision_box_idx = i;
min_hit_dist = collision.distance;
}
}
}
//----------------------------------------------------------------------------------
// Draw
//---------------------------------------------------------------------------------
c.BeginDrawing();
defer c.EndDrawing();
c.ClearBackground(c.RAYWHITE);
{
c.BeginMode3D(camera);
defer c.EndMode3D();
if (collision_box_idx) |box_idx| // (collision.hit)
{
for (cube_pos_arr, cube_size_arr, 0..) |cube_pos, cube_size, i|
{
if (i == box_idx)
{
c.DrawCube(cube_pos, cube_size.x, cube_size.y, cube_size.z, c.RED);
c.DrawCubeWires(cube_pos, cube_size.x, cube_size.y, cube_size.z, c.MAROON);
c.DrawCubeWires(cube_pos, cube_size.x + 0.2, cube_size.y + 0.2, cube_size.z + 0.2, c.GREEN);
}
else
{
c.DrawCube(cube_pos, cube_size.x, cube_size.y, cube_size.z, c.GRAY);
c.DrawCubeWires(cube_pos, cube_size.x, cube_size.y, cube_size.z, c.DARKGRAY);
}
}
}
else // collision_box_idx == null
for (cube_pos_arr, cube_size_arr) |cube_pos, cube_size|
{
c.DrawCube(cube_pos, cube_size.x, cube_size.y, cube_size.z, c.GRAY);
c.DrawCubeWires(cube_pos, cube_size.x, cube_size.y, cube_size.z, c.DARKGRAY);
}
//c.DrawRay(ray, c.MAROON);
c.DrawGrid(10, 1.0);
}
c.DrawText("Click on a box", 280, 10, 20, c.DARKGRAY);
if (collision_box_idx) |box_idx|
{
// https://github.com/raysan5/raylib/blob/9d38363e09aa8725415b444cde37a909d4d9d8a0/src/rtext.c
// raylib's TextFormat stores formatted text in one of it's internal static buffers:
// static char buffers[MAX_TEXTFORMAT_BUFFERS][MAX_TEXT_BUFFER_LENGTH] = { 0 };
// It returns a pointer to one of its buffers. The buffers are reused in a circular manner.
// Normally, #define MAX_TEXTFORMAT_BUFFERS 4
// and #define MAX_TEXT_BUFFER_LENGTH 1024
const fmt_text = c.TextFormat("BOX %03i SELECTED", box_idx);
c.DrawText(fmt_text,
@divTrunc(screen_width - c.MeasureText(fmt_text, 30), 2),
@intFromFloat(screen_height * 0.1), 30, c.GREEN);
}
c.DrawText("Press A or D to orbit the camera, mouse wheel to dolly, P or Numpad 5 to switch projection modes", 10, 430, 10, c.GRAY);
c.DrawFPS(10, 10);
//---------------------------------------------------------------------------------
}
}
inline fn UpdateCam(cam: *c.Camera3D, cam_angle: f32, cam_dist: f32) void
{
cam.position.x = cam_dist * @sin(cam_angle * std.math.pi / 180.0);
cam.position.z = cam_dist * @cos(cam_angle * std.math.pi / 180.0);
}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-14b-core-3d-picking-(2-cubes)/build.sh | #!/bin/sh
tmp_raylib_include_path=''
tmp_raylib_external_include_path=''
tmp_raylib_lib_path=''
tmp_raylib_zig_build_mode=''
# No command line arguments => use local variables
if [ $# -eq 0 ]; then
echo
echo 'Using locally defined build variables and paths'
# Set the paths here if you invoke this build.sh manually
tmp_raylib_path='~/ray'
tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include"
tmp_raylib_external_include_path="${tmp_raylib_path}/src/external"
tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib"
# One of:
# -O Debug
# -O ReleaseFast
# -O ReleaseSafe
# -O ReleaseSmall
tmp_raylib_zig_build_mode='-O ReleaseSmall'
else
# Using variables set in ../build_example.sh
tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH
tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH
tmp_raylib_lib_path=$RAYLIB_LIB_PATH
tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE
fi
tmp_raylib_include_arg=''
if [ -n "$tmp_raylib_include_path" ]; then # Not empty
tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}"
fi
if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty
tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}"
fi
#echo 'tmp_raylib_include_arg = '
#echo "$tmp_raylib_include_arg"
tmp_raylib_lib_arg=''
if [ -n "$tmp_raylib_lib_path" ]; then # Not empty
tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib"
else
tmp_raylib_lib_arg='-lc -lraylib'
fi
#echo 'tmp_raylib_lib_arg = '
#echo "$tmp_raylib_lib_arg"
echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}"
zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-14b-core-3d-picking-(2-cubes)/build.bat | @echo off
REM First parameter not set = build.bat launched manually
if "%~1"=="" (
echo.
echo Using locally defined build variables and paths
setlocal enableDelayedExpansion
REM These values are used if you invoke this build.bat file manualy.
REM If you use build_example.bat in the root folder, values set in that file are used.
SET RAYLIB_PATH=D:\libs\raylib-4.5.0
SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include
SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external
SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib
REM One of:
REM -O Debug
REM -O ReleaseFast
REM -O ReleaseSafe
REM -O ReleaseSmall
SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall
)
REM echo RAYLIB_PATH: %RAYLIB_PATH%
REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH%
REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH%
REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH%
REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE%
@echo on
zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc
@echo off
REM End local variables scope if not called from the main script
if "%~1"=="" (
endlocal & (
SET RAYLIB_PATH=%RAYLIB_PATH%
SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH%
SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH%
SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH%
SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE%
)
)
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-14b-core-3d-picking-(2-cubes)/clean.bat | del main.exe
del main.exe.obj
del main.pdb
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-29-core-split-screen/clean.sh | rm ./main
rm ./main.o
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-29-core-split-screen/main.zig | // build with `zig build-exe main.zig -lc -lraylib`
// This is a Zig version of a raylib example from
// https://github.com/raysan5/raylib/
// It is distributed under the same license as the original - unmodified zlib/libpng license
// Header from the original source code follows below:
///*******************************************************************************************
//*
//* raylib [core] example - split screen
//*
//* Example originally created with raylib 3.7, last time updated with raylib 4.0
//*
//* Example contributed by Jeffery Myers (@JeffM2501) and reviewed by Ramon Santamaria (@raysan5)
//*
//* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
//* BSD-like license that allows static linking with closed source software
//*
//* Copyright (c) 2021-2023 Jeffery Myers (@JeffM2501)
//*
//********************************************************************************************/
const c = @cImport(
{
@cInclude("raylib.h");
});
var camera_player1 = c.Camera3D
{
.position = .{ .x = 0.0, .y = 1.0, .z = -3.0 }, // Camera position
.target = .{ .x = 0.0, .y = 1.0, .z = 0.0 }, // Camera looking at point
.up = .{ .x = 0.0, .y = 1.0, .z = 0.0 }, // Camera up vector (rotation towards target)
.fovy = 45.0, // Camera field-of-view Y
.projection = c.CAMERA_PERSPECTIVE // Camera mode type
};
var camera_player2 = c.Camera3D
{
.position = .{ .x = -3.0, .y = 3.0, .z = 0.0 }, // Camera position
.target = .{ .x = 0.0, .y = 3.0, .z = 0.0 }, // Camera looking at point
.up = .{ .x = 0.0, .y = 1.0, .z = 0.0 }, // Camera up vector (rotation towards target)
.fovy = 45.0, // Camera field-of-view Y
.projection = c.CAMERA_PERSPECTIVE // Camera mode type
};
pub fn main() void
{
const screen_width = 800;
const screen_height = 450;
c.InitWindow(screen_width, screen_height, "raylib [core] example - split screen");
defer c.CloseWindow(); // Close window and OpenGL context
const screen_player1 = c.LoadRenderTexture(screen_width / 2, screen_height); // RenderTexture
defer c.UnloadRenderTexture(screen_player1); // Unload render texture
const screen_player2 = c.LoadRenderTexture(screen_width / 2, screen_height); // RenderTexture
defer c.UnloadRenderTexture(screen_player2); // Unload render texture
// Build a flipped rectangle the size of the split view to use for drawing later
const split_screen_rect = c.Rectangle
{
.x = 0.0, .y = 0.0,
.width = @floatFromInt(screen_player1.texture.width),
.height = @floatFromInt(-screen_player2.texture.height)
};
c.SetTargetFPS(60);
while (!c.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// If anyone moves this frame, how far will they move based on the time since the last frame
// this moves thigns at 10 world units per second, regardless of the actual FPS
const offset_this_frame = 10.0 * c.GetFrameTime();
// Move Player1 forward and backwards (no turning)
if (c.IsKeyDown(c.KEY_W))
{
camera_player1.position.z += offset_this_frame;
camera_player1.target.z += offset_this_frame;
}
else if (c.IsKeyDown(c.KEY_S))
{
camera_player1.position.z -= offset_this_frame;
camera_player1.target.z -= offset_this_frame;
}
// Move Player2 forward and backwards (no turning)
if (c.IsKeyDown(c.KEY_UP))
{
camera_player2.position.x += offset_this_frame;
camera_player2.target.x += offset_this_frame;
}
else if (c.IsKeyDown(c.KEY_DOWN))
{
camera_player2.position.x -= offset_this_frame;
camera_player2.target.x -= offset_this_frame;
}
//----------------------------------------------------------------------------------
// Draw
//---------------------------------------------------------------------------------
// Draw Player1 view to the render texture
{
c.BeginTextureMode(screen_player1);
defer c.EndTextureMode(); // we can use defer to execute this at the end of the block..
c.ClearBackground(c.SKYBLUE);
c.BeginMode3D(camera_player1);
DrawScene();
c.EndMode3D();
c.DrawText("PLAYER1 W/S to move", 10, 10, 20, c.RED);
}
// Draw Player2 view to the render texture
c.BeginTextureMode(screen_player2);
c.ClearBackground(c.SKYBLUE);
c.BeginMode3D(camera_player2);
DrawScene();
c.EndMode3D();
c.DrawText("PLAYER2 UP/DOWN to move", 10, 10, 20, c.BLUE);
c.EndTextureMode(); // ..or we can do it the C way
c.BeginDrawing();
defer c.EndDrawing();
c.ClearBackground(c.BLACK);
c.DrawTextureRec(screen_player1.texture, split_screen_rect,
.{ .x = 0.0, .y = 0.0 }, c.WHITE);
c.DrawTextureRec(screen_player2.texture, split_screen_rect,
.{ .x = @as(f32, @floatFromInt(screen_width)) / 2.0, .y = 0 }, c.WHITE);
c.DrawFPS(10, 30);
//---------------------------------------------------------------------------------
}
}
// Scene drawing
fn DrawScene() void
{
const count = 5;
const spacing = 4.0;
// Grid of cube trees on a plane to make a "world"
c.DrawPlane(.{ .x = 0.0, .y = 0.0, .z = 0.0 }, .{ .x = 50.0, .y = 50.0 }, c.BEIGE); // Simple world plane
// The trees
var x: f32 = -count * spacing;
while (x <= count * spacing) : (x += spacing)
{
var z: f32 = -count * spacing;
while (z <= count * spacing) : (z += spacing)
{
c.DrawCube(.{ .x = x, .y = 1.5, .z = z }, 1.0, 1.0, 1.0, c.LIME);
c.DrawCube(.{ .x = x, .y = 0.5, .z = z }, 0.25, 1.0, 0.25, c.BROWN);
}
}
// Draw a cube at each player's position
c.DrawCube(camera_player1.position, 1.0, 1.0, 1.0, c.RED);
c.DrawCube(camera_player2.position, 1.0, 1.0, 1.0, c.BLUE);
}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-29-core-split-screen/build.sh | #!/bin/sh
tmp_raylib_include_path=''
tmp_raylib_external_include_path=''
tmp_raylib_lib_path=''
tmp_raylib_zig_build_mode=''
# No command line arguments => use local variables
if [ $# -eq 0 ]; then
echo
echo 'Using locally defined build variables and paths'
# Set the paths here if you invoke this build.sh manually
tmp_raylib_path='~/ray'
tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include"
tmp_raylib_external_include_path="${tmp_raylib_path}/src/external"
tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib"
# One of:
# -O Debug
# -O ReleaseFast
# -O ReleaseSafe
# -O ReleaseSmall
tmp_raylib_zig_build_mode='-O ReleaseSmall'
else
# Using variables set in ../build_example.sh
tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH
tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH
tmp_raylib_lib_path=$RAYLIB_LIB_PATH
tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE
fi
tmp_raylib_include_arg=''
if [ -n "$tmp_raylib_include_path" ]; then # Not empty
tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}"
fi
if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty
tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}"
fi
#echo 'tmp_raylib_include_arg = '
#echo "$tmp_raylib_include_arg"
tmp_raylib_lib_arg=''
if [ -n "$tmp_raylib_lib_path" ]; then # Not empty
tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib"
else
tmp_raylib_lib_arg='-lc -lraylib'
fi
#echo 'tmp_raylib_lib_arg = '
#echo "$tmp_raylib_lib_arg"
echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}"
zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-29-core-split-screen/build.bat | @echo off
REM First parameter not set = build.bat launched manually
if "%~1"=="" (
echo.
echo Using locally defined build variables and paths
setlocal enableDelayedExpansion
REM These values are used if you invoke this build.bat file manualy.
REM If you use build_example.bat in the root folder, values set in that file are used.
SET RAYLIB_PATH=D:\libs\raylib-4.5.0
SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include
SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external
SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib
REM One of:
REM -O Debug
REM -O ReleaseFast
REM -O ReleaseSafe
REM -O ReleaseSmall
SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall
)
REM echo RAYLIB_PATH: %RAYLIB_PATH%
REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH%
REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH%
REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH%
REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE%
@echo on
zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc
@echo off
REM End local variables scope if not called from the main script
if "%~1"=="" (
endlocal & (
SET RAYLIB_PATH=%RAYLIB_PATH%
SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH%
SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH%
SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH%
SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE%
)
)
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-29-core-split-screen/clean.bat | del main.exe
del main.exe.obj
del main.pdb
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-43-shapes-draw-circle_sector/clean.sh | rm ./main
rm ./main.o
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-43-shapes-draw-circle_sector/main.zig | // This is a Zig version of a raylib example from
// https://github.com/raysan5/raylib/
// It is distributed under the same license as the original - unmodified zlib/libpng license
// Header from the original source code follows below:
///*******************************************************************************************
//*
//* raylib [shapes] example - draw circle sector (with gui options)
//*
//* Example originally created with raylib 2.5, last time updated with raylib 2.5
//*
//* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5)
//*
//* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
//* BSD-like license that allows static linking with closed source software
//*
//* Copyright (c) 2018-2023 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5)
//*
//********************************************************************************************/
// Download raygui.h from https://github.com/raysan5/raygui/tree/master/src and copy it to this project's folder.
// Build with `zig build-exe main.zig -idirafter ./ -lc -lraylib`
// WARNING: unless this bug in Zig transtale - https://github.com/ziglang/zig/issues/15408 - has been fixed,
// you're going to see errors similar to this:
// /home/archie/.cache/zig/o/c95bc39f271b884ec25d6b2251a68075/cimport.zig:7631:27: error: incompatible types: 'c_int' and 'f32'
// value += (GetMouseDelta().y / (scrollbar.height - slider.height)) * @floatFromInt(valueRange);
// ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// /home/archie/.cache/zig/o/c95bc39f271b884ec25d6b2251a68075/cimport.zig:7631:21: note: type 'c_int' here
// value += (GetMouseDelta().y / (scrollbar.height - slider.height)) * @floatFromInt(valueRange);
// ^~~~~
// /home/archie/.cache/zig/o/c95bc39f271b884ec25d6b2251a68075/cimport.zig:7631:87: note: type 'f32' here
// value += (GetMouseDelta().y / (scrollbar.height - slider.height)) * @floatFromInt(valueRange);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Zig incorrectly skips type coercion when translating certain C code in raygui.h.
// As a workaround, edit raygui.h you have downloaded to this example's folder:
// Find the body of the function that causes Zig translate-c to stumble (currently it's `static int GuiScrollBar`, on line 4442),
// then within it, find the lines that are causing the issue (currently lines 4516, 4517):
//
// if (isVertical) value += (GetMouseDelta().y/(scrollbar.height - slider.height)*valueRange);
// else value += (GetMouseDelta().x/(scrollbar.width - slider.width)*valueRange);
// below them, two more lines (currently lines 4553, 4554):
//
// if (isVertical) value += (GetMouseDelta().y/(scrollbar.height - slider.height)*valueRange);
// else value += (GetMouseDelta().x/(scrollbar.width - slider.width)*valueRange);
// Add explicit type cast `(int)` to the value added to `value` variable in each of the 4 lines like this:
//
// if (isVertical) value += (int)(GetMouseDelta().y/(scrollbar.height - slider.height)*valueRange);
// else value += (int)(GetMouseDelta().x/(scrollbar.width - slider.width)*valueRange);
// This should fix the issue.
// Alternatively, edit the lines in cimport.zig mentioned in the error message, manually adding necessary type coercion:
// value += @intFromFloat((GetMouseDelta().y / (scrollbar.height - slider.height)) * @floatFromInt(valueRange));
//
// Also correct the lines below it:
// value += (GetMouseDelta().x / (scrollbar.width - slider.width)) * @floatFromInt(valueRange);
// Add similar type coercion:
// value += @intFromFloat((GetMouseDelta().x / (scrollbar.width - slider.width)) * @floatFromInt(valueRange));
//
// Apply the same modification to each line where it is needed.
//
// Save cimport.zig and build the project again, it should compile without errors.
// You may need to do this again, if cimport.zig is regenerated by Zig :(
const c = @cImport(
{
@cInclude("raylib.h");
//@cDefine("RAYGUI_IMPLEMENTATION", {}); - Moved to raygui_impl.c
// Here we only need raygui declarations, not actual function bodies.
@cInclude("raygui.h"); // Required for GUI controls
});
pub fn main() void
{
const screen_width = 800;
const screen_height = 450;
c.InitWindow(screen_width, screen_height, "raylib [shapes] example - draw circle sector");
defer c.CloseWindow(); // Close window and OpenGL context
const center = c.Vector2{ .x = @as(f32, @floatFromInt(c.GetScreenWidth() - 300)) / 2.0, .y = @as(f32, @floatFromInt(c.GetScreenHeight())) / 2.0 };
var outer_radius: f32 = 180.0;
var start_angle: f32 = 0.0;
var end_angle: f32 = 180.0;
var segments: f32 = 0.0;
var min_segments: i32 = 4;
c.SetTargetFPS(60);
while (!c.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// NOTE: All variables update happens inside GUI control functions
//----------------------------------------------------------------------------------
// Draw
//---------------------------------------------------------------------------------
c.BeginDrawing();
defer c.EndDrawing();
c.ClearBackground(c.RAYWHITE);
c.DrawLine(500, 0, 500, c.GetScreenHeight(), c.Fade(c.LIGHTGRAY, 0.6));
c.DrawRectangle(500, 0, c.GetScreenWidth() - 500, c.GetScreenHeight(), c.Fade(c.LIGHTGRAY, 0.3));
c.DrawCircleSector(center, outer_radius, start_angle, end_angle, @intFromFloat(segments), c.Fade(c.MAROON, 0.3));
c.DrawCircleSectorLines(center, outer_radius, start_angle, end_angle, @intFromFloat(segments), c.Fade(c.MAROON, 0.6));
// Draw GUI controls
//------------------------------------------------------------------------------
_ = c.GuiSliderBar(.{ .x = 600.0, .y = 40.0, .width = 120.0, .height = 20.0 },
"StartAngle", null, &start_angle, 0.0, 720.0);
_ = c.GuiSliderBar(.{ .x = 600.0, .y = 70.0, .width = 120.0, .height = 20.0 },
"EndAngle", null, &end_angle, 0.0, 720.0);
_ = c.GuiSliderBar(.{ .x = 600.0, .y = 140.0, .width = 120.0, .height = 20.0 },
"Radius", null, &outer_radius, 0.0, 200.0);
_ = c.GuiSliderBar(.{ .x = 600.0, .y = 170.0, .width = 120.0, .height = 20.0 },
"Segments", null, &segments, 0.0, 100.0);
//------------------------------------------------------------------------------
min_segments = @intFromFloat(@ceil((end_angle - start_angle) / 90.0));
// @ptrCast -> [*c]const u8: https://github.com/ziglang/zig/issues/16234
// -- This code causes Zig compiler (0.11.0-dev.3859+88284c124) to segfault, see
// -- https://github.com/ziglang/zig/issues/16197
//c.DrawText(c.TextFormat("MODE: %s",
// if (@as(i32, @intFromFloat(segments)) >= min_segments) "MANUAL" else "AUTO"),
// 600, 200, 10, if (@as(i32, @intFromFloat(segments)) >= min_segments) c.MAROON else c.DARKGRAY);
// -- This does not
const text = if (@as(i32, @intFromFloat(segments)) >= min_segments) "MODE: MANUAL" else "MODE: AUTO";
c.DrawText(text, 600, 200, 10, if (@as(i32, @intFromFloat(segments)) >= min_segments) c.MAROON else c.DARKGRAY);
c.DrawFPS(10, 10);
//---------------------------------------------------------------------------------
}
}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-43-shapes-draw-circle_sector/build.sh | #!/bin/sh
tmp_raylib_include_path=''
tmp_raylib_external_include_path=''
tmp_raylib_lib_path=''
tmp_raylib_zig_build_mode=''
# No command line arguments => use local variables
if [ $# -eq 0 ]; then
echo
echo 'Using locally defined build variables and paths'
# Set the paths here if you invoke this build.sh manually
tmp_raylib_path='~/ray'
tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include"
tmp_raylib_external_include_path="${tmp_raylib_path}/src/external"
tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib"
# One of:
# -O Debug
# -O ReleaseFast
# -O ReleaseSafe
# -O ReleaseSmall
tmp_raylib_zig_build_mode='-O ReleaseSmall'
else
# Using variables set in ../build_example.sh
tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH
tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH
tmp_raylib_lib_path=$RAYLIB_LIB_PATH
tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE
fi
tmp_raylib_include_arg=''
if [ -n "$tmp_raylib_include_path" ]; then # Not empty
tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}"
fi
if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty
tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}"
fi
#echo 'tmp_raylib_include_arg = '
#echo "$tmp_raylib_include_arg"
tmp_raylib_lib_arg=''
if [ -n "$tmp_raylib_lib_path" ]; then # Not empty
tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib"
else
tmp_raylib_lib_arg='-lc -lraylib'
fi
#echo 'tmp_raylib_lib_arg = '
#echo "$tmp_raylib_lib_arg"
echo "zig build-exe main.zig raygui_impl.c ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}"
zig build-exe main.zig raygui_impl.c ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-43-shapes-draw-circle_sector/build.bat | @echo off
REM First parameter not set = build.bat launched manually
if "%~1"=="" (
echo.
echo Using locally defined build variables and paths
setlocal enableDelayedExpansion
REM These values are used if you invoke this build.bat file manualy.
REM If you use build_example.bat in the root folder, values set in that file are used.
SET RAYLIB_PATH=D:\libs\raylib-4.5.0
SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include
SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external
SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib
REM One of:
REM -O Debug
REM -O ReleaseFast
REM -O ReleaseSafe
REM -O ReleaseSmall
SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall
)
REM echo RAYLIB_PATH: %RAYLIB_PATH%
REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH%
REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH%
REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH%
REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE%
@echo on
zig build-exe main.zig raygui_impl.c %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc
@echo off
REM End local variables scope if not called from the main script
if "%~1"=="" (
endlocal & (
SET RAYLIB_PATH=%RAYLIB_PATH%
SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH%
SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH%
SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH%
SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE%
)
)
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-43-shapes-draw-circle_sector/raygui_impl.c | // Since raygui is a single-header C library,
// we've got to have this "implementation" file,
// which is just an adapter used to facilitate C-to-Zig
// translation
#define RAYGUI_IMPLEMENTATION
// UGLY WORKAROUND:
// Declaration and implementation of `TextToFloat` were copied from raygui.h due to reasons below.
// I'm not sure why `raygui.h` does this now, but `TextToFloat` is defined ONLY if
// `RAYGUI_STANDALONE` constant is defined.
// At the same time, `TextToFloat` is called from `GuiValueBoxFloat`, which means it can't be compiled.
// So, in order to build our project, we must provide a copy of `TextToFloat`, since we do not
// want to define `RAYGUI_STANDALONE` (it breaks things for us).
static float TextToFloat(const char *text); // Get float value from text
#include "raygui.h"
// Get float value from text
// NOTE: This function replaces atof() [stdlib.h]
// WARNING: Only '.' character is understood as decimal point
static float TextToFloat(const char *text)
{
float value = 0.0f;
float sign = 1.0f;
if ((text[0] == '+') || (text[0] == '-'))
{
if (text[0] == '-') sign = -1.0f;
text++;
}
int i = 0;
for (; ((text[i] >= '0') && (text[i] <= '9')); i++) value = value*10.0f + (float)(text[i] - '0');
if (text[i++] != '.') value *= sign;
else
{
float divisor = 10.0f;
for (; ((text[i] >= '0') && (text[i] <= '9')); i++)
{
value += ((float)(text[i] - '0'))/divisor;
divisor = divisor*10.0f;
}
}
return value;
}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-43-shapes-draw-circle_sector/clean.bat | del main.exe
del main.exe.obj
del main.pdb
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/sshots/sshots.md | #### Screenshot gallery
[<img src="thumbs/th_01.jpg">](01.png) [<img src="thumbs/th_02.jpg">](02.png)
[<img src="thumbs/th_03.jpg">](03.png) [<img src="thumbs/th_04.jpg">](04.png)
[<img src="thumbs/th_07.jpg">](07.png) [<img src="thumbs/th_08.jpg">](08.png)
[<img src="thumbs/th_09.jpg">](09.png) [<img src="thumbs/th_11.jpg">](11.png)
[<img src="thumbs/th_12.jpg">](12.png) [<img src="thumbs/th_13.jpg">](13.png)
[<img src="thumbs/th_14a.jpg">](14a.png) [<img src="thumbs/th_14b.jpg">](14b.png)
[<img src="thumbs/th_15.jpg">](15.png) [<img src="thumbs/th_17.jpg">](17.png)
[<img src="thumbs/th_19.jpg">](19.png) [<img src="thumbs/th_27.jpg">](27.png)
[<img src="thumbs/th_29.jpg">](29.png) [<img src="thumbs/th_30.jpg">](30.png)
[<img src="thumbs/th_32.jpg">](32.png) [<img src="thumbs/th_33.jpg">](33.png)
[<img src="thumbs/th_34.jpg">](34.png) [<img src="thumbs/th_35.jpg">](35.png)
[<img src="thumbs/th_36.jpg">](36.png) [<img src="thumbs/th_37.jpg">](37.png)
[<img src="thumbs/th_38.jpg">](38.png) [<img src="thumbs/th_39.jpg">](39.png)
[<img src="thumbs/th_40.jpg">](40.png) [<img src="thumbs/th_41.jpg">](41.png)
[<img src="thumbs/th_42.jpg">](42.png) [<img src="thumbs/th_43.jpg">](43.png)
[<img src="thumbs/th_44.jpg">](44.png) [<img src="thumbs/th_45.jpg">](45.png)
[<img src="thumbs/th_46.jpg">](46.png) [<img src="thumbs/th_49.jpg">](49.png)
[<img src="thumbs/th_50.jpg">](50.png) [<img src="thumbs/th_53.jpg">](53.png)
[<img src="thumbs/th_54a.jpg">](54a.jpg) [<img src="thumbs/th_54b.jpg">](54b.jpg)
[<img src="thumbs/th_68.jpg">](68.png) [<img src="thumbs/th_69.jpg">](69.png)
[<img src="thumbs/th_70.jpg">](70.png) [<img src="thumbs/th_71.jpg">](71.png)
[<img src="thumbs/th_72.jpg">](72.png) [<img src="thumbs/th_74.jpg">](74.png)
[<img src="thumbs/th_75.jpg">](75.png) [<img src="thumbs/th_76.jpg">](76.png)
[<img src="thumbs/th_77.jpg">](77.png) [<img src="thumbs/th_83.jpg">](83.png)
[<img src="thumbs/th_84.jpg">](84.jpg) [<img src="thumbs/th_85.jpg">](85.jpg)
[<img src="thumbs/th_86.jpg">](86.png) [<img src="thumbs/th_87a.jpg">](87a.png)
[<img src="thumbs/th_87b.jpg">](87b.png) [<img src="thumbs/th_93.jpg">](93.png)
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-14a-core-3d-picking-(original)/clean.sh | rm ./main
rm ./main.o
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-14a-core-3d-picking-(original)/main.zig | // build with `zig build-exe main.zig -lc -lraylib`
// This is a Zig version of a raylib example from
// https://github.com/raysan5/raylib/
// It is distributed under the same license as the original - unmodified zlib/libpng license
// This version sticks to the original C example.
// For the version with two cubes, see version 14b.
// Header from the original source code follows below:
///*******************************************************************************************
//*
//* raylib [core] example - Picking in 3d mode
//*
//* Example originally created with raylib 1.3, last time updated with raylib 4.0
//*
//* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
//* BSD-like license that allows static linking with closed source software
//*
//* Copyright (c) 2015-2023 Ramon Santamaria (@raysan5)
//*
//********************************************************************************************/
const std = @import("std"); // std.mem.zeroes()
const c = @cImport(
{
@cInclude("raylib.h");
});
pub fn main() void
{
const screen_width = 800;
const screen_height = 450;
c.InitWindow(screen_width, screen_height, "raylib [core] example - 3d picking");
defer c.CloseWindow(); // Close window and OpenGL context
// Define the camera to look into our 3d world
var camera = c.Camera3D
{
.position = .{ .x = 10.0, .y = 10.0, .z = 10.0 }, // Camera position
.target = .{ .x = 0.0, .y = 0.0, .z = 0.0 }, // Camera looking at point
.up = .{ .x = 0.0, .y = 1.0, .z = 0.0 }, // Camera up vector (rotation towards target)
.fovy = 45.0, // Camera field-of-view Y
.projection = c.CAMERA_PERSPECTIVE // Camera mode type
};
const cube_pos = c.Vector3{ .x = 0.0, .y = 1.0, .z = 0.0 };
const cube_size = c.Vector3{ .x = 2.0, .y = 2.0, .z = 2.0 };
var ray = c.Ray{ .position = .{ .x = 0.0, .y = 0.0, .z = 0.0 },
.direction = .{ .x = 0.0, .y = 0.0, .z = 0.0 } }; // Picking line ray
var collision = comptime std.mem.zeroes(c.RayCollision); // Ray collision hit info
c.SetTargetFPS(60);
while (!c.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
if (c.IsCursorHidden()) c.UpdateCamera(&camera, c.CAMERA_FIRST_PERSON);
// Toggle camera controls
if (c.IsMouseButtonPressed(c.MOUSE_BUTTON_RIGHT))
{
if (c.IsCursorHidden()) { c.EnableCursor(); }
else c.DisableCursor();
}
if (c.IsMouseButtonPressed(c.MOUSE_BUTTON_LEFT))
{
if (!collision.hit)
{
ray = c.GetMouseRay(c.GetMousePosition(), camera);
// Check collision between ray and box
collision = c.GetRayCollisionBox(ray,
.{ .min = .{ .x = cube_pos.x - cube_size.x/2, .y = cube_pos.y - cube_size.y/2, .z = cube_pos.z - cube_size.z/2 },
.max = .{ .x = cube_pos.x + cube_size.x/2, .y = cube_pos.y + cube_size.y/2, .z = cube_pos.z + cube_size.z/2 }});
}
else collision.hit = false;
}
//----------------------------------------------------------------------------------
// Draw
//---------------------------------------------------------------------------------
c.BeginDrawing();
defer c.EndDrawing();
c.ClearBackground(c.RAYWHITE);
{
c.BeginMode3D(camera);
defer c.EndMode3D();
if (collision.hit)
{
c.DrawCube(cube_pos, cube_size.x, cube_size.y, cube_size.z, c.RED);
c.DrawCubeWires(cube_pos, cube_size.x, cube_size.y, cube_size.z, c.MAROON);
c.DrawCubeWires(cube_pos, cube_size.x + 0.2, cube_size.y + 0.2, cube_size.z + 0.2, c.GREEN);
}
else
{
c.DrawCube(cube_pos, cube_size.x, cube_size.y, cube_size.z, c.GRAY);
c.DrawCubeWires(cube_pos, cube_size.x, cube_size.y, cube_size.z, c.DARKGRAY);
}
c.DrawRay(ray, c.MAROON);
c.DrawGrid(10, 1.0);
}
c.DrawText("Try clicking on the box with your mouse!", 240, 10, 20, c.DARKGRAY);
if (collision.hit)
c.DrawText("BOX SELECTED",
@divTrunc(screen_width - c.MeasureText("BOX SELECTED", 30), 2),
@intFromFloat(screen_height * 0.1), 30, c.GREEN);
c.DrawText("Right click mouse to toggle camera controls", 10, 430, 10, c.GRAY);
c.DrawFPS(10, 10);
//---------------------------------------------------------------------------------
}
}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-14a-core-3d-picking-(original)/build.sh | #!/bin/sh
tmp_raylib_include_path=''
tmp_raylib_external_include_path=''
tmp_raylib_lib_path=''
tmp_raylib_zig_build_mode=''
# No command line arguments => use local variables
if [ $# -eq 0 ]; then
echo
echo 'Using locally defined build variables and paths'
# Set the paths here if you invoke this build.sh manually
tmp_raylib_path='~/ray'
tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include"
tmp_raylib_external_include_path="${tmp_raylib_path}/src/external"
tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib"
# One of:
# -O Debug
# -O ReleaseFast
# -O ReleaseSafe
# -O ReleaseSmall
tmp_raylib_zig_build_mode='-O ReleaseSmall'
else
# Using variables set in ../build_example.sh
tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH
tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH
tmp_raylib_lib_path=$RAYLIB_LIB_PATH
tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE
fi
tmp_raylib_include_arg=''
if [ -n "$tmp_raylib_include_path" ]; then # Not empty
tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}"
fi
if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty
tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}"
fi
#echo 'tmp_raylib_include_arg = '
#echo "$tmp_raylib_include_arg"
tmp_raylib_lib_arg=''
if [ -n "$tmp_raylib_lib_path" ]; then # Not empty
tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib"
else
tmp_raylib_lib_arg='-lc -lraylib'
fi
#echo 'tmp_raylib_lib_arg = '
#echo "$tmp_raylib_lib_arg"
echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}"
zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-14a-core-3d-picking-(original)/build.bat | @echo off
REM First parameter not set = build.bat launched manually
if "%~1"=="" (
echo.
echo Using locally defined build variables and paths
setlocal enableDelayedExpansion
REM These values are used if you invoke this build.bat file manualy.
REM If you use build_example.bat in the root folder, values set in that file are used.
SET RAYLIB_PATH=D:\libs\raylib-4.5.0
SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include
SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external
SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib
REM One of:
REM -O Debug
REM -O ReleaseFast
REM -O ReleaseSafe
REM -O ReleaseSmall
SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall
)
REM echo RAYLIB_PATH: %RAYLIB_PATH%
REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH%
REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH%
REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH%
REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE%
@echo on
zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc
@echo off
REM End local variables scope if not called from the main script
if "%~1"=="" (
endlocal & (
SET RAYLIB_PATH=%RAYLIB_PATH%
SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH%
SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH%
SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH%
SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE%
)
)
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-14a-core-3d-picking-(original)/clean.bat | del main.exe
del main.exe.obj
del main.pdb
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-85-models-first-person-maze/clean.sh | rm ./main
rm ./main.o
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-85-models-first-person-maze/main.zig | // build with `zig build-exe main.zig -lc -lraylib`
// This is a Zig version of a raylib example from
// https://github.com/raysan5/raylib/
// It is distributed under the same license as the original - unmodified zlib/libpng license
// Header from the original source code follows below:
///*******************************************************************************************
//*
//* raylib [models] example - first person maze
//*
//* Example originally created with raylib 2.5, last time updated with raylib 3.5
//*
//* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
//* BSD-like license that allows static linking with closed source software
//*
//* Copyright (c) 2019-2023 Ramon Santamaria (@raysan5)
//*
//********************************************************************************************/
const c = @cImport(
{
@cInclude("raylib.h");
});
pub fn main() void
{
const screen_width = 800;
const screen_height = 450;
c.InitWindow(screen_width, screen_height, "raylib [models] example - first person maze");
defer c.CloseWindow(); // Close window and OpenGL context
// Define the camera to look into our 3d world
var camera = c.Camera3D
{
.position = .{ .x = 0.2, .y = 0.4, .z = 0.2 }, // Camera position
.target = .{ .x = 0.185, .y = 0.4, .z = 0.0 }, // Camera looking at point
.up = .{ .x = 0.0, .y = 1.0, .z = 0.0 }, // Camera up vector (rotation towards target)
.fovy = 45.0, // Camera field-of-view Y
.projection = c.CAMERA_PERSPECTIVE // Camera mode type
};
const im_map = c.LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM) - c.Image
const cubicmap = c.LoadTextureFromImage(im_map); // Convert image to texture to display (VRAM) - c.Texture2D
const mesh = c.GenMeshCubicmap(im_map, .{ .x = 1.0, .y = 1.0, .z = 1.0 }); // c.Mesh
const model = c.LoadModelFromMesh(mesh); // c.Model
defer c.UnloadModel(model); // Unload map model
// NOTE: By default each cube is mapped to one part of texture atlas
const texture = c.LoadTexture("resources/cubicmap_atlas.png"); // Load map texture - c.Texture2D
defer c.UnloadTexture(texture); // Unload map texture
defer c.UnloadTexture(cubicmap); // Unload cubicmap texture
model.materials[0].maps[c.MATERIAL_MAP_DIFFUSE].texture = texture; // Set map diffuse texture
const map_pos = c.Vector3{ .x = -16.0, .y = 0.0, .z = -8.0 }; // Set model position
// Get map image data to be used for collision detection
const map_pixels = c.LoadImageColors(im_map); // [*c]Color
defer c.UnloadImageColors(map_pixels); // Unload color array
c.UnloadImage(im_map); // Unload cubesmap image from RAM, already uploaded to VRAM
c.DisableCursor(); // Limit cursor to relative movement inside the window
c.SetTargetFPS(60);
while (!c.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
const old_cam_pos = camera.position; // Store old camera position
c.UpdateCamera(&camera, c.CAMERA_FIRST_PERSON);
// Check player collision (we simplify to 2D collision detection)
const player_pos = .{ .x = camera.position.x, .y = camera.position.z };
const player_radius = 0.1; // Collision radius (player is modelled as a cilinder for collision)
var player_cell_x: i32 = @intFromFloat(player_pos.x - map_pos.x + 0.5);
var player_cell_y: i32 = @intFromFloat(player_pos.y - map_pos.z + 0.5);
// Out-of-limits security check
if (player_cell_x < 0)
{ player_cell_x = 0; }
else
if (player_cell_x >= cubicmap.width)
player_cell_x = cubicmap.width - 1;
if (player_cell_y < 0)
{ player_cell_y = 0; }
else
if (player_cell_y >= cubicmap.height)
player_cell_y = cubicmap.height - 1;
// Check map collisions using image data and player position
// TODO: Improvement: Just check player surrounding cells for collision
for (0..@intCast(cubicmap.height)) |y| // @intCast -> usize
{
for (0..@intCast(cubicmap.width)) |x| // @intCast -> usize
{
if ((map_pixels[y * @as(usize, @intCast(cubicmap.width)) + x].r == 255) and // Collision: white pixel, only check R channel
c.CheckCollisionCircleRec(player_pos, player_radius,
.{ .x = map_pos.x - 0.5 + @as(f32, @floatFromInt(x)),
.y = map_pos.z - 0.5 + @as(f32, @floatFromInt(y)),
.width = 1.0, .height = 1.0 }))
camera.position = old_cam_pos; // Collision detected, reset camera position
}
}
//----------------------------------------------------------------------------------
// Draw
//---------------------------------------------------------------------------------
c.BeginDrawing();
defer c.EndDrawing();
c.ClearBackground(c.RAYWHITE);
{
c.BeginMode3D(camera);
defer c.EndMode3D();
c.DrawModel(model, map_pos, 1.0, c.WHITE);
}
c.DrawTextureEx(cubicmap,
.{ .x = @floatFromInt(c.GetScreenWidth() - cubicmap.width * 4 - 20),
.y = 20.0 }, 0.0, 4.0, c.WHITE);
c.DrawRectangleLines(c.GetScreenWidth() - cubicmap.width * 4 - 20, 20,
cubicmap.width * 4, cubicmap.height * 4, c.GREEN);
// Draw player position radar
c.DrawRectangle(c.GetScreenWidth() - cubicmap.width * 4 - 20 + player_cell_x * 4,
20 + player_cell_y * 4, 4, 4, c.RED);
c.DrawFPS(10, 10);
//---------------------------------------------------------------------------------
}
}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-85-models-first-person-maze/build.sh | #!/bin/sh
tmp_raylib_include_path=''
tmp_raylib_external_include_path=''
tmp_raylib_lib_path=''
tmp_raylib_zig_build_mode=''
# No command line arguments => use local variables
if [ $# -eq 0 ]; then
echo
echo 'Using locally defined build variables and paths'
# Set the paths here if you invoke this build.sh manually
tmp_raylib_path='~/ray'
tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include"
tmp_raylib_external_include_path="${tmp_raylib_path}/src/external"
tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib"
# One of:
# -O Debug
# -O ReleaseFast
# -O ReleaseSafe
# -O ReleaseSmall
tmp_raylib_zig_build_mode='-O ReleaseSmall'
else
# Using variables set in ../build_example.sh
tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH
tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH
tmp_raylib_lib_path=$RAYLIB_LIB_PATH
tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE
fi
tmp_raylib_include_arg=''
if [ -n "$tmp_raylib_include_path" ]; then # Not empty
tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}"
fi
if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty
tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}"
fi
#echo 'tmp_raylib_include_arg = '
#echo "$tmp_raylib_include_arg"
tmp_raylib_lib_arg=''
if [ -n "$tmp_raylib_lib_path" ]; then # Not empty
tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib"
else
tmp_raylib_lib_arg='-lc -lraylib'
fi
#echo 'tmp_raylib_lib_arg = '
#echo "$tmp_raylib_lib_arg"
echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}"
zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-85-models-first-person-maze/build.bat | @echo off
REM First parameter not set = build.bat launched manually
if "%~1"=="" (
echo.
echo Using locally defined build variables and paths
setlocal enableDelayedExpansion
REM These values are used if you invoke this build.bat file manualy.
REM If you use build_example.bat in the root folder, values set in that file are used.
SET RAYLIB_PATH=D:\libs\raylib-4.5.0
SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include
SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external
SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib
REM One of:
REM -O Debug
REM -O ReleaseFast
REM -O ReleaseSafe
REM -O ReleaseSmall
SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall
)
REM echo RAYLIB_PATH: %RAYLIB_PATH%
REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH%
REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH%
REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH%
REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE%
@echo on
zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc
@echo off
REM End local variables scope if not called from the main script
if "%~1"=="" (
endlocal & (
SET RAYLIB_PATH=%RAYLIB_PATH%
SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH%
SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH%
SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH%
SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE%
)
)
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-85-models-first-person-maze/clean.bat | del main.exe
del main.exe.obj
del main.pdb
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-71-text-font-filters/clean.sh | rm ./main
rm ./main.o
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-71-text-font-filters/main.zig | // build with `zig build-exe main.zig -lc -lraylib`
// This is a Zig version of a raylib example from
// https://github.com/raysan5/raylib/
// It is distributed under the same license as the original - unmodified zlib/libpng license
// Header from the original source code follows below:
///*******************************************************************************************
//*
//* raylib [text] example - Font filters
//*
//* NOTE: After font loading, font texture atlas filter could be configured for a softer
//* display of the font when scaling it to different sizes, that way, it's not required
//* to generate multiple fonts at multiple sizes (as long as the scaling is not very different)
//*
//* Example originally created with raylib 1.3, last time updated with raylib 4.2
//*
//* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
//* BSD-like license that allows static linking with closed source software
//*
//* Copyright (c) 2015-2023 Ramon Santamaria (@raysan5)
//*
//********************************************************************************************/
const c = @cImport(
{
@cInclude("raylib.h");
});
pub fn main() void
{
const screen_width = 800;
const screen_height = 450;
c.InitWindow(screen_width, screen_height, "raylib [text] example - font filters");
defer c.CloseWindow(); // Close window and OpenGL context
const msg: [*:0]const u8 = "Loaded Font";
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
// TTF Font loading with custom generation parameters
var font = c.LoadFontEx("resources/KAISG.ttf", 96, 0, 0); // c.Font
defer c.UnloadFont(font);
// Generate mipmap levels to use trilinear filtering
// NOTE: On 2D drawing it won't be noticeable, it looks like FILTER_BILINEAR
c.GenTextureMipmaps(&font.texture);
var font_size: f32 = @floatFromInt(font.baseSize);
var font_pos = c.Vector2{ .x = 40.0, .y = screen_height / 2.0 - 80.0 };
var text_size = c.Vector2{ .x = 0.0, .y = 0.0 };
// Setup texture scaling filter
c.SetTextureFilter(font.texture, c.TEXTURE_FILTER_POINT);
var curr_font_filter = c.TEXTURE_FILTER_POINT;
c.SetTargetFPS(60);
while (!c.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
font_size += c.GetMouseWheelMove() * 4.0;
// Choose font texture filter method
if (c.IsKeyPressed(c.KEY_ONE))
{
c.SetTextureFilter(font.texture, c.TEXTURE_FILTER_POINT);
curr_font_filter = c.TEXTURE_FILTER_POINT;
}
else if (c.IsKeyPressed(c.KEY_TWO))
{
c.SetTextureFilter(font.texture, c.TEXTURE_FILTER_BILINEAR);
curr_font_filter = c.TEXTURE_FILTER_BILINEAR;
}
else if (c.IsKeyPressed(c.KEY_THREE))
{
// NOTE: Trilinear filter won't be noticed on 2D drawing
c.SetTextureFilter(font.texture, c.TEXTURE_FILTER_TRILINEAR);
curr_font_filter = c.TEXTURE_FILTER_TRILINEAR;
}
text_size = c.MeasureTextEx(font, msg, font_size, 0);
if (c.IsKeyDown(c.KEY_LEFT))
{ font_pos.x -= 10; }
else
if (c.IsKeyDown(c.KEY_RIGHT))
font_pos.x += 10;
// Load a dropped TTF file dynamically (at current font_size)
if (c.IsFileDropped())
{
const droppedFiles = c.LoadDroppedFiles(); // c.FilePathList
// NOTE: We only support first ttf file dropped
if (c.IsFileExtension(droppedFiles.paths[0], ".ttf"))
{
c.UnloadFont(font);
font = c.LoadFontEx(droppedFiles.paths[0], @intFromFloat(font_size), 0, 0);
}
c.UnloadDroppedFiles(droppedFiles); // Unload filepaths from memory
}
//----------------------------------------------------------------------------------
// Draw
//---------------------------------------------------------------------------------
c.BeginDrawing();
defer c.EndDrawing();
c.ClearBackground(c.RAYWHITE);
c.DrawText("Use mouse wheel to change font size", 20, 20, 10, c.GRAY);
c.DrawText("Use KEY_RIGHT and KEY_LEFT to move text", 20, 40, 10, c.GRAY);
c.DrawText("Use 1, 2, 3 to change texture filter", 20, 60, 10, c.GRAY);
c.DrawText("Drop a new TTF font for dynamic loading", 20, 80, 10, c.DARKGRAY);
c.DrawTextEx(font, msg, font_pos, font_size, 0, c.BLACK);
// TODO: It seems texSize measurement is not accurate due to chars offsets...
//DrawRectangleLines(font_pos.x, font_pos.y, text_size.x, text_size.y, RED);
c.DrawRectangle(0, screen_height - 80, screen_width, 80, c.LIGHTGRAY);
c.DrawText(c.TextFormat("Font size: %02.02f", text_size), 20, screen_height - 50, 10, c.DARKGRAY);
c.DrawText(c.TextFormat("Text size: [%02.02f, %02.02f]", text_size.x, text_size.y),
20, screen_height - 30, 10, c.DARKGRAY);
c.DrawText("CURRENT TEXTURE FILTER:", 250, 400, 20, c.GRAY);
if (curr_font_filter == 0)
{ c.DrawText("POINT", 570, 400, 20, c.BLACK); }
else
if (curr_font_filter == 1)
{ c.DrawText("BILINEAR", 570, 400, 20, c.BLACK); }
else
if (curr_font_filter == 2)
c.DrawText("TRILINEAR", 570, 400, 20, c.BLACK);
//---------------------------------------------------------------------------------
}
}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-71-text-font-filters/build.sh | #!/bin/sh
tmp_raylib_include_path=''
tmp_raylib_external_include_path=''
tmp_raylib_lib_path=''
tmp_raylib_zig_build_mode=''
# No command line arguments => use local variables
if [ $# -eq 0 ]; then
echo
echo 'Using locally defined build variables and paths'
# Set the paths here if you invoke this build.sh manually
tmp_raylib_path='~/ray'
tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include"
tmp_raylib_external_include_path="${tmp_raylib_path}/src/external"
tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib"
# One of:
# -O Debug
# -O ReleaseFast
# -O ReleaseSafe
# -O ReleaseSmall
tmp_raylib_zig_build_mode='-O ReleaseSmall'
else
# Using variables set in ../build_example.sh
tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH
tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH
tmp_raylib_lib_path=$RAYLIB_LIB_PATH
tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE
fi
tmp_raylib_include_arg=''
if [ -n "$tmp_raylib_include_path" ]; then # Not empty
tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}"
fi
if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty
tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}"
fi
#echo 'tmp_raylib_include_arg = '
#echo "$tmp_raylib_include_arg"
tmp_raylib_lib_arg=''
if [ -n "$tmp_raylib_lib_path" ]; then # Not empty
tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib"
else
tmp_raylib_lib_arg='-lc -lraylib'
fi
#echo 'tmp_raylib_lib_arg = '
#echo "$tmp_raylib_lib_arg"
echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}"
zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-71-text-font-filters/build.bat | @echo off
REM First parameter not set = build.bat launched manually
if "%~1"=="" (
echo.
echo Using locally defined build variables and paths
setlocal enableDelayedExpansion
REM These values are used if you invoke this build.bat file manualy.
REM If you use build_example.bat in the root folder, values set in that file are used.
SET RAYLIB_PATH=D:\libs\raylib-4.5.0
SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include
SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external
SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib
REM One of:
REM -O Debug
REM -O ReleaseFast
REM -O ReleaseSafe
REM -O ReleaseSmall
SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall
)
REM echo RAYLIB_PATH: %RAYLIB_PATH%
REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH%
REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH%
REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH%
REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE%
@echo on
zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc
@echo off
REM End local variables scope if not called from the main script
if "%~1"=="" (
endlocal & (
SET RAYLIB_PATH=%RAYLIB_PATH%
SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH%
SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH%
SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH%
SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE%
)
)
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-71-text-font-filters/clean.bat | del main.exe
del main.exe.obj
del main.pdb
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-09-core-2d-camera-mouse-zoom/clean.sh | rm ./main
rm ./main.o
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-09-core-2d-camera-mouse-zoom/main.zig | // build with `zig build-exe main.zig -lc -lraylib`
// This is a Zig version of a raylib example from
// https://github.com/raysan5/raylib/
// It is distributed under the same license as the original - unmodified zlib/libpng license
// Header from the original source code follows below:
///*******************************************************************************************
//*
//* raylib [core] example - 2d camera mouse zoom
//*
//* Example originally created with raylib 4.2, last time updated with raylib 4.2
//*
//* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
//* BSD-like license that allows static linking with closed source software
//*
//* Copyright (c) 2022-2023 Jeffery Myers (@JeffM2501)
//*
//********************************************************************************************/
const std = @import("std"); // std.mem.zeroes()
const c = @cImport(
{
@cInclude("raylib.h");
@cInclude("rlgl.h");
@cInclude("raymath.h");
});
pub fn main() void
{
const screen_width = 800;
const screen_height = 450;
c.InitWindow(screen_width, screen_height, "raylib [core] example - 2d camera mouse zoom");
defer c.CloseWindow();
// Explicitly initializing struct fields is better,
// but we can also do this:
var camera = comptime std.mem.zeroes(c.Camera2D);
camera.zoom = 1.0;
c.SetTargetFPS(60);
while (!c.WindowShouldClose())
{
// Update
//----------------------------------------------------------------------------------
// Translate based on mouse right click
if (c.IsMouseButtonDown(c.MOUSE_BUTTON_RIGHT))
{
var delta = c.GetMouseDelta(); // Vector2
delta = c.Vector2Scale(delta, -1.0 / camera.zoom);
camera.target = c.Vector2Add(camera.target, delta);
}
// Zoom based on mouse wheel
const wheel = c.GetMouseWheelMove();
if (wheel != 0.0)
{
// Get the world point that is under the mouse
const mouse_world_pos = c.GetScreenToWorld2D(c.GetMousePosition(), camera); // Vector2
// Set the offset to where the mouse is
camera.offset = c.GetMousePosition();
// Set the target to match, so that the camera maps the world space point
// under the cursor to the screen space point under the cursor at any zoom
camera.target = mouse_world_pos;
// Zoom increment
const zoom_increment = 0.125;
camera.zoom += (wheel * zoom_increment);
if (camera.zoom < zoom_increment) camera.zoom = zoom_increment;
}
//----------------------------------------------------------------------------------
// Draw
//---------------------------------------------------------------------------------
c.BeginDrawing();
defer c.EndDrawing();
c.ClearBackground(c.BLACK);
{
c.BeginMode2D(camera);
defer c.EndMode2D();
// Draw the 3d grid, rotated 90 degrees and centered around 0,0
// just so we have something in the XY plane
c.rlPushMatrix();
c.rlTranslatef(0.0, 25.0*50.0, 0.0);
c.rlRotatef(90.0, 1.0, 0.0, 0.0);
c.DrawGrid(100, 50.0);
c.rlPopMatrix();
// Draw a reference circle
c.DrawCircle(100, 100, 50, c.YELLOW);
}
c.DrawText("Mouse right button drag to move, mouse wheel to zoom", 10, 10, 20, c.WHITE);
//---------------------------------------------------------------------------------
}
}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-09-core-2d-camera-mouse-zoom/build.sh | #!/bin/sh
tmp_raylib_include_path=''
tmp_raylib_external_include_path=''
tmp_raylib_lib_path=''
tmp_raylib_zig_build_mode=''
# No command line arguments => use local variables
if [ $# -eq 0 ]; then
echo
echo 'Using locally defined build variables and paths'
# Set the paths here if you invoke this build.sh manually
tmp_raylib_path='~/ray'
tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include"
tmp_raylib_external_include_path="${tmp_raylib_path}/src/external"
tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib"
# One of:
# -O Debug
# -O ReleaseFast
# -O ReleaseSafe
# -O ReleaseSmall
tmp_raylib_zig_build_mode='-O ReleaseSmall'
else
# Using variables set in ../build_example.sh
tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH
tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH
tmp_raylib_lib_path=$RAYLIB_LIB_PATH
tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE
fi
tmp_raylib_include_arg=''
if [ -n "$tmp_raylib_include_path" ]; then # Not empty
tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}"
fi
if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty
tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}"
fi
#echo 'tmp_raylib_include_arg = '
#echo "$tmp_raylib_include_arg"
tmp_raylib_lib_arg=''
if [ -n "$tmp_raylib_lib_path" ]; then # Not empty
tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib"
else
tmp_raylib_lib_arg='-lc -lraylib'
fi
#echo 'tmp_raylib_lib_arg = '
#echo "$tmp_raylib_lib_arg"
echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}"
zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-09-core-2d-camera-mouse-zoom/build.bat | @echo off
REM First parameter not set = build.bat launched manually
if "%~1"=="" (
echo.
echo Using locally defined build variables and paths
setlocal enableDelayedExpansion
REM These values are used if you invoke this build.bat file manualy.
REM If you use build_example.bat in the root folder, values set in that file are used.
SET RAYLIB_PATH=D:\libs\raylib-4.5.0
SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include
SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external
SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib
REM One of:
REM -O Debug
REM -O ReleaseFast
REM -O ReleaseSafe
REM -O ReleaseSmall
SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall
)
REM echo RAYLIB_PATH: %RAYLIB_PATH%
REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH%
REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH%
REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH%
REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE%
@echo on
zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc
@echo off
REM End local variables scope if not called from the main script
if "%~1"=="" (
endlocal & (
SET RAYLIB_PATH=%RAYLIB_PATH%
SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH%
SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH%
SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH%
SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE%
)
)
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-09-core-2d-camera-mouse-zoom/clean.bat | del main.exe
del main.exe.obj
del main.pdb
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-27-core-custom-frame-control/clean.sh | rm ./main
rm ./main.o
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-27-core-custom-frame-control/main.zig | // build with `zig build-exe main.zig -lc -lraylib`
// This is a Zig version of a raylib example from
// https://github.com/raysan5/raylib/
// It is distributed under the same license as the original - unmodified zlib/libpng license
// Header from the original source code follows below:
//*******************************************************************************************
//
// raylib [core] example - custom frame control
//
// NOTE: WARNING: This is an example for advance users willing to have full control over
// the frame processes. By default, EndDrawing() calls the following processes:
// 1. Draw remaining batch data: rlDrawRenderBatchActive()
// 2. SwapScreenBuffer()
// 3. Frame time control: WaitTime()
// 4. PollInputEvents()
//
// To avoid steps 2, 3 and 4, flag SUPPORT_CUSTOM_FRAME_CONTROL can be enabled in
// config.h (it requires recompiling raylib). This way those steps are up to the user.
//
// Note that enabling this flag invalidates some functions:
// - GetFrameTime()
// - SetTargetFPS()
// - GetFPS()
//
// Example originally created with raylib 4.0, last time updated with raylib 4.0
//
// Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
// BSD-like license that allows static linking with closed source software
//
// Copyright (c) 2021-2023 Ramon Santamaria (@raysan5)
//
//********************************************************************************************
const c = @cImport(
{
@cInclude("raylib.h");
});
pub fn main() void
{
const screenWidth = 800;
const screenHeight = 450;
c.InitWindow(screenWidth, screenHeight, "raylib [core] example - custom frame control");
defer c.CloseWindow(); // Close window and OpenGL context
// Custom timming variables
var prev_time: f64 = c.GetTime(); // Previous time measure
var cur_time: f64 = 0.0; // Current time measure
var update_draw_time: f64 = 0.0; // Update + Draw time
var wait_time: f64 = 0.0; // Wait time (if target fps required)
var delta_time: f32 = 0.0; // Frame time (Update + Draw + Wait time)
var time_counter: f32 = 0.0; // Accumulative time counter (seconds)
var position: f32 = 0.0; // Circle position
var pause = false; // Pause control flag
var target_fps: i32 = 60; // Our initial target fps
//--------------------------------------------------------------------------------------
while (!c.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
c.PollInputEvents(); // Poll input events (SUPPORT_CUSTOM_FRAME_CONTROL)
if (c.IsKeyPressed(c.KEY_SPACE)) pause = !pause;
if (c.IsKeyPressed(c.KEY_UP)) { target_fps += 20; }
else if (c.IsKeyPressed(c.KEY_DOWN)) target_fps -= 20;
if (target_fps < 0) target_fps = 0;
if (!pause)
{
position += 200 * delta_time; // We move at 200 pixels per second
if (@as(c_int, @intFromFloat(position)) >= c.GetScreenWidth()) position = 0.0;
time_counter += delta_time; // We count time (seconds)
}
//----------------------------------------------------------------------------------
// Draw
//---------------------------------------------------------------------------------
{
c.BeginDrawing();
defer c.EndDrawing();
c.ClearBackground(c.RAYWHITE);
// @intCast -> usize
for (0..@intCast(@divTrunc(c.GetScreenWidth(), 200))) |i|
c.DrawRectangle(200 * @as(c_int, @intCast(i)), 0, 1, c.GetScreenHeight(), c.SKYBLUE);
c.DrawCircle(@intFromFloat(position), @divTrunc(c.GetScreenHeight(), 2) - 25, 50, c.RED);
c.DrawText(c.TextFormat("%03.0f ms", time_counter * 1000.0),
@as(c_int, @intFromFloat(position)) - 40,
@divTrunc(c.GetScreenHeight(), 2) - 100, 20, c.MAROON);
c.DrawText(c.TextFormat("PosX: %03.0f", position),
@as(c_int, @intFromFloat(position)) - 50,
@divTrunc(c.GetScreenHeight(), 2) + 40, 20, c.BLACK);
c.DrawText("Circle is moving at a constant 200 pixels/sec,\nindependently of the frame rate.", 10, 10, 20, c.DARKGRAY);
c.DrawText("PRESS SPACE to PAUSE MOVEMENT", 10, c.GetScreenHeight() - 60, 20, c.GRAY);
c.DrawText("PRESS UP | DOWN to CHANGE TARGET FPS", 10, c.GetScreenHeight() - 30, 20, c.GRAY);
c.DrawText(c.TextFormat("TARGET FPS: %i", target_fps), c.GetScreenWidth() - 220, 10, 20, c.LIME);
// -- This code causes Zig compiler (0.11.0-dev.3859+88284c124) to segfault, see
// -- https://github.com/ziglang/zig/issues/16197
//c.DrawText(c.TextFormat("CURRENT FPS: %i",
// if (delta_time == 0.0) 0 else @intFromFloat(1.0 / delta_time)),
// c.GetScreenWidth() - 220, 40, 20, c.GREEN);
const fps: c_int = if (delta_time == 0.0) 0 else @intFromFloat(1.0 / delta_time);
c.DrawText(c.TextFormat("CURRENT FPS: %i", fps), c.GetScreenWidth() - 220, 40, 20, c.GREEN);
}
// NOTE: In case raylib is configured to SUPPORT_CUSTOM_FRAME_CONTROL,
// Events polling, screen buffer swap and frame time control must be managed by the user
c.SwapScreenBuffer(); // Flip the back buffer to screen (front buffer)
cur_time = c.GetTime();
update_draw_time = cur_time - prev_time;
if (target_fps > 0) // We want a fixed frame rate
{
wait_time = (1.0 / @as(f64, @floatFromInt(target_fps))) - update_draw_time;
if (wait_time > 0.0)
{
c.WaitTime(wait_time);
cur_time = c.GetTime();
delta_time = @floatCast(cur_time - prev_time); // @floatCast -> f32
}
}
else // @floatCast -> f32
delta_time = @floatCast(update_draw_time); // Framerate could be variable
prev_time = cur_time;
//---------------------------------------------------------------------------------
}
}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-27-core-custom-frame-control/build.sh | #!/bin/sh
tmp_raylib_include_path=''
tmp_raylib_external_include_path=''
tmp_raylib_lib_path=''
tmp_raylib_zig_build_mode=''
# No command line arguments => use local variables
if [ $# -eq 0 ]; then
echo
echo 'Using locally defined build variables and paths'
# Set the paths here if you invoke this build.sh manually
tmp_raylib_path='~/ray'
tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include"
tmp_raylib_external_include_path="${tmp_raylib_path}/src/external"
tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib"
# One of:
# -O Debug
# -O ReleaseFast
# -O ReleaseSafe
# -O ReleaseSmall
tmp_raylib_zig_build_mode='-O ReleaseSmall'
else
# Using variables set in ../build_example.sh
tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH
tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH
tmp_raylib_lib_path=$RAYLIB_LIB_PATH
tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE
fi
tmp_raylib_include_arg=''
if [ -n "$tmp_raylib_include_path" ]; then # Not empty
tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}"
fi
if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty
tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}"
fi
#echo 'tmp_raylib_include_arg = '
#echo "$tmp_raylib_include_arg"
tmp_raylib_lib_arg=''
if [ -n "$tmp_raylib_lib_path" ]; then # Not empty
tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib"
else
tmp_raylib_lib_arg='-lc -lraylib'
fi
#echo 'tmp_raylib_lib_arg = '
#echo "$tmp_raylib_lib_arg"
echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}"
zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-27-core-custom-frame-control/build.bat | @echo off
REM First parameter not set = build.bat launched manually
if "%~1"=="" (
echo.
echo Using locally defined build variables and paths
setlocal enableDelayedExpansion
REM These values are used if you invoke this build.bat file manualy.
REM If you use build_example.bat in the root folder, values set in that file are used.
SET RAYLIB_PATH=D:\libs\raylib-4.5.0
SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include
SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external
SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib
REM One of:
REM -O Debug
REM -O ReleaseFast
REM -O ReleaseSafe
REM -O ReleaseSmall
SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall
)
REM echo RAYLIB_PATH: %RAYLIB_PATH%
REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH%
REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH%
REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH%
REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE%
@echo on
zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc
@echo off
REM End local variables scope if not called from the main script
if "%~1"=="" (
endlocal & (
SET RAYLIB_PATH=%RAYLIB_PATH%
SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH%
SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH%
SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH%
SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE%
)
)
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-27-core-custom-frame-control/clean.bat | del main.exe
del main.exe.obj
del main.pdb
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-72-text-font-loading/clean.sh | rm ./main
rm ./main.o
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-72-text-font-loading/main.zig | // build with `zig build-exe main.zig -lc -lraylib`
// This is a Zig version of a raylib example from
// https://github.com/raysan5/raylib/
// It is distributed under the same license as the original - unmodified zlib/libpng license
// Header from the original source code follows below:
///*******************************************************************************************
//*
//* raylib [text] example - Font loading
//*
//* NOTE: raylib can load fonts from multiple input file formats:
//*
//* - TTF/OTF > Sprite font atlas is generated on loading, user can configure
//* some of the generation parameters (size, characters to include)
//* - BMFonts > Angel code font fileformat, sprite font image must be provided
//* together with the .fnt file, font generation cna not be configured
//* - XNA Spritefont > Sprite font image, following XNA Spritefont conventions,
//* Characters in image must follow some spacing and order rules
//*
//* Example originally created with raylib 1.4, last time updated with raylib 3.0
//*
//* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
//* BSD-like license that allows static linking with closed source software
//*
//* Copyright (c) 2016-2023 Ramon Santamaria (@raysan5)
//*
//********************************************************************************************/
const c = @cImport(
{
@cInclude("raylib.h");
});
pub fn main() void
{
const screen_width = 800;
const screen_height = 450;
c.InitWindow(screen_width, screen_height, "raylib [text] example - font loading");
defer c.CloseWindow(); // Close window and OpenGL context
// Define characters to draw
// NOTE: raylib supports UTF-8 encoding, following list is actually codified as UTF8 internally
const msg: [*:0]const u8 = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI\nJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmn\nopqrstuvwxyz{|}~¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓ\nÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷\nøùúûüýþÿ";
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
// BMFont (AngelCode) : Font data and image atlas have been generated using external program
const font_bm = c.LoadFont("resources/pixantiqua.fnt"); // c.Font
defer c.UnloadFont(font_bm);
// TTF font : Font data and atlas are generated directly from TTF
// NOTE: We define a font base size of 32 pixels tall and up-to 250 characters
const font_ttf = c.LoadFontEx("resources/pixantiqua.ttf", 32, 0, 250); // c.Font
defer c.UnloadFont(font_ttf);
var use_ttf = false;
c.SetTargetFPS(60);
while (!c.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
if (c.IsKeyDown(c.KEY_SPACE))
{ use_ttf = true; }
else
use_ttf = false;
//----------------------------------------------------------------------------------
// Draw
//---------------------------------------------------------------------------------
c.BeginDrawing();
defer c.EndDrawing();
c.ClearBackground(c.RAYWHITE);
c.DrawText("Hold SPACE to use TTF generated font", 20, 20, 20, c.LIGHTGRAY);
if (!use_ttf)
{
c.DrawTextEx(font_bm, msg, .{ .x = 20.0, .y = 100.0 },
@floatFromInt(font_bm.baseSize), 2, c.MAROON);
c.DrawText("Using BMFont (Angelcode) imported", 20, c.GetScreenHeight() - 30, 20, c.GRAY);
}
else
{
c.DrawTextEx(font_ttf, msg, .{ .x = 20.0, .y = 100.0 },
@floatFromInt(font_ttf.baseSize), 2, c.LIME);
c.DrawText("Using TTF font generated", 20, c.GetScreenHeight() - 30, 20, c.GRAY);
}
//---------------------------------------------------------------------------------
}
}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-72-text-font-loading/build.sh | #!/bin/sh
tmp_raylib_include_path=''
tmp_raylib_external_include_path=''
tmp_raylib_lib_path=''
tmp_raylib_zig_build_mode=''
# No command line arguments => use local variables
if [ $# -eq 0 ]; then
echo
echo 'Using locally defined build variables and paths'
# Set the paths here if you invoke this build.sh manually
tmp_raylib_path='~/ray'
tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include"
tmp_raylib_external_include_path="${tmp_raylib_path}/src/external"
tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib"
# One of:
# -O Debug
# -O ReleaseFast
# -O ReleaseSafe
# -O ReleaseSmall
tmp_raylib_zig_build_mode='-O ReleaseSmall'
else
# Using variables set in ../build_example.sh
tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH
tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH
tmp_raylib_lib_path=$RAYLIB_LIB_PATH
tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE
fi
tmp_raylib_include_arg=''
if [ -n "$tmp_raylib_include_path" ]; then # Not empty
tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}"
fi
if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty
tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}"
fi
#echo 'tmp_raylib_include_arg = '
#echo "$tmp_raylib_include_arg"
tmp_raylib_lib_arg=''
if [ -n "$tmp_raylib_lib_path" ]; then # Not empty
tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib"
else
tmp_raylib_lib_arg='-lc -lraylib'
fi
#echo 'tmp_raylib_lib_arg = '
#echo "$tmp_raylib_lib_arg"
echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}"
zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-72-text-font-loading/build.bat | @echo off
REM First parameter not set = build.bat launched manually
if "%~1"=="" (
echo.
echo Using locally defined build variables and paths
setlocal enableDelayedExpansion
REM These values are used if you invoke this build.bat file manualy.
REM If you use build_example.bat in the root folder, values set in that file are used.
SET RAYLIB_PATH=D:\libs\raylib-4.5.0
SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include
SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external
SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib
REM One of:
REM -O Debug
REM -O ReleaseFast
REM -O ReleaseSafe
REM -O ReleaseSmall
SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall
)
REM echo RAYLIB_PATH: %RAYLIB_PATH%
REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH%
REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH%
REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH%
REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE%
@echo on
zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc
@echo off
REM End local variables scope if not called from the main script
if "%~1"=="" (
endlocal & (
SET RAYLIB_PATH=%RAYLIB_PATH%
SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH%
SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH%
SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH%
SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE%
)
)
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-72-text-font-loading/clean.bat | del main.exe
del main.exe.obj
del main.pdb
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-93-models-orthographic-projection/clean.sh | rm ./main
rm ./main.o
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-93-models-orthographic-projection/main.zig | // build with `zig build-exe main.zig -lc -lraylib`
// This is a Zig version of a raylib example from
// https://github.com/raysan5/raylib/
// It is distributed under the same license as the original - unmodified zlib/libpng license
// Header from the original source code follows below:
///*******************************************************************************************
//*
//* raylib [models] example - Show the difference between perspective and orthographic projection
//*
//* Example originally created with raylib 2.0, last time updated with raylib 3.7
//*
//* Example contributed by Max Danielsson (@autious) and reviewed by Ramon Santamaria (@raysan5)
//*
//* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
//* BSD-like license that allows static linking with closed source software
//*
//* Copyright (c) 2018-2023 Max Danielsson (@autious) and Ramon Santamaria (@raysan5)
//*
//********************************************************************************************/
const c = @cImport(
{
@cInclude("raylib.h");
});
pub fn main() void
{
const screen_width = 800;
const screen_height = 450;
const fovy_perspective = 45.0;
const width_orthographic = 10.0;
c.InitWindow(screen_width, screen_height, "raylib [models] example - orthographic projection");
defer c.CloseWindow(); // Close window and OpenGL context
// Define the camera to look into our 3d world
var camera = c.Camera3D
{
.position = .{ .x = 0.0, .y = 10.0, .z = 10.0 }, // Camera position
.target = .{ .x = 0.0, .y = 0.0, .z = 0.0 }, // Camera looking at point
.up = .{ .x = 0.0, .y = 1.0, .z = 0.0 }, // Camera up vector (rotation towards target)
.fovy = fovy_perspective, // Camera field-of-view Y
.projection = c.CAMERA_PERSPECTIVE // Camera mode type
};
c.SetTargetFPS(60);
while (!c.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
if (c.IsKeyPressed(c.KEY_SPACE))
{
if (camera.projection == c.CAMERA_PERSPECTIVE)
{
camera.fovy = width_orthographic;
camera.projection = c.CAMERA_ORTHOGRAPHIC;
}
else
{
camera.fovy = fovy_perspective;
camera.projection = c.CAMERA_PERSPECTIVE;
}
}
//----------------------------------------------------------------------------------
// Draw
//---------------------------------------------------------------------------------
c.BeginDrawing();
defer c.EndDrawing();
c.ClearBackground(c.RAYWHITE);
{
c.BeginMode3D(camera);
defer c.EndMode3D();
c.DrawCube(.{.x = -4.0, .y = 0.0, .z = 2.0}, 2.0, 5.0, 2.0, c.RED);
c.DrawCubeWires(.{.x = -4.0, .y = 0.0, .z = 2.0}, 2.0, 5.0, 2.0, c.GOLD);
c.DrawCubeWires(.{.x = -4.0, .y = 0.0, .z = -2.0}, 3.0, 6.0, 2.0, c.MAROON);
c.DrawSphere(.{.x = -1.0, .y = 0.0, .z = -2.0}, 1.0, c.GREEN);
c.DrawSphereWires(.{.x = 1.0, .y = 0.0, .z = 2.0}, 2.0, 16, 16, c.LIME);
c.DrawCylinder(.{.x = 4.0, .y = 0.0, .z = -2.0}, 1.0, 2.0, 3.0, 4, c.SKYBLUE);
c.DrawCylinderWires(.{.x = 4.0, .y = 0.0, .z = -2.0}, 1.0, 2.0, 3.0, 4, c.DARKBLUE);
c.DrawCylinderWires(.{.x = 4.5, .y = -1.0, .z = 2.0}, 1.0, 1.0, 2.0, 6, c.BROWN);
c.DrawCylinder(.{.x = 1.0, .y = 0.0, .z = -4.0}, 0.0, 1.5, 3.0, 8, c.GOLD);
c.DrawCylinderWires(.{.x = 1.0, .y = 0.0, .z = -4.0}, 0.0, 1.5, 3.0, 8, c.PINK);
c.DrawCapsule (.{.x = -3.0, .y = 1.5, .z = -4.0}, .{.x = -4.0, .y = -1.0, .z = -4.0}, 1.2, 8, 8, c.VIOLET);
c.DrawCapsuleWires(.{.x = -3.0, .y = 1.5, .z = -4.0}, .{.x = -4.0, .y = -1.0, .z = -4.0}, 1.2, 8, 8, c.PURPLE);
c.DrawGrid(10, 1.0); // Draw a grid
}
c.DrawText("Press Spacebar to switch camera type", 10, c.GetScreenHeight() - 30, 20, c.DARKGRAY);
if (camera.projection == c.CAMERA_ORTHOGRAPHIC)
{ c.DrawText("ORTHOGRAPHIC", 10, 40, 20, c.BLACK); }
else
if (camera.projection == c.CAMERA_PERSPECTIVE)
c.DrawText("PERSPECTIVE", 10, 40, 20, c.BLACK);
c.DrawFPS(10, 10);
//---------------------------------------------------------------------------------
}
}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-93-models-orthographic-projection/build.sh | #!/bin/sh
tmp_raylib_include_path=''
tmp_raylib_external_include_path=''
tmp_raylib_lib_path=''
tmp_raylib_zig_build_mode=''
# No command line arguments => use local variables
if [ $# -eq 0 ]; then
echo
echo 'Using locally defined build variables and paths'
# Set the paths here if you invoke this build.sh manually
tmp_raylib_path='~/ray'
tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include"
tmp_raylib_external_include_path="${tmp_raylib_path}/src/external"
tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib"
# One of:
# -O Debug
# -O ReleaseFast
# -O ReleaseSafe
# -O ReleaseSmall
tmp_raylib_zig_build_mode='-O ReleaseSmall'
else
# Using variables set in ../build_example.sh
tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH
tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH
tmp_raylib_lib_path=$RAYLIB_LIB_PATH
tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE
fi
tmp_raylib_include_arg=''
if [ -n "$tmp_raylib_include_path" ]; then # Not empty
tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}"
fi
if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty
tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}"
fi
#echo 'tmp_raylib_include_arg = '
#echo "$tmp_raylib_include_arg"
tmp_raylib_lib_arg=''
if [ -n "$tmp_raylib_lib_path" ]; then # Not empty
tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib"
else
tmp_raylib_lib_arg='-lc -lraylib'
fi
#echo 'tmp_raylib_lib_arg = '
#echo "$tmp_raylib_lib_arg"
echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}"
zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-93-models-orthographic-projection/build.bat | @echo off
REM First parameter not set = build.bat launched manually
if "%~1"=="" (
echo.
echo Using locally defined build variables and paths
setlocal enableDelayedExpansion
REM These values are used if you invoke this build.bat file manualy.
REM If you use build_example.bat in the root folder, values set in that file are used.
SET RAYLIB_PATH=D:\libs\raylib-4.5.0
SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include
SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external
SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib
REM One of:
REM -O Debug
REM -O ReleaseFast
REM -O ReleaseSafe
REM -O ReleaseSmall
SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall
)
REM echo RAYLIB_PATH: %RAYLIB_PATH%
REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH%
REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH%
REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH%
REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE%
@echo on
zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc
@echo off
REM End local variables scope if not called from the main script
if "%~1"=="" (
endlocal & (
SET RAYLIB_PATH=%RAYLIB_PATH%
SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH%
SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH%
SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH%
SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE%
)
)
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-93-models-orthographic-projection/clean.bat | del main.exe
del main.exe.obj
del main.pdb
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-01-core-basic-window/clean.sh | rm ./main
rm ./main.o
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-01-core-basic-window/main.zig | // build with `zig build-exe main.zig -lc -lraylib`
// This is a Zig version of a raylib example from
// https://github.com/raysan5/raylib/
// It is distributed under the same license as the original - unmodified zlib/libpng license
// Header from the original source code follows below:
///*******************************************************************************************
//*
//* raylib [core] example - Basic window
//*
//* Welcome to raylib!
//*
//* To test examples, just press F6 and execute raylib_compile_execute script
//* Note that compiled executable is placed in the same folder as .c file
//*
//* You can find all basic examples on C:\raylib\raylib\examples folder or
//* raylib official webpage: www.raylib.com
//*
//* Enjoy using raylib. :)
//*
//* Example originally created with raylib 1.0, last time updated with raylib 1.0
//*
//* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
//* BSD-like license that allows static linking with closed source software
//*
//* Copyright (c) 2013-2023 Ramon Santamaria (@raysan5)
//*
//********************************************************************************************/
const ray = @cImport(
{
@cInclude("raylib.h");
});
pub fn main() void
{
const screen_width = 800;
const screen_height = 450;
ray.InitWindow(screen_width, screen_height, "raylib [core] example - basic window");
defer ray.CloseWindow(); // Close window and OpenGL context
ray.SetTargetFPS(60); // Set our game to run at 60 frames-per-second
while (!ray.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
ray.BeginDrawing();
defer ray.EndDrawing();
ray.ClearBackground(ray.RAYWHITE);
ray.DrawText("Congrats! You created your first window!", 190, 200, 20, ray.LIGHTGRAY);
//----------------------------------------------------------------------------------
}
}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-01-core-basic-window/build.sh | #!/bin/sh
tmp_raylib_include_path=''
tmp_raylib_external_include_path=''
tmp_raylib_lib_path=''
tmp_raylib_zig_build_mode=''
# No command line arguments => use local variables
if [ $# -eq 0 ]; then
echo
echo 'Using locally defined build variables and paths'
# Set the paths here if you invoke this build.sh manually
tmp_raylib_path='~/ray'
tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include"
tmp_raylib_external_include_path="${tmp_raylib_path}/src/external"
tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib"
# One of:
# -O Debug
# -O ReleaseFast
# -O ReleaseSafe
# -O ReleaseSmall
tmp_raylib_zig_build_mode='-O ReleaseSmall'
else
# Using variables set in ../build_example.sh
tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH
tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH
tmp_raylib_lib_path=$RAYLIB_LIB_PATH
tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE
fi
tmp_raylib_include_arg=''
if [ -n "$tmp_raylib_include_path" ]; then # Not empty
tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}"
fi
if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty
tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}"
fi
#echo 'tmp_raylib_include_arg = '
#echo "$tmp_raylib_include_arg"
tmp_raylib_lib_arg=''
if [ -n "$tmp_raylib_lib_path" ]; then # Not empty
tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib"
else
tmp_raylib_lib_arg='-lc -lraylib'
fi
#echo 'tmp_raylib_lib_arg = '
#echo "$tmp_raylib_lib_arg"
echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}"
zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-01-core-basic-window/build.bat | @echo off
REM First parameter not set = build.bat launched manually
if "%~1"=="" (
echo.
echo Using locally defined build variables and paths
setlocal enableDelayedExpansion
REM These values are used if you invoke this build.bat file manualy.
REM If you use build_example.bat in the root folder, values set in that file are used.
SET RAYLIB_PATH=D:\libs\raylib-4.5.0
SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include
SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external
SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib
REM One of:
REM -O Debug
REM -O ReleaseFast
REM -O ReleaseSafe
REM -O ReleaseSmall
SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall
)
REM echo RAYLIB_PATH: %RAYLIB_PATH%
REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH%
REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH%
REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH%
REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE%
@echo on
zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc
@echo off
REM End local variables scope if not called from the main script
if "%~1"=="" (
endlocal & (
SET RAYLIB_PATH=%RAYLIB_PATH%
SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH%
SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH%
SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH%
SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE%
)
)
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-01-core-basic-window/clean.bat | del main.exe
del main.exe.obj
del main.pdb
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-75-text-input-box/clean.sh | rm ./main
rm ./main.o
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-75-text-input-box/main.zig | // build with `zig build-exe main.zig -lc -lraylib`
// This is a Zig version of a raylib example from
// https://github.com/raysan5/raylib/
// It is distributed under the same license as the original - unmodified zlib/libpng license
// Header from the original source code follows below:
///*******************************************************************************************
//*
//* raylib [text] example - Input Box
//*
//* Example originally created with raylib 1.7, last time updated with raylib 3.5
//*
//* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
//* BSD-like license that allows static linking with closed source software
//*
//* Copyright (c) 2017-2023 Ramon Santamaria (@raysan5)
//*
//********************************************************************************************/
const c = @cImport(
{
@cInclude("raylib.h");
});
pub fn main() void
{
const screen_width = 800;
const screen_height = 450;
const max_input_chars = 9;
c.InitWindow(screen_width, screen_height, "raylib [text] example - input box");
defer c.CloseWindow(); // Close window and OpenGL context
// NOTE: One extra space required for null terminator char '\0'
var name = [_]u8{ 0 } ** (max_input_chars + 1);
var letter_count: usize = 0;
const text_box = c.Rectangle{ .x = screen_width / 2.0 - 100.0, .y = 180.0,
.width = 225.0, .height = 50.0 };
var mouse_on_text = false;
var frames_counter: usize = 0;
c.SetTargetFPS(10); // Set our game to run at 10 frames-per-second
while (!c.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
if (c.CheckCollisionPointRec(c.GetMousePosition(), text_box))
{ mouse_on_text = true; }
else
mouse_on_text = false;
if (mouse_on_text)
{
// Set the window's cursor to the I-Beam
c.SetMouseCursor(c.MOUSE_CURSOR_IBEAM);
// Get char pressed (unicode character) on the queue
var key = c.GetCharPressed();
// Check if more characters have been pressed on the same frame
while (key > 0)
{
// NOTE: Only allow keys in range [32..125]
if ((key >= 32) and (key <= 125) and (letter_count < max_input_chars))
{
name[letter_count] = @intCast(key); // u8
name[letter_count + 1] = '\x00'; // Add null terminator at the end of the string.
letter_count += 1;
}
key = c.GetCharPressed(); // Check next character in the queue
}
if (c.IsKeyPressed(c.KEY_BACKSPACE))
{
//letter_count -= 1;
//if (letter_count < 0)
// letter_count = 0;
// We want letter_count to be usize, since it's used to index in name array.
// Because of this, the logic has to be changed - we can't decrement first,
// check if letter_count is below 0 later, since letter_count is unsigned.
if (letter_count > 0)
letter_count -= 1;
name[letter_count] = '\x00';
}
}
else c.SetMouseCursor(c.MOUSE_CURSOR_DEFAULT);
if (mouse_on_text)
{ frames_counter += 1; }
else
frames_counter = 0;
//----------------------------------------------------------------------------------
// Draw
//---------------------------------------------------------------------------------
c.BeginDrawing();
defer c.EndDrawing();
c.ClearBackground(c.RAYWHITE);
c.DrawText("PLACE MOUSE OVER INPUT BOX!", 240, 140, 20, c.GRAY);
c.DrawRectangleRec(text_box, c.LIGHTGRAY);
if (mouse_on_text)
{
c.DrawRectangleLines(@intFromFloat(text_box.x), @intFromFloat(text_box.y),
@intFromFloat(text_box.width), @intFromFloat(text_box.height),
c.RED);
}
else
c.DrawRectangleLines(@intFromFloat(text_box.x), @intFromFloat(text_box.y),
@intFromFloat(text_box.width), @intFromFloat(text_box.height),
c.DARKGRAY);
c.DrawText(&name, @as(c_int, @intFromFloat(text_box.x)) + 5, @as(c_int, @intFromFloat(text_box.y)) + 8, 40, c.MAROON);
c.DrawText(c.TextFormat("INPUT CHARS: %i/%i", letter_count, @as(i32, max_input_chars)), 315, 250, 20, c.DARKGRAY);
if (mouse_on_text)
{
if (letter_count < max_input_chars)
{
// Draw blinking underscore char
if (((frames_counter/20)%2) == 0)
c.DrawText("_", @as(c_int, @intFromFloat(text_box.x)) + 8 + c.MeasureText(&name, 40),
@as(c_int, @intFromFloat(text_box.y)) + 12, 40, c.MAROON);
}
else
c.DrawText("Press BACKSPACE to delete chars...", 230, 300, 20, c.GRAY);
}
//---------------------------------------------------------------------------------
}
}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-75-text-input-box/build.sh | #!/bin/sh
tmp_raylib_include_path=''
tmp_raylib_external_include_path=''
tmp_raylib_lib_path=''
tmp_raylib_zig_build_mode=''
# No command line arguments => use local variables
if [ $# -eq 0 ]; then
echo
echo 'Using locally defined build variables and paths'
# Set the paths here if you invoke this build.sh manually
tmp_raylib_path='~/ray'
tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include"
tmp_raylib_external_include_path="${tmp_raylib_path}/src/external"
tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib"
# One of:
# -O Debug
# -O ReleaseFast
# -O ReleaseSafe
# -O ReleaseSmall
tmp_raylib_zig_build_mode='-O ReleaseSmall'
else
# Using variables set in ../build_example.sh
tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH
tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH
tmp_raylib_lib_path=$RAYLIB_LIB_PATH
tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE
fi
tmp_raylib_include_arg=''
if [ -n "$tmp_raylib_include_path" ]; then # Not empty
tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}"
fi
if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty
tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}"
fi
#echo 'tmp_raylib_include_arg = '
#echo "$tmp_raylib_include_arg"
tmp_raylib_lib_arg=''
if [ -n "$tmp_raylib_lib_path" ]; then # Not empty
tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib"
else
tmp_raylib_lib_arg='-lc -lraylib'
fi
#echo 'tmp_raylib_lib_arg = '
#echo "$tmp_raylib_lib_arg"
echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}"
zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-75-text-input-box/build.bat | @echo off
REM First parameter not set = build.bat launched manually
if "%~1"=="" (
echo.
echo Using locally defined build variables and paths
setlocal enableDelayedExpansion
REM These values are used if you invoke this build.bat file manualy.
REM If you use build_example.bat in the root folder, values set in that file are used.
SET RAYLIB_PATH=D:\libs\raylib-4.5.0
SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include
SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external
SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib
REM One of:
REM -O Debug
REM -O ReleaseFast
REM -O ReleaseSafe
REM -O ReleaseSmall
SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall
)
REM echo RAYLIB_PATH: %RAYLIB_PATH%
REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH%
REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH%
REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH%
REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE%
@echo on
zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc
@echo off
REM End local variables scope if not called from the main script
if "%~1"=="" (
endlocal & (
SET RAYLIB_PATH=%RAYLIB_PATH%
SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH%
SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH%
SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH%
SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE%
)
)
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-75-text-input-box/clean.bat | del main.exe
del main.exe.obj
del main.pdb
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-08-core-2d-camera/clean.sh | rm ./main
rm ./main.o
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-08-core-2d-camera/main.zig | // build with `zig build-exe main.zig -lc -lraylib`
// This is a Zig version of a raylib example from
// https://github.com/raysan5/raylib/
// It is distributed under the same license as the original - unmodified zlib/libpng license
// Header from the original source code follows below:
///*******************************************************************************************
//*
//* raylib [core] example - 2d camera
//*
//* Example originally created with raylib 1.5, last time updated with raylib 3.0
//*
//* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
//* BSD-like license that allows static linking with closed source software
//*
//* Copyright (c) 2016-2023 Ramon Santamaria (@raysan5)
//*
//********************************************************************************************/
const c = @cImport(
{
@cInclude("raylib.h");
});
pub fn main() void
{
const screen_width = 800;
const screen_height = 450;
const max_buildings = 100;
c.InitWindow(screen_width, screen_height, "raylib [core] example - 2d camera");
defer c.CloseWindow(); // Close window and OpenGL context
var player = c.Rectangle{ .x = 400.0, .y = 280.0, .width = 40.0, .height = 40.0 };
var buildings = [_]c.Rectangle{ .{ .x = 0.0, .y = 0.0, .width = 0.0, .height = 0.0 } } ** max_buildings;
var build_colors = [_]c.Color{ .{ .r = 0, .g = 0, .b = 0, .a = 0 } } ** max_buildings;
// comptime
// error: comptime call of extern function
// buildings[i].width = @as(f32, c.GetRandomValue(50, 200));
// ~~~~~~~~~~~~~~~~^~~~~~~~~
{
var spacing: i32 = 0;
for (0..max_buildings) |i|
{
buildings[i].width = @floatFromInt(c.GetRandomValue(50, 200));
buildings[i].height = @floatFromInt(c.GetRandomValue(100, 800));
buildings[i].y = screen_height - 130.0 - buildings[i].height;
buildings[i].x = -6000.0 + @as(f32, @floatFromInt(spacing));
spacing += @intFromFloat(buildings[i].width);
build_colors[i] = c.Color
{
.r = @intCast(c.GetRandomValue(200, 240)), // u8
.g = @intCast(c.GetRandomValue(200, 240)), // u8
.b = @intCast(c.GetRandomValue(200, 250)), // u8
.a = 255
};
}
}
var camera = c.Camera2D
{
.target = .{ .x = player.x + 20.0, .y = player.y + 20.0 }, // c.Vector2
.offset = .{ .x = screen_width / 2.0, .y = screen_height / 2.0 }, // c.Vector2
.rotation = 0.0,
.zoom = 1.0,
};
c.SetTargetFPS(60);
while (!c.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// Player movement
if (c.IsKeyDown(c.KEY_RIGHT))
{ player.x += 2; }
else
if (c.IsKeyDown(c.KEY_LEFT))
player.x -= 2;
// Camera target follows player
camera.target = .{ .x = player.x + 20.0, .y = player.y + 20.0 };
// Camera rotation controls
if (c.IsKeyDown(c.KEY_A))
{ camera.rotation -= 1.0; }
else
if (c.IsKeyDown(c.KEY_S))
camera.rotation += 1.0;
// Limit camera rotation to 80 degrees (-40 to 40)
if (camera.rotation > 40)
{ camera.rotation = 40; }
else
if (camera.rotation < -40)
camera.rotation = -40;
// Camera zoom controls
camera.zoom += c.GetMouseWheelMove() * 0.05;
if (camera.zoom > 3.0)
{ camera.zoom = 3.0; }
else
if (camera.zoom < 0.1)
camera.zoom = 0.1;
// Camera reset (zoom and rotation)
if (c.IsKeyPressed(c.KEY_R))
{
camera.zoom = 1.0;
camera.rotation = 0.0;
}
//----------------------------------------------------------------------------------
// Draw
//---------------------------------------------------------------------------------
{
c.BeginDrawing();
defer c.EndDrawing();
c.ClearBackground(c.RAYWHITE);
{
c.BeginMode2D(camera);
defer c.EndMode2D();
c.DrawRectangle(-6000, 320, 13000, 8000, c.DARKGRAY);
for (buildings, build_colors) |bldng, clr|
c.DrawRectangleRec(bldng, clr);
// Player character box
c.DrawRectangleRec(player, c.RED);
c.DrawLine(@intFromFloat(camera.target.x), -screen_height*10,
@intFromFloat(camera.target.x), screen_height*10, c.GREEN);
c.DrawLine(-screen_width*10, @intFromFloat(camera.target.y),
screen_width*10, @intFromFloat(camera.target.y), c.GREEN);
}
c.DrawText("SCREEN AREA", 640, 10, 20, c.RED);
// Viewport outline
c.DrawRectangle(0, 0, screen_width, 5, c.RED);
c.DrawRectangle(0, 5, 5, screen_height - 10, c.RED);
c.DrawRectangle(screen_width - 5, 5, 5, screen_height - 10, c.RED);
c.DrawRectangle(0, screen_height - 5, screen_width, 5, c.RED);
// Info pane
c.DrawRectangle(10, 10, 250, 113, c.Fade(c.SKYBLUE, 0.5));
c.DrawRectangleLines(10, 10, 250, 113, c.BLUE);
c.DrawText("Free 2d camera controls:", 20, 20, 10, c.BLACK);
c.DrawText("- Right/Left to move Offset", 40, 40, 10, c.DARKGRAY);
c.DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, c.DARKGRAY);
c.DrawText("- A / S to Rotate", 40, 80, 10, c.DARKGRAY);
c.DrawText("- R to reset Zoom and Rotation", 40, 100, 10, c.DARKGRAY);
}
//---------------------------------------------------------------------------------
}
}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-08-core-2d-camera/build.sh | #!/bin/sh
tmp_raylib_include_path=''
tmp_raylib_external_include_path=''
tmp_raylib_lib_path=''
tmp_raylib_zig_build_mode=''
# No command line arguments => use local variables
if [ $# -eq 0 ]; then
echo
echo 'Using locally defined build variables and paths'
# Set the paths here if you invoke this build.sh manually
tmp_raylib_path='~/ray'
tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include"
tmp_raylib_external_include_path="${tmp_raylib_path}/src/external"
tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib"
# One of:
# -O Debug
# -O ReleaseFast
# -O ReleaseSafe
# -O ReleaseSmall
tmp_raylib_zig_build_mode='-O ReleaseSmall'
else
# Using variables set in ../build_example.sh
tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH
tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH
tmp_raylib_lib_path=$RAYLIB_LIB_PATH
tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE
fi
tmp_raylib_include_arg=''
if [ -n "$tmp_raylib_include_path" ]; then # Not empty
tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}"
fi
if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty
tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}"
fi
#echo 'tmp_raylib_include_arg = '
#echo "$tmp_raylib_include_arg"
tmp_raylib_lib_arg=''
if [ -n "$tmp_raylib_lib_path" ]; then # Not empty
tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib"
else
tmp_raylib_lib_arg='-lc -lraylib'
fi
#echo 'tmp_raylib_lib_arg = '
#echo "$tmp_raylib_lib_arg"
echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}"
zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-08-core-2d-camera/build.bat | @echo off
REM First parameter not set = build.bat launched manually
if "%~1"=="" (
echo.
echo Using locally defined build variables and paths
setlocal enableDelayedExpansion
REM These values are used if you invoke this build.bat file manualy.
REM If you use build_example.bat in the root folder, values set in that file are used.
SET RAYLIB_PATH=D:\libs\raylib-4.5.0
SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include
SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external
SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib
REM One of:
REM -O Debug
REM -O ReleaseFast
REM -O ReleaseSafe
REM -O ReleaseSmall
SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall
)
REM echo RAYLIB_PATH: %RAYLIB_PATH%
REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH%
REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH%
REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH%
REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE%
@echo on
zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc
@echo off
REM End local variables scope if not called from the main script
if "%~1"=="" (
endlocal & (
SET RAYLIB_PATH=%RAYLIB_PATH%
SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH%
SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH%
SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH%
SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE%
)
)
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-08-core-2d-camera/clean.bat | del main.exe
del main.exe.obj
del main.pdb
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-45-shapes-top-down_lights/clean.sh | rm ./main
rm ./main.o
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-45-shapes-top-down_lights/main.zig | // build with `zig build-exe main.zig -lc -lraylib`
// This is a Zig version of a raylib example from
// https://github.com/raysan5/raylib/
// It is distributed under the same license as the original - unmodified zlib/libpng license
// Header from the original source code follows below:
///*******************************************************************************************
//*
//* raylib [shapes] example - top down lights
//*
//* Example originally created with raylib 4.2, last time updated with raylib 4.2
//*
//* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5)
//*
//* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
//* BSD-like license that allows static linking with closed source software
//*
//* Copyright (c) 2022-2023 Jeffery Myers (@JeffM2501)
//*
//********************************************************************************************/
const c = @cImport(
{
@cInclude("raylib.h");
@cInclude("raymath.h");
@cInclude("rlgl.h");
});
// Custom Blend Modes
const rlgl_src_alpha = 0x0302;
const rlgl_min = 0x8007;
const rlgl_max = 0x8008;
const max_boxes = 20;
const max_shadows = max_boxes * 3; // max_boxes *3. Each box can cast up to two shadow volumes for the edges it is away from, and one for the box itself
const max_lights = 16;
// Shadow geometry type
const ShadowGeometry = struct
{
vertices: [4]c.Vector2,
fn init() ShadowGeometry
{
return .{ .vertices = [_]c.Vector2{ .{ .x = 0.0, .y = 0.0 } } ** 4 };
}
};
// Light info type
const LightInfo = struct
{
active: bool, // Is this light slot active?
dirty: bool, // Does this light need to be updated?
valid: bool, // Is this light in a valid position?
position: c.Vector2, // Light position
mask: c.RenderTexture, // Alpha mask for the light
outer_radius: f32, // The distance the light touches
bounds: c.Rectangle, // A cached rectangle of the light bounds to help with culling
shadows: [max_shadows]ShadowGeometry,
shadowCount: u32,
fn init() LightInfo
{
return
.{
.active = false,
.dirty = false,
.valid = false,
.position = .{ .x = 0.0, .y = 0.0 },
.mask =
.{
.id = 0,
.texture = .{ .id = 0, .width = 0, .height = 0, .mipmaps = 0, .format = 0 },
.depth = .{ .id = 0, .width = 0, .height = 0, .mipmaps = 0, .format = 0 }
},
.outer_radius = 0,
.bounds = .{ .x = 0.0, .y = 0.0, .width = 0.0, .height = 0.0 },
.shadows = [_]ShadowGeometry{ ShadowGeometry.init() } ** max_shadows,
.shadowCount = 0
};
}
};
var lights = [_]LightInfo{ LightInfo.init() } ** max_lights;
pub fn main() void
{
const screen_width = 800;
const screen_height = 450;
c.InitWindow(screen_width, screen_height, "raylib [shapes] example - top down lights");
defer c.CloseWindow(); // Close window and OpenGL context
// Initialize our 'world' of boxes
const box_count = max_boxes; // Why do we need this?
var boxes: [max_boxes]c.Rectangle = undefined; //= comptime setupBoxes(box_count);
setupBoxes(boxes[0..max_boxes]);
// Create a checkerboard ground texture
const img = c.GenImageChecked(64, 64, 32, 32, c.DARKBROWN, c.DARKGRAY); // c.Image
const background_texture = c.LoadTextureFromImage(img); // c.Texture2D
defer c.UnloadTexture(background_texture);
c.UnloadImage(img);
// Create a global light mask to hold all the blended lights
const light_mask = c.LoadRenderTexture(c.GetScreenWidth(), c.GetScreenHeight()); // c.RenderTexture
defer c.UnloadRenderTexture(light_mask);
// Setup initial light
setupLight(0, 600, 400, 300);
defer
for (lights) |light|
if (light.active)
c.UnloadRenderTexture(light.mask);
var next_light: u32 = 1;
var show_lines = false;
c.SetTargetFPS(60);
while (!c.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// Drag light 0
if (c.IsMouseButtonDown(c.MOUSE_BUTTON_LEFT))
moveLight(0, c.GetMousePosition().x, c.GetMousePosition().y);
// Make a new light
if (c.IsMouseButtonPressed(c.MOUSE_BUTTON_RIGHT) and (next_light < max_lights))
{
setupLight(next_light, c.GetMousePosition().x, c.GetMousePosition().y, 200);
next_light += 1;
}
// Toggle debug info
if (c.IsKeyPressed(c.KEY_F1))
show_lines = !show_lines;
// Update the lights and keep track if any were dirty so we know if we need to update the master light mask
var dirtyLights = false;
for (0..max_lights) |i|
{
if (updateLight(@intCast(i), boxes[0..max_boxes])) // @intCast -> u32
dirtyLights = true;
}
// Update the light mask
if (dirtyLights)
{
// Build up the light mask
c.BeginTextureMode(light_mask);
defer c.EndTextureMode();
c.ClearBackground(c.BLACK);
// Force the blend mode to only set the alpha of the destination
c.rlSetBlendFactors(rlgl_src_alpha, rlgl_src_alpha, rlgl_min);
c.rlSetBlendMode(c.BLEND_CUSTOM);
// Merge in all the light masks
for (0..max_lights) |i|
{
if (lights[i].active)
c.DrawTextureRec(lights[i].mask.texture,
.{ .x = 0, .y = 0,
.width = @floatFromInt(c.GetScreenWidth()), .height = @floatFromInt(-c.GetScreenHeight()) },
c.Vector2Zero(), c.WHITE);
}
c.rlDrawRenderBatchActive();
// Go back to normal blend
c.rlSetBlendMode(c.BLEND_ALPHA);
}
//----------------------------------------------------------------------------------
// Draw
//---------------------------------------------------------------------------------
c.BeginDrawing();
defer c.EndDrawing();
c.ClearBackground(c.BLACK);
// Draw the tile background
c.DrawTextureRec(background_texture,
.{ .x = 0.0, .y = 0.0,
.width = @floatFromInt(c.GetScreenWidth()),
.height = @floatFromInt(c.GetScreenHeight()) },
c.Vector2Zero(), c.WHITE);
// Overlay the shadows from all the lights
c.DrawTextureRec(light_mask.texture,
.{ .x = 0.0, .y = 0.0,
.width = @floatFromInt(c.GetScreenWidth()),
.height = @floatFromInt(-c.GetScreenHeight()) },
c.Vector2Zero(), c.ColorAlpha(c.WHITE, if (show_lines) 0.75 else 1.0));
// Draw the lights
for (0..max_lights) |i|
if (lights[i].active)
c.DrawCircle(@intFromFloat(lights[i].position.x),
@intFromFloat(lights[i].position.y), 10,
if (i == 0) c.YELLOW else c.WHITE);
if (show_lines)
{
for (0..lights[0].shadowCount) |s|
c.DrawTriangleFan(&lights[0].shadows[s].vertices, 4, c.DARKPURPLE);
for (0..box_count) |b|
{
if (c.CheckCollisionRecs(boxes[b], lights[0].bounds))
c.DrawRectangleRec(boxes[b], c.PURPLE);
c.DrawRectangleLines(@intFromFloat(boxes[b].x), @intFromFloat(boxes[b].y),
@intFromFloat(boxes[b].width), @intFromFloat(boxes[b].height),
c.DARKBLUE);
}
c.DrawText("(F1) Hide Shadow Volumes", 10, 50, 10, c.GREEN);
}
else
c.DrawText("(F1) Show Shadow Volumes", 10, 50, 10, c.GREEN);
c.DrawFPS(screen_width - 80, 10);
c.DrawText("Drag to move light #1", 10, 10, 10, c.DARKGREEN);
c.DrawText("Right click to add new light", 10, 30, 10, c.DARKGREEN);
//---------------------------------------------------------------------------------
}
}
// Set up some boxes
fn setupBoxes(boxes: []c.Rectangle) void
{
// boxes.len must be >= 5
boxes[0] = .{ .x = 150.0, .y = 80.0, .width = 40.0, .height = 40.0 };
boxes[1] = .{ .x = 1200.0, .y = 700.0, .width = 40.0, .height = 40.0 };
boxes[2] = .{ .x = 200.0, .y = 600.0, .width = 40.0, .height = 40.0 };
boxes[3] = .{ .x = 1000.0, .y = 50.0, .width = 40.0, .height = 40.0 };
boxes[4] = .{ .x = 500.0, .y = 350.0, .width = 40.0, .height = 40.0 };
for (5..boxes.len) |i|
{
boxes[i] =
.{
.x = @floatFromInt(c.GetRandomValue(0, c.GetScreenWidth())),
.y = @floatFromInt(c.GetRandomValue(0, c.GetScreenHeight())),
.width = @floatFromInt(c.GetRandomValue(10, 100)),
.height = @floatFromInt(c.GetRandomValue(10, 100))
};
}
}
// Setup a light
fn setupLight(slot: u32, x: f32, y: f32, radius: f32) void
{
lights[slot].active = true;
lights[slot].valid = false; // The light must prove it is valid
lights[slot].mask = c.LoadRenderTexture(c.GetScreenWidth(), c.GetScreenHeight());
lights[slot].outer_radius = radius;
lights[slot].bounds.width = radius * 2;
lights[slot].bounds.height = radius * 2;
moveLight(slot, x, y);
// Force the render texture to have something in it
drawLightMask(slot);
}
// Move a light and mark it as dirty so that we update it's mask next frame
fn moveLight(slot: u32, x: f32, y: f32) void
{
lights[slot].dirty = true;
lights[slot].position.x = x;
lights[slot].position.y = y;
// update the cached bounds
lights[slot].bounds.x = x - lights[slot].outer_radius;
lights[slot].bounds.y = y - lights[slot].outer_radius;
}
// See if a light needs to update its mask
fn updateLight(slot: u32, boxes: []c.Rectangle) bool
{
if (!lights[slot].active or !lights[slot].dirty)
return false;
lights[slot].dirty = false;
lights[slot].shadowCount = 0;
lights[slot].valid = false;
for (boxes) |box|
{
// Are we in a box? if so we are not valid
if (c.CheckCollisionPointRec(lights[slot].position, box))
return false;
// If this box is outside our bounds, we can skip it
if (!c.CheckCollisionRecs(lights[slot].bounds, box))
continue;
// Check the edges that are on the same side we are, and cast shadow volumes out from them
// Top
var sp = c.Vector2{ .x = box.x, .y = box.y };
var ep = c.Vector2{ .x = box.x + box.width, .y = box.y };
if (lights[slot].position.y > ep.y)
computeShadowVolumeForEdge(slot, sp, ep);
// Right
sp = ep;
ep.y += box.height;
if (lights[slot].position.x < ep.x)
computeShadowVolumeForEdge(slot, sp, ep);
// Bottom
sp = ep;
ep.x -= box.width;
if (lights[slot].position.y < ep.y)
computeShadowVolumeForEdge(slot, sp, ep);
// Left
sp = ep;
ep.y -= box.height;
if (lights[slot].position.x > ep.x)
computeShadowVolumeForEdge(slot, sp, ep);
// The box itself
lights[slot].shadows[lights[slot].shadowCount].vertices[0] = .{ .x = box.x, .y = box.y };
lights[slot].shadows[lights[slot].shadowCount].vertices[1] = .{ .x = box.x, .y = box.y + box.height };
lights[slot].shadows[lights[slot].shadowCount].vertices[2] = .{ .x = box.x + box.width, .y = box.y + box.height };
lights[slot].shadows[lights[slot].shadowCount].vertices[3] = .{ .x = box.x + box.width, .y = box.y };
lights[slot].shadowCount += 1;
}
lights[slot].valid = true;
drawLightMask(slot);
return true;
}
// Compute a shadow volume for the edge
// It takes the edge and projects it back by the light radius and turns it into a quad
fn computeShadowVolumeForEdge(slot: u32, sp: c.Vector2, ep: c.Vector2) void
{
if (lights[slot].shadowCount >= max_shadows)
return;
const extension = lights[slot].outer_radius * 2.0;
const sp_vector = c.Vector2Normalize(c.Vector2Subtract(sp, lights[slot].position)); // c.Vector2
const sp_projection = c.Vector2Add(sp, c.Vector2Scale(sp_vector, extension)); // c.Vector2
const ep_vector = c.Vector2Normalize(c.Vector2Subtract(ep, lights[slot].position)); // c.Vector2
const ep_projection = c.Vector2Add(ep, c.Vector2Scale(ep_vector, extension)); // c.Vector2
lights[slot].shadows[lights[slot].shadowCount].vertices[0] = sp;
lights[slot].shadows[lights[slot].shadowCount].vertices[1] = ep;
lights[slot].shadows[lights[slot].shadowCount].vertices[2] = ep_projection;
lights[slot].shadows[lights[slot].shadowCount].vertices[3] = sp_projection;
lights[slot].shadowCount += 1;
}
// Draw the light and shadows to the mask for a light
fn drawLightMask(slot: u32) void
{
// Use the light mask
c.BeginTextureMode(lights[slot].mask);
defer c.EndTextureMode();
c.ClearBackground(c.WHITE);
// Force the blend mode to only set the alpha of the destination
c.rlSetBlendFactors(rlgl_src_alpha, rlgl_src_alpha, rlgl_min);
c.rlSetBlendMode(c.BLEND_CUSTOM);
// If we are valid, then draw the light radius to the alpha mask
if (lights[slot].valid)
c.DrawCircleGradient(@intFromFloat(lights[slot].position.x),
@intFromFloat(lights[slot].position.y),
lights[slot].outer_radius, c.ColorAlpha(c.WHITE, 0), c.WHITE);
c.rlDrawRenderBatchActive();
// Cut out the shadows from the light radius by forcing the alpha to maximum
c.rlSetBlendMode(c.BLEND_ALPHA);
c.rlSetBlendFactors(rlgl_src_alpha, rlgl_src_alpha, rlgl_max);
c.rlSetBlendMode(c.BLEND_CUSTOM);
// Draw the shadows to the alpha mask
for (0..lights[slot].shadowCount) |i|
c.DrawTriangleFan(&lights[slot].shadows[i].vertices, 4, c.WHITE);
c.rlDrawRenderBatchActive();
// Go back to normal blend mode
c.rlSetBlendMode(c.BLEND_ALPHA);
}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-45-shapes-top-down_lights/build.sh | #!/bin/sh
tmp_raylib_include_path=''
tmp_raylib_external_include_path=''
tmp_raylib_lib_path=''
tmp_raylib_zig_build_mode=''
# No command line arguments => use local variables
if [ $# -eq 0 ]; then
echo
echo 'Using locally defined build variables and paths'
# Set the paths here if you invoke this build.sh manually
tmp_raylib_path='~/ray'
tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include"
tmp_raylib_external_include_path="${tmp_raylib_path}/src/external"
tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib"
# One of:
# -O Debug
# -O ReleaseFast
# -O ReleaseSafe
# -O ReleaseSmall
tmp_raylib_zig_build_mode='-O ReleaseSmall'
else
# Using variables set in ../build_example.sh
tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH
tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH
tmp_raylib_lib_path=$RAYLIB_LIB_PATH
tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE
fi
tmp_raylib_include_arg=''
if [ -n "$tmp_raylib_include_path" ]; then # Not empty
tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}"
fi
if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty
tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}"
fi
#echo 'tmp_raylib_include_arg = '
#echo "$tmp_raylib_include_arg"
tmp_raylib_lib_arg=''
if [ -n "$tmp_raylib_lib_path" ]; then # Not empty
tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib"
else
tmp_raylib_lib_arg='-lc -lraylib'
fi
#echo 'tmp_raylib_lib_arg = '
#echo "$tmp_raylib_lib_arg"
echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}"
zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-45-shapes-top-down_lights/build.bat | @echo off
REM First parameter not set = build.bat launched manually
if "%~1"=="" (
echo.
echo Using locally defined build variables and paths
setlocal enableDelayedExpansion
REM These values are used if you invoke this build.bat file manualy.
REM If you use build_example.bat in the root folder, values set in that file are used.
SET RAYLIB_PATH=D:\libs\raylib-4.5.0
SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include
SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external
SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib
REM One of:
REM -O Debug
REM -O ReleaseFast
REM -O ReleaseSafe
REM -O ReleaseSmall
SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall
)
REM echo RAYLIB_PATH: %RAYLIB_PATH%
REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH%
REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH%
REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH%
REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE%
@echo on
zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc
@echo off
REM End local variables scope if not called from the main script
if "%~1"=="" (
endlocal & (
SET RAYLIB_PATH=%RAYLIB_PATH%
SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH%
SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH%
SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH%
SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE%
)
)
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-45-shapes-top-down_lights/clean.bat | del main.exe
del main.exe.obj
del main.pdb
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-37-shapes-collision-area/clean.sh | rm ./main
rm ./main.o
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-37-shapes-collision-area/main.zig | // build with `zig build-exe main.zig -lc -lraylib`
// This is a Zig version of a raylib example from
// https://github.com/raysan5/raylib/
// It is distributed under the same license as the original - unmodified zlib/libpng license
// Header from the original source code follows below:
///*******************************************************************************************
//*
//* raylib [shapes] example - collision area
//*
//* Example originally created with raylib 2.5, last time updated with raylib 2.5
//*
//* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
//* BSD-like license that allows static linking with closed source software
//*
//* Copyright (c) 2013-2023 Ramon Santamaria (@raysan5)
//*
//********************************************************************************************/
const c = @cImport(
{
@cInclude("raylib.h");
});
pub fn main() void
{
const screen_width = 800;
const screen_height = 450;
c.InitWindow(screen_width, screen_height, "raylib [shapes] example - collision area");
defer c.CloseWindow(); // Close window and OpenGL context
// Box A: Moving box
var box_a = c.Rectangle{ .x = 10.0, .y = @as(f32, @floatFromInt(c.GetScreenHeight())) / 2.0 - 50.0, .width = 200.0, .height = 100.0 };
var box_a_speed_x: i32 = 4;
// Box B: Mouse moved box
var box_b = c.Rectangle{ .x = @as(f32, @floatFromInt(c.GetScreenWidth())) / 2.0 - 30.0, .y = @as(f32, @floatFromInt(c.GetScreenHeight())) / 2.0 - 30.0, .width = 60.0, .height = 60.0 };
var box_collision = c.Rectangle{ .x = 0.0, .y = 0.0, .width = 0.0, .height = 0.0 }; // Collision rectangle
const screen_upper_limit = 40; // Top menu limits
var pause = false; // Movement pause
var collision = false; // Collision detection
c.SetTargetFPS(60);
while (!c.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// Move box if not paused
if (!pause)
box_a.x += @floatFromInt(box_a_speed_x);
// Bounce box on x screen limits
if (((box_a.x + box_a.width) >= @as(f32, @floatFromInt(c.GetScreenWidth()))) or (box_a.x <= 0.0))
box_a_speed_x = -box_a_speed_x;
// Update player-controlled-box (box02)
box_b.x = @as(f32, @floatFromInt(c.GetMouseX())) - box_b.width / 2.0;
box_b.y = @as(f32, @floatFromInt(c.GetMouseY())) - box_b.height / 2.0;
// Make sure Box B does not go out of move area limits
if ((box_b.x + box_b.width) >= @as(f32, @floatFromInt(c.GetScreenWidth())))
{ box_b.x = @as(f32, @floatFromInt(c.GetScreenWidth())) - box_b.width; }
else
if (box_b.x <= 0.0)
box_b.x = 0.0;
if ((box_b.y + box_b.height) >= @as(f32, @floatFromInt(c.GetScreenHeight())))
{ box_b.y = @as(f32, @floatFromInt(c.GetScreenHeight())) - box_b.height; }
else
if (box_b.y <= screen_upper_limit)
box_b.y = screen_upper_limit;
// Check boxes collision
collision = c.CheckCollisionRecs(box_a, box_b);
// Get collision rectangle (only on collision)
if (collision)
box_collision = c.GetCollisionRec(box_a, box_b);
// Pause Box A movement
if (c.IsKeyPressed(c.KEY_SPACE)) pause = !pause;
//----------------------------------------------------------------------------------
// Draw
//---------------------------------------------------------------------------------
c.BeginDrawing();
defer c.EndDrawing();
c.ClearBackground(c.RAYWHITE);
c.DrawRectangle(0, 0, screen_width, screen_upper_limit, if (collision) c.RED else c.BLACK);
c.DrawRectangleRec(box_a, c.GOLD);
c.DrawRectangleRec(box_b, c.BLUE);
if (collision)
{
// Draw collision area
c.DrawRectangleRec(box_collision, c.LIME);
// Draw collision message
c.DrawText("COLLISION!", @divTrunc(c.GetScreenWidth(), 2) - @divTrunc(c.MeasureText("COLLISION!", 20), 2), screen_upper_limit / 2 - 10, 20, c.BLACK);
// Draw collision area
c.DrawText(c.TextFormat("Collision Area: %i",
@as(c_int, @intFromFloat(box_collision.width)) * @as(c_int, @intFromFloat(box_collision.height))),
@divTrunc(c.GetScreenWidth(), 2) - 100, screen_upper_limit + 10, 20, c.BLACK);
}
c.DrawFPS(10, 10);
//---------------------------------------------------------------------------------
}
}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-37-shapes-collision-area/build.sh | #!/bin/sh
tmp_raylib_include_path=''
tmp_raylib_external_include_path=''
tmp_raylib_lib_path=''
tmp_raylib_zig_build_mode=''
# No command line arguments => use local variables
if [ $# -eq 0 ]; then
echo
echo 'Using locally defined build variables and paths'
# Set the paths here if you invoke this build.sh manually
tmp_raylib_path='~/ray'
tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include"
tmp_raylib_external_include_path="${tmp_raylib_path}/src/external"
tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib"
# One of:
# -O Debug
# -O ReleaseFast
# -O ReleaseSafe
# -O ReleaseSmall
tmp_raylib_zig_build_mode='-O ReleaseSmall'
else
# Using variables set in ../build_example.sh
tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH
tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH
tmp_raylib_lib_path=$RAYLIB_LIB_PATH
tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE
fi
tmp_raylib_include_arg=''
if [ -n "$tmp_raylib_include_path" ]; then # Not empty
tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}"
fi
if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty
tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}"
fi
#echo 'tmp_raylib_include_arg = '
#echo "$tmp_raylib_include_arg"
tmp_raylib_lib_arg=''
if [ -n "$tmp_raylib_lib_path" ]; then # Not empty
tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib"
else
tmp_raylib_lib_arg='-lc -lraylib'
fi
#echo 'tmp_raylib_lib_arg = '
#echo "$tmp_raylib_lib_arg"
echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}"
zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-37-shapes-collision-area/build.bat | @echo off
REM First parameter not set = build.bat launched manually
if "%~1"=="" (
echo.
echo Using locally defined build variables and paths
setlocal enableDelayedExpansion
REM These values are used if you invoke this build.bat file manualy.
REM If you use build_example.bat in the root folder, values set in that file are used.
SET RAYLIB_PATH=D:\libs\raylib-4.5.0
SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include
SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external
SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib
REM One of:
REM -O Debug
REM -O ReleaseFast
REM -O ReleaseSafe
REM -O ReleaseSmall
SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall
)
REM echo RAYLIB_PATH: %RAYLIB_PATH%
REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH%
REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH%
REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH%
REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE%
@echo on
zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc
@echo off
REM End local variables scope if not called from the main script
if "%~1"=="" (
endlocal & (
SET RAYLIB_PATH=%RAYLIB_PATH%
SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH%
SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH%
SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH%
SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE%
)
)
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-37-shapes-collision-area/clean.bat | del main.exe
del main.exe.obj
del main.pdb
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-30-shapes-basic-shapes/clean.sh | rm ./main
rm ./main.o
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-30-shapes-basic-shapes/main.zig | // build with `zig build-exe main.zig -lc -lraylib`
// This is a Zig version of a raylib example from
// https://github.com/raysan5/raylib/
// It is distributed under the same license as the original - unmodified zlib/libpng license
// Header from the original source code follows below:
///*******************************************************************************************
//*
//* raylib [shapes] example - Draw basic shapes 2d (rectangle, circle, line...)
//*
//* Example originally created with raylib 1.0, last time updated with raylib 4.2
//*
//* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,an5)
//* BSD-like license that allows static linking with closed source software
//*
//* Copyright (c) 2014-2023 Ramon Santamaria (@raysan5)
//*
//********************************************************************************************/
const c = @cImport(
{
@cInclude("raylib.h");
});
pub fn main() void
{
const screen_width = 800;
const screen_height = 450;
c.InitWindow(screen_width, screen_height, "raylib [shapes] example - basic shapes drawing");
defer c.CloseWindow(); // Close window and OpenGL context
var rotation: f32 = 0.0;
c.SetTargetFPS(60);
while (!c.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
rotation += 0.2;
//----------------------------------------------------------------------------------
// Draw
//---------------------------------------------------------------------------------
c.BeginDrawing();
defer c.EndDrawing();
c.ClearBackground(c.RAYWHITE);
c.DrawText("some basic shapes available on raylib", 20, 20, 20, c.DARKGRAY);
// Circle shapes and lines
c.DrawCircle(screen_width/5, 120, 35, c.DARKBLUE);
c.DrawCircleGradient(screen_width/5, 220, 60, c.GREEN, c.SKYBLUE);
c.DrawCircleLines(screen_width/5, 340, 80, c.DARKBLUE);
// Rectangle shapes and lines
c.DrawRectangle(screen_width/4*2 - 60, 100, 120, 60, c.RED);
c.DrawRectangleGradientH(screen_width/4*2 - 90, 170, 180, 130, c.MAROON, c.GOLD);
c.DrawRectangleLines(screen_width/4*2 - 40, 320, 80, 60, c.ORANGE); // NOTE: Uses QUADS internally, not lines
// Triangle shapes and lines
c.DrawTriangle(.{ .x = screen_width/4.0 * 3.0, .y = 80.0 },
.{ .x = screen_width/4.0 * 3.0 - 60.0, .y = 150.0 },
.{ .x = screen_width/4.0 * 3.0 + 60.0, .y = 150.0 }, c.VIOLET);
c.DrawTriangleLines(.{ .x = screen_width/4.0 * 3.0, .y = 160.0 },
.{ .x = screen_width/4.0 * 3.0 - 20.0, .y = 230.0 },
.{ .x = screen_width/4.0 * 3.0 + 20.0, .y = 230.0 }, c.DARKBLUE);
// Polygon shapes and lines
c.DrawPoly(.{ .x = screen_width/4.0 * 3, .y = 330 }, 6, 80, rotation, c.BROWN);
c.DrawPolyLines(.{ .x = screen_width/4.0 * 3, .y = 330 }, 6, 90, rotation, c.BROWN);
c.DrawPolyLinesEx(.{ .x = screen_width/4.0 * 3, .y = 330 }, 6, 85, rotation, 6, c.BEIGE);
// NOTE: We draw all LINES based shapes together to optimize internal drawing,
// this way, all LINES are rendered in a single draw pass
c.DrawLine(18, 42, screen_width - 18, 42, c.BLACK);
//---------------------------------------------------------------------------------
}
}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-30-shapes-basic-shapes/build.sh | #!/bin/sh
tmp_raylib_include_path=''
tmp_raylib_external_include_path=''
tmp_raylib_lib_path=''
tmp_raylib_zig_build_mode=''
# No command line arguments => use local variables
if [ $# -eq 0 ]; then
echo
echo 'Using locally defined build variables and paths'
# Set the paths here if you invoke this build.sh manually
tmp_raylib_path='~/ray'
tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include"
tmp_raylib_external_include_path="${tmp_raylib_path}/src/external"
tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib"
# One of:
# -O Debug
# -O ReleaseFast
# -O ReleaseSafe
# -O ReleaseSmall
tmp_raylib_zig_build_mode='-O ReleaseSmall'
else
# Using variables set in ../build_example.sh
tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH
tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH
tmp_raylib_lib_path=$RAYLIB_LIB_PATH
tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE
fi
tmp_raylib_include_arg=''
if [ -n "$tmp_raylib_include_path" ]; then # Not empty
tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}"
fi
if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty
tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}"
fi
#echo 'tmp_raylib_include_arg = '
#echo "$tmp_raylib_include_arg"
tmp_raylib_lib_arg=''
if [ -n "$tmp_raylib_lib_path" ]; then # Not empty
tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib"
else
tmp_raylib_lib_arg='-lc -lraylib'
fi
#echo 'tmp_raylib_lib_arg = '
#echo "$tmp_raylib_lib_arg"
echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}"
zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-30-shapes-basic-shapes/build.bat | @echo off
REM First parameter not set = build.bat launched manually
if "%~1"=="" (
echo.
echo Using locally defined build variables and paths
setlocal enableDelayedExpansion
REM These values are used if you invoke this build.bat file manualy.
REM If you use build_example.bat in the root folder, values set in that file are used.
SET RAYLIB_PATH=D:\libs\raylib-4.5.0
SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include
SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external
SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib
REM One of:
REM -O Debug
REM -O ReleaseFast
REM -O ReleaseSafe
REM -O ReleaseSmall
SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall
)
REM echo RAYLIB_PATH: %RAYLIB_PATH%
REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH%
REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH%
REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH%
REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE%
@echo on
zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc
@echo off
REM End local variables scope if not called from the main script
if "%~1"=="" (
endlocal & (
SET RAYLIB_PATH=%RAYLIB_PATH%
SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH%
SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH%
SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH%
SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE%
)
)
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-30-shapes-basic-shapes/clean.bat | del main.exe
del main.exe.obj
del main.pdb
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-84-models-cubicmap/clean.sh | rm ./main
rm ./main.o
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-84-models-cubicmap/main.zig | // build with `zig build-exe main.zig -lc -lraylib`
// This is a Zig version of a raylib example from
// https://github.com/raysan5/raylib/
// It is distributed under the same license as the original - unmodified zlib/libpng license
// Header from the original source code follows below:
///*******************************************************************************************
//*
//* raylib [models] example - Cubicmap loading and drawing
//*
//* Example originally created with raylib 1.8, last time updated with raylib 3.5
//*
//* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
//* BSD-like license that allows static linking with closed source software
//*
//* Copyright (c) 2015-2023 Ramon Santamaria (@raysan5)
//*
//********************************************************************************************/
const c = @cImport(
{
@cInclude("raylib.h");
});
pub fn main() void
{
const screen_width = 800;
const screen_height = 450;
c.InitWindow(screen_width, screen_height, "raylib [models] example - cubesmap loading and drawing");
defer c.CloseWindow(); // Close window and OpenGL context
// Define the camera to look into our 3d world
var camera = c.Camera3D
{
.position = .{ .x = 16.0, .y = 14.0, .z = 16.0 }, // Camera position
.target = .{ .x = 0.0, .y = 0.0, .z = 0.0 }, // Camera looking at point
.up = .{ .x = 0.0, .y = 1.0, .z = 0.0 }, // Camera up vector (rotation towards target)
.fovy = 45.0, // Camera field-of-view Y
.projection = c.CAMERA_PERSPECTIVE // Camera mode type
};
const image = c.LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM) - c.Image
const cubicmap = c.LoadTextureFromImage(image); // Convert image to texture to display (VRAM) - c.Texture2D
const mesh = c.GenMeshCubicmap(image, .{ .x = 1.0, .y = 1.0, .z = 1.0 }); // c.Mesh
const model = c.LoadModelFromMesh(mesh); // c.Model
defer c.UnloadModel(model); // Unload map model
// NOTE: By default each cube is mapped to one part of texture atlas
const texture = c.LoadTexture("resources/cubicmap_atlas.png"); // Load map texture - c.Texture2D
defer c.UnloadTexture(texture); // Unload map texture
defer c.UnloadTexture(cubicmap); // Unload cubicmap texture
model.materials[0].maps[c.MATERIAL_MAP_DIFFUSE].texture = texture; // Set map diffuse texture
const map_pos = c.Vector3{ .x = -16.0, .y = 0.0, .z = -8.0 }; // Set model position
c.UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM
c.SetTargetFPS(60);
while (!c.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
c.UpdateCamera(&camera, c.CAMERA_ORBITAL);
//----------------------------------------------------------------------------------
// Draw
//---------------------------------------------------------------------------------
c.BeginDrawing();
defer c.EndDrawing();
c.ClearBackground(c.RAYWHITE);
{
c.BeginMode3D(camera);
defer c.EndMode3D();
c.DrawModel(model, map_pos, 1.0, c.WHITE);
}
c.DrawTextureEx(cubicmap, .{ .x = screen_width - @as(f32, @floatFromInt(cubicmap.width)) * 4.0 - 20.0, .y = 20.0 },
0.0, 4.0, c.WHITE);
c.DrawRectangleLines(screen_width - cubicmap.width * 4 - 20, 20, cubicmap.width * 4, cubicmap.height * 4, c.GREEN);
c.DrawText("cubicmap image used to", 658, 90, 10, c.GRAY);
c.DrawText("generate map 3d model", 658, 104, 10, c.GRAY);
c.DrawFPS(10, 10);
//---------------------------------------------------------------------------------
}
}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-84-models-cubicmap/build.sh | #!/bin/sh
tmp_raylib_include_path=''
tmp_raylib_external_include_path=''
tmp_raylib_lib_path=''
tmp_raylib_zig_build_mode=''
# No command line arguments => use local variables
if [ $# -eq 0 ]; then
echo
echo 'Using locally defined build variables and paths'
# Set the paths here if you invoke this build.sh manually
tmp_raylib_path='~/ray'
tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include"
tmp_raylib_external_include_path="${tmp_raylib_path}/src/external"
tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib"
# One of:
# -O Debug
# -O ReleaseFast
# -O ReleaseSafe
# -O ReleaseSmall
tmp_raylib_zig_build_mode='-O ReleaseSmall'
else
# Using variables set in ../build_example.sh
tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH
tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH
tmp_raylib_lib_path=$RAYLIB_LIB_PATH
tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE
fi
tmp_raylib_include_arg=''
if [ -n "$tmp_raylib_include_path" ]; then # Not empty
tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}"
fi
if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty
tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}"
fi
#echo 'tmp_raylib_include_arg = '
#echo "$tmp_raylib_include_arg"
tmp_raylib_lib_arg=''
if [ -n "$tmp_raylib_lib_path" ]; then # Not empty
tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib"
else
tmp_raylib_lib_arg='-lc -lraylib'
fi
#echo 'tmp_raylib_lib_arg = '
#echo "$tmp_raylib_lib_arg"
echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}"
zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-84-models-cubicmap/build.bat | @echo off
REM First parameter not set = build.bat launched manually
if "%~1"=="" (
echo.
echo Using locally defined build variables and paths
setlocal enableDelayedExpansion
REM These values are used if you invoke this build.bat file manualy.
REM If you use build_example.bat in the root folder, values set in that file are used.
SET RAYLIB_PATH=D:\libs\raylib-4.5.0
SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include
SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external
SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib
REM One of:
REM -O Debug
REM -O ReleaseFast
REM -O ReleaseSafe
REM -O ReleaseSmall
SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall
)
REM echo RAYLIB_PATH: %RAYLIB_PATH%
REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH%
REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH%
REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH%
REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE%
@echo on
zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc
@echo off
REM End local variables scope if not called from the main script
if "%~1"=="" (
endlocal & (
SET RAYLIB_PATH=%RAYLIB_PATH%
SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH%
SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH%
SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH%
SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE%
)
)
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-84-models-cubicmap/clean.bat | del main.exe
del main.exe.obj
del main.pdb
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-77-text-rectangle-bounds/clean.sh | rm ./main
rm ./main.o
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-77-text-rectangle-bounds/main.zig | // build with `zig build-exe main.zig -lc -lraylib`
// This is a Zig version of a raylib example from
// https://github.com/raysan5/raylib/
// It is distributed under the same license as the original - unmodified zlib/libpng license
// Header from the original source code follows below:
///*******************************************************************************************
//*
//* raylib [text] example - Rectangle bounds
//*
//* Example originally created with raylib 2.5, last time updated with raylib 4.0
//*
//* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5)
//*
//* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
//* BSD-like license that allows static linking with closed source software
//*
//* Copyright (c) 2018-2023 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5)
//*
//********************************************************************************************/
const c = @cImport(
{
@cInclude("raylib.h");
});
pub fn main() void
{
const screen_width = 800;
const screen_height = 450;
c.InitWindow(screen_width, screen_height, "raylib [text] example - draw text inside a rectangle");
defer c.CloseWindow(); // Close window and OpenGL context
const text: [*:0]const u8 = "Text cannot escape\tthis container\t...word wrap also works when active so here's a long text for testing.\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Nec ullamcorper sit amet risus nullam eget felis eget.";
var resizing = false;
var word_wrap = true;
var container = c.Rectangle
{
.x = 25.0, .y = 25.0,
.width = screen_width - 50.0, .height = screen_height - 250.0
};
var resizer = c.Rectangle
{
.x = container.x + container.width - 17.0,
.y = container.y + container.height - 17.0,
.width = 14.0, .height = 14.0
};
// Minimum width and heigh for the container rectangle
const min_width = 60.0;
const min_height = 60.0;
const max_width = screen_width - 50.0;
const max_height = screen_height - 160.0;
var last_mouse = c.Vector2{ .x = 0.0, .y = 0.0 }; // Stores last mouse coordinates
var border_color: c.Color = c.MAROON; // Container border color
const font = c.GetFontDefault(); // Get default system font - c.Font
c.SetTargetFPS(60); // Set our game to run at 10 frames-per-second
while (!c.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
if (c.IsKeyPressed(c.KEY_SPACE))
word_wrap = !word_wrap;
const mouse = c.GetMousePosition(); // Vector2
// Check if the mouse is inside the container and toggle border color
if (c.CheckCollisionPointRec(mouse, container))
{ border_color = c.Fade(c.MAROON, 0.4); }
else
if (!resizing)
border_color = c.MAROON;
// Container resizing logic
if (resizing)
{
if (c.IsMouseButtonReleased(c.MOUSE_BUTTON_LEFT))
resizing = false;
const width = container.width + (mouse.x - last_mouse.x);
container.width = if (width > min_width) (if (width < max_width) width else max_width) else min_width;
const height = container.height + (mouse.y - last_mouse.y);
container.height = if (height > min_height) (if (height < max_height) height else max_height) else min_height;
}
else
{
// Check if we're resizing
if (c.IsMouseButtonDown(c.MOUSE_BUTTON_LEFT) and c.CheckCollisionPointRec(mouse, resizer))
resizing = true;
}
// Move resizer rectangle properly
resizer.x = container.x + container.width - 17.0;
resizer.y = container.y + container.height - 17.0;
last_mouse = mouse; // Update mouse
//----------------------------------------------------------------------------------
// Draw
//---------------------------------------------------------------------------------
c.BeginDrawing();
defer c.EndDrawing();
c.ClearBackground(c.RAYWHITE);
c.DrawRectangleLinesEx(container, 3, border_color); // Draw container border
// Draw text in container (add some padding)
DrawTextBoxed(font, text,
.{ .x = container.x + 4.0, .y = container.y + 4.0,
.width = container.width - 4.0, .height = container.height - 4.0 },
20.0, 2.0, word_wrap, c.GRAY);
c.DrawRectangleRec(resizer, border_color); // Draw the resize box
// Draw bottom info
c.DrawRectangle(0, screen_height - 54, screen_width, 54, c.GRAY);
c.DrawRectangleRec(.{ .x = 382.0, .y = screen_height - 34.0, .width = 12.0, .height = 12.0 }, c.MAROON);
c.DrawText("Word Wrap: ", 313, screen_height - 115, 20, c.BLACK);
if (word_wrap)
{ c.DrawText("ON", 447, screen_height - 115, 20, c.RED); }
else
c.DrawText("OFF", 447, screen_height - 115, 20, c.BLACK);
c.DrawText("Press [SPACE] to toggle word wrap", 218, screen_height - 86, 20, c.GRAY);
c.DrawText("Click hold & drag the to resize the container", 155, screen_height - 38, 20, c.RAYWHITE);
//---------------------------------------------------------------------------------
}
}
// Draw text using font inside rectangle limits
fn DrawTextBoxed(font: c.Font, text: [*c]const u8, rec: c.Rectangle,
font_size: f32, spacing: f32, word_wrap: bool, tint: c.Color) void
{
DrawTextBoxedSelectable(font, text, rec, font_size, spacing, word_wrap, tint, 0, 0, c.WHITE, c.WHITE);
}
// Draw text using font inside rectangle limits with support for text selection
fn DrawTextBoxedSelectable(font: c.Font, text: [*c]const u8, rec: c.Rectangle,
font_size: f32, spacing: f32, word_wrap: bool, tint: c.Color,
arg_select_start: i32, select_length: i32, select_tint: c.Color, select_back_tint: c.Color) void
{
var select_start = arg_select_start;
const length = c.TextLength(text); // Total length in bytes of the text, scanned by codepoints in loop
var text_offset_y: f32 = 0.0; // Offset between lines (on line break '\n')
var text_offset_x: f32 = 0.0; // Offset X to next character to draw
const scale_factor = font_size / @as(f32, @floatFromInt(font.baseSize)); // Character rectangle scaling factor
// Word/character wrapping mechanism variables
const State = enum { MEASURE_STATE, DRAW_STATE };
var state = if (word_wrap) State.MEASURE_STATE else State.DRAW_STATE;
var start_line: i32 = -1; // Index where to begin drawing (where a line begins)
var end_line: i32 = -1; // Index where to stop drawing (where a line ends)
var lastk: i32 = -1; // Holds last value of the character position
var i: i32 = 0;
var k: i32 = 0;
while (i < length) : (i += 1)
{
// Original C code increments both i and k in a single for statement:
// for (int i = 0, k = 0; i < length; i++, k++)
// Since i is modified in the for loop body (see below), we can't use
// for (0..length, 0..) |i, k|
defer k += 1;
// Get next codepoint from byte string and glyph index in font
var codepoint_byte_count: c_int = 0;
const codepoint = c.GetCodepoint(&text[@intCast(i)], &codepoint_byte_count); // @intCast -> usize
const index = c.GetGlyphIndex(font, codepoint);
// NOTE: Normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f)
// but we need to draw all of the bad bytes using the '?' symbol moving one byte
if (codepoint == 0x3F)
codepoint_byte_count = 1;
i += codepoint_byte_count - 1;
var glyph_width: f32 = 0.0;
if (codepoint != '\n')
{
glyph_width = if (font.glyphs[@intCast(index)].advanceX == 0) // @intCast -> usize
font.recs[@intCast(index)].width * scale_factor // @intCast -> usize
else
@as(f32, @floatFromInt(font.glyphs[@intCast(index)].advanceX)) * scale_factor; // @intCast -> usize
if (i + 1 < length)
glyph_width += spacing;
}
// NOTE: When wordWrap is ON we first measure how much of the text we can draw before going outside of the rec container
// We store this info in startLine and endLine, then we change states, draw the text between those two variables
// and change states again and again recursively until the end of the text (or until we get outside of the container).
// When wordWrap is OFF we don't need the measure state so we go to the drawing state immediately
// and begin drawing on the next line before we can get outside the container.
if (state == State.MEASURE_STATE)
{
// TODO: There are multiple types of spaces in UNICODE, maybe it's a good idea to add support for more
// Ref: http://jkorpela.fi/chars/spaces.html
if ((codepoint == ' ') or (codepoint == '\t') or (codepoint == '\n'))
end_line = i;
if ((text_offset_x + glyph_width) > rec.width)
{
if (end_line < 1) //end_line = if (end_line < 1) i else end_line; - why?
end_line = i;
if (i == end_line)
end_line -= codepoint_byte_count;
if ((start_line + codepoint_byte_count) == end_line)
end_line = i - codepoint_byte_count;
state = State.DRAW_STATE;
}
else
if ((i + 1) == length)
{
end_line = i;
state = State.DRAW_STATE;
}
else
if (codepoint == '\n')
state = State.DRAW_STATE;
if (state == State.DRAW_STATE)
{
text_offset_x = 0.0;
i = start_line;
glyph_width = 0.0;
// Save character position when we switch states
const tmp = lastk;
lastk = k - 1;
k = tmp;
}
}
else // !if (state == State.MEASURE_STATE)
{
if (codepoint == '\n')
{
if (!word_wrap)
{
text_offset_y += @as(f32, @floatFromInt((font.baseSize + @divTrunc(font.baseSize, 2)))) * scale_factor;
text_offset_x = 0.0;
}
}
else
{
if (!word_wrap and ((text_offset_x + glyph_width) > rec.width))
{
text_offset_y += @as(f32, @floatFromInt((font.baseSize + @divTrunc(font.baseSize, 2)))) * scale_factor;
text_offset_x = 0.0;
}
// When text overflows rectangle height limit, just stop drawing
if ((text_offset_y + @as(f32, @floatFromInt(font.baseSize)) * scale_factor) > rec.height)
break;
// Draw selection background
var is_glyph_selected = false;
if ((select_start >= 0) and (k >= select_start) and (k < (select_start + select_length)))
{
c.DrawRectangleRec(.{ .x = rec.x + text_offset_x - 1.0, .y = rec.y + text_offset_y,
.width = glyph_width, .height = @as(f32, @floatFromInt(font.baseSize)) * scale_factor },
select_back_tint);
is_glyph_selected = true;
}
// Draw current character glyph
if ((codepoint != ' ') and (codepoint != '\t'))
c.DrawTextCodepoint(font, codepoint,
.{ .x = rec.x + text_offset_x, .y = rec.y + text_offset_y },
font_size, if (is_glyph_selected) select_tint else tint);
}
if (word_wrap and (i == end_line))
{
text_offset_y += @as(f32, @floatFromInt((font.baseSize + @divTrunc(font.baseSize, 2)))) * scale_factor;
text_offset_x = 0.0;
start_line = end_line;
end_line = -1;
glyph_width = 0.0;
select_start += lastk - k;
k = lastk;
state = State.MEASURE_STATE;
}
} // !if (state == State.MEASURE_STATE)
if ((text_offset_x != 0.0) or (codepoint != ' '))
text_offset_x += glyph_width; // avoid leading spaces
}
}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-77-text-rectangle-bounds/build.sh | #!/bin/sh
tmp_raylib_include_path=''
tmp_raylib_external_include_path=''
tmp_raylib_lib_path=''
tmp_raylib_zig_build_mode=''
# No command line arguments => use local variables
if [ $# -eq 0 ]; then
echo
echo 'Using locally defined build variables and paths'
# Set the paths here if you invoke this build.sh manually
tmp_raylib_path='~/ray'
tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include"
tmp_raylib_external_include_path="${tmp_raylib_path}/src/external"
tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib"
# One of:
# -O Debug
# -O ReleaseFast
# -O ReleaseSafe
# -O ReleaseSmall
tmp_raylib_zig_build_mode='-O ReleaseSmall'
else
# Using variables set in ../build_example.sh
tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH
tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH
tmp_raylib_lib_path=$RAYLIB_LIB_PATH
tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE
fi
tmp_raylib_include_arg=''
if [ -n "$tmp_raylib_include_path" ]; then # Not empty
tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}"
fi
if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty
tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}"
fi
#echo 'tmp_raylib_include_arg = '
#echo "$tmp_raylib_include_arg"
tmp_raylib_lib_arg=''
if [ -n "$tmp_raylib_lib_path" ]; then # Not empty
tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib"
else
tmp_raylib_lib_arg='-lc -lraylib'
fi
#echo 'tmp_raylib_lib_arg = '
#echo "$tmp_raylib_lib_arg"
echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}"
zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-77-text-rectangle-bounds/build.bat | @echo off
REM First parameter not set = build.bat launched manually
if "%~1"=="" (
echo.
echo Using locally defined build variables and paths
setlocal enableDelayedExpansion
REM These values are used if you invoke this build.bat file manualy.
REM If you use build_example.bat in the root folder, values set in that file are used.
SET RAYLIB_PATH=D:\libs\raylib-4.5.0
SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include
SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external
SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib
REM One of:
REM -O Debug
REM -O ReleaseFast
REM -O ReleaseSafe
REM -O ReleaseSmall
SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall
)
REM echo RAYLIB_PATH: %RAYLIB_PATH%
REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH%
REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH%
REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH%
REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE%
@echo on
zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc
@echo off
REM End local variables scope if not called from the main script
if "%~1"=="" (
endlocal & (
SET RAYLIB_PATH=%RAYLIB_PATH%
SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH%
SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH%
SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH%
SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE%
)
)
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-77-text-rectangle-bounds/clean.bat | del main.exe
del main.exe.obj
del main.pdb
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-36-shapes-lines-bezier/clean.sh | rm ./main
rm ./main.o
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-36-shapes-lines-bezier/main.zig | // build with `zig build-exe main.zig -lc -lraylib`
// This is a Zig version of a raylib example from
// https://github.com/raysan5/raylib/
// It is distributed under the same license as the original - unmodified zlib/libpng license
// Header from the original source code follows below:
///*******************************************************************************************
//*
//* raylib [shapes] example - Cubic-bezier lines
//*
//* Example originally created with raylib 1.7, last time updated with raylib 1.7
//*
//* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
//* BSD-like license that allows static linking with closed source software
//*
//* Copyright (c) 2017-2023 Ramon Santamaria (@raysan5)
//*
//********************************************************************************************/
const c = @cImport(
{
@cInclude("raylib.h");
});
pub fn main() void
{
const screen_width = 800;
const screen_height = 450;
c.SetConfigFlags(c.FLAG_MSAA_4X_HINT);
c.InitWindow(screen_width, screen_height, "raylib [shapes] example - cubic-bezier lines");
defer c.CloseWindow(); // Close window and OpenGL context
var start = c.Vector2{ .x = 0.0, .y = 0.0 };
var end = c.Vector2{ .x = screen_width, .y = screen_height };
c.SetTargetFPS(60);
while (!c.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
if (c.IsMouseButtonDown(c.MOUSE_BUTTON_LEFT)) { start = c.GetMousePosition(); }
else if (c.IsMouseButtonDown(c.MOUSE_BUTTON_RIGHT)) end = c.GetMousePosition();
//----------------------------------------------------------------------------------
// Draw
//---------------------------------------------------------------------------------
c.BeginDrawing();
defer c.EndDrawing();
c.ClearBackground(c.RAYWHITE);
c.DrawText("USE MOUSE LEFT-RIGHT CLICK to DEFINE LINE START and END POINTS", 15, 20, 20, c.GRAY);
c.DrawLineBezier(start, end, 2.0, c.RED);
//---------------------------------------------------------------------------------
}
}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-36-shapes-lines-bezier/build.sh | #!/bin/sh
tmp_raylib_include_path=''
tmp_raylib_external_include_path=''
tmp_raylib_lib_path=''
tmp_raylib_zig_build_mode=''
# No command line arguments => use local variables
if [ $# -eq 0 ]; then
echo
echo 'Using locally defined build variables and paths'
# Set the paths here if you invoke this build.sh manually
tmp_raylib_path='~/ray'
tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include"
tmp_raylib_external_include_path="${tmp_raylib_path}/src/external"
tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib"
# One of:
# -O Debug
# -O ReleaseFast
# -O ReleaseSafe
# -O ReleaseSmall
tmp_raylib_zig_build_mode='-O ReleaseSmall'
else
# Using variables set in ../build_example.sh
tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH
tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH
tmp_raylib_lib_path=$RAYLIB_LIB_PATH
tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE
fi
tmp_raylib_include_arg=''
if [ -n "$tmp_raylib_include_path" ]; then # Not empty
tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}"
fi
if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty
tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}"
fi
#echo 'tmp_raylib_include_arg = '
#echo "$tmp_raylib_include_arg"
tmp_raylib_lib_arg=''
if [ -n "$tmp_raylib_lib_path" ]; then # Not empty
tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib"
else
tmp_raylib_lib_arg='-lc -lraylib'
fi
#echo 'tmp_raylib_lib_arg = '
#echo "$tmp_raylib_lib_arg"
echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}"
zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
|
0 | repos/raylib-zig-examples | repos/raylib-zig-examples/zig-raylib-36-shapes-lines-bezier/build.bat | @echo off
REM First parameter not set = build.bat launched manually
if "%~1"=="" (
echo.
echo Using locally defined build variables and paths
setlocal enableDelayedExpansion
REM These values are used if you invoke this build.bat file manualy.
REM If you use build_example.bat in the root folder, values set in that file are used.
SET RAYLIB_PATH=D:\libs\raylib-4.5.0
SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include
SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external
SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib
REM One of:
REM -O Debug
REM -O ReleaseFast
REM -O ReleaseSafe
REM -O ReleaseSmall
SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall
)
REM echo RAYLIB_PATH: %RAYLIB_PATH%
REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH%
REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH%
REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH%
REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE%
@echo on
zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc
@echo off
REM End local variables scope if not called from the main script
if "%~1"=="" (
endlocal & (
SET RAYLIB_PATH=%RAYLIB_PATH%
SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH%
SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH%
SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH%
SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE%
)
)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.