mirror of
https://github.com/Not-Nik/raylib-zig.git
synced 2025-09-08 19:47:28 +00:00
Bump to Zig 0.12/raylib 5.1-dev (#81)
* Update to Zig 0.12.0 and raylib 5.1-dev * More build.zig fixes for 0.12 * Get module with target and optimization * Add examples to build step when compiling for emscripten * Remove unused function * Add build.* and emcc.zig to the zon paths (#83) As per some info found through https://github.com/ziglang/zig/issues/18282, this is apparently necessary to use this library as a dependency. Co-authored-by: Drum Ogilvie <me@daogilvie.com> * Update binding
This commit is contained in:
parent
6eeb304ff3
commit
ae751ce82e
@ -92,9 +92,9 @@ Now add the modules and artifact to your target as you would normally:
|
||||
|
||||
```zig
|
||||
exe.linkLibrary(raylib_artifact);
|
||||
exe.addModule("raylib", raylib);
|
||||
exe.addModule("raylib-math", raylib_math);
|
||||
exe.addModule("rlgl", rlgl);
|
||||
exe.root_module.addImport("raylib", raylib);
|
||||
exe.root_module.addImport("raylib-math", raylib_math);
|
||||
exe.root_module.addImport("rlgl", rlgl);
|
||||
```
|
||||
|
||||
If you additionally want to support Web as a platform with emscripten, you will need `emcc.zig`. Refer to raylib-zig's project template on how to use it
|
||||
|
82
build.zig
82
build.zig
@ -13,12 +13,12 @@ const Program = struct {
|
||||
fn link(
|
||||
b: *std.Build,
|
||||
exe: *std.Build.Step.Compile,
|
||||
target: std.zig.CrossTarget,
|
||||
target: std.Build.ResolvedTarget,
|
||||
optimize: std.builtin.Mode,
|
||||
) void {
|
||||
const lib = getRaylib(b, target, optimize);
|
||||
|
||||
const target_os = exe.target.toTarget().os.tag;
|
||||
const target_os = exe.rootModuleTarget().os.tag;
|
||||
switch (target_os) {
|
||||
.windows => {
|
||||
exe.linkSystemLibrary("winmm");
|
||||
@ -60,12 +60,8 @@ fn link(
|
||||
exe.linkLibrary(lib);
|
||||
}
|
||||
|
||||
var _raylib_lib_cache: ?*std.build.Step.Compile = null;
|
||||
fn getRaylib(
|
||||
b: *std.Build,
|
||||
target: std.zig.CrossTarget,
|
||||
optimize: std.builtin.Mode,
|
||||
) *std.Build.Step.Compile {
|
||||
var _raylib_lib_cache: ?*std.Build.Step.Compile = null;
|
||||
fn getRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.Mode) *std.Build.Step.Compile {
|
||||
if (_raylib_lib_cache) |lib| return lib else {
|
||||
const raylib = b.dependency("raylib", .{
|
||||
.target = target,
|
||||
@ -79,34 +75,42 @@ fn getRaylib(
|
||||
}
|
||||
}
|
||||
|
||||
fn getModule(b: *std.Build) *std.Build.Module {
|
||||
fn getModule(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.Mode) *std.Build.Module {
|
||||
if (b.modules.contains("raylib")) {
|
||||
return b.modules.get("raylib").?;
|
||||
}
|
||||
return b.addModule("raylib", .{ .source_file = .{ .path = "lib/raylib.zig" } });
|
||||
return b.addModule("raylib", .{
|
||||
.root_source_file = b.path("lib/raylib.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
}
|
||||
|
||||
const math = struct {
|
||||
fn getModule(b: *std.Build) *std.Build.Module {
|
||||
const raylib = rl.getModule(b);
|
||||
fn getModule(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.Mode) *std.Build.Module {
|
||||
const raylib = rl.getModule(b, target, optimize);
|
||||
return b.addModule("raylib-math", .{
|
||||
.source_file = .{ .path = "lib/raymath.zig" },
|
||||
.dependencies = &.{.{ .name = "raylib-zig", .module = raylib }},
|
||||
.root_source_file = b.path("lib/raymath.zig"),
|
||||
.imports = &.{.{ .name = "raylib-zig", .module = raylib }},
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const gl = struct {
|
||||
fn getModule(b: *std.Build) *std.Build.Module {
|
||||
const raylib = rl.getModule(b);
|
||||
fn getModule(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.Mode) *std.Build.Module {
|
||||
const raylib = rl.getModule(b, target, optimize);
|
||||
return b.addModule("rlgl", .{
|
||||
.source_file = .{ .path = "lib/rlgl.zig" },
|
||||
.dependencies = &.{.{ .name = "raylib-zig", .module = raylib }},
|
||||
.root_source_file = b.path("lib/rlgl.zig"),
|
||||
.imports = &.{.{ .name = "raylib-zig", .module = raylib }},
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
fn build(b: *std.Build) !void {
|
||||
pub fn build(b: *std.Build) !void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
@ -183,43 +187,43 @@ fn build(b: *std.Build) !void {
|
||||
// },
|
||||
};
|
||||
|
||||
const examples_step = b.step("examples", "Builds all the examples");
|
||||
|
||||
const raylib = rl.getModule(b);
|
||||
const raylib_math = rl.math.getModule(b);
|
||||
const rlgl = rl.gl.getModule(b);
|
||||
const raylib = rl.getModule(b, target, optimize);
|
||||
const raylib_math = rl.math.getModule(b, target, optimize);
|
||||
const rlgl = rl.gl.getModule(b, target, optimize);
|
||||
|
||||
const raylib_test = b.addTest(.{
|
||||
.root_source_file = .{ .path = "lib/raylib.zig" },
|
||||
.root_source_file = b.path("lib/raylib.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
const raylib_math_test = b.addTest(.{
|
||||
.root_source_file = .{ .path = "lib/raymath.zig" },
|
||||
.root_source_file = b.path("lib/raymath.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
raylib_math_test.addModule("raylib-zig", raylib);
|
||||
raylib_math_test.root_module.addImport("raylib-zig", raylib);
|
||||
|
||||
const rlgl_test = b.addTest(.{
|
||||
.root_source_file = .{ .path = "lib/rlgl.zig" },
|
||||
.root_source_file = b.path("lib/rlgl.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
rlgl_test.addModule("raylib-zig", raylib);
|
||||
rlgl_test.root_module.addImport("raylib-zig", raylib);
|
||||
|
||||
const test_step = b.step("test", "Check for library compilation errors");
|
||||
test_step.dependOn(&raylib_test.step);
|
||||
test_step.dependOn(&raylib_math_test.step);
|
||||
test_step.dependOn(&rlgl_test.step);
|
||||
|
||||
const examples_step = b.step("examples", "Builds all the examples");
|
||||
|
||||
for (examples) |ex| {
|
||||
if (target.getOsTag() == .emscripten) {
|
||||
if (target.query.os_tag == .emscripten) {
|
||||
const exe_lib = emcc.compileForEmscripten(b, ex.name, ex.path, target, optimize);
|
||||
exe_lib.addModule("raylib", raylib);
|
||||
exe_lib.addModule("raylib-math", raylib_math);
|
||||
exe_lib.addModule("rlgl", rlgl);
|
||||
exe_lib.root_module.addImport("raylib", raylib);
|
||||
exe_lib.root_module.addImport("raylib-math", raylib_math);
|
||||
exe_lib.root_module.addImport("rlgl", rlgl);
|
||||
const raylib_lib = getRaylib(b, target, optimize);
|
||||
|
||||
// Note that raylib itself isn't actually added to the exe_lib
|
||||
@ -232,20 +236,24 @@ fn build(b: *std.Build) !void {
|
||||
const run_step = try emcc.emscriptenRunStep(b);
|
||||
run_step.step.dependOn(&link_step.step);
|
||||
const run_option = b.step(ex.name, ex.desc);
|
||||
|
||||
run_option.dependOn(&run_step.step);
|
||||
examples_step.dependOn(&exe_lib.step);
|
||||
} else {
|
||||
const exe = b.addExecutable(.{
|
||||
.name = ex.name,
|
||||
.root_source_file = .{ .path = ex.path },
|
||||
.root_source_file = b.path(ex.path),
|
||||
.optimize = optimize,
|
||||
.target = target,
|
||||
});
|
||||
rl.link(b, exe, target, optimize);
|
||||
exe.addModule("raylib", raylib);
|
||||
exe.addModule("raylib-math", raylib_math);
|
||||
exe.addModule("rlgl", rlgl);
|
||||
exe.root_module.addImport("raylib", raylib);
|
||||
exe.root_module.addImport("raylib-math", raylib_math);
|
||||
exe.root_module.addImport("rlgl", rlgl);
|
||||
|
||||
const run_cmd = b.addRunArtifact(exe);
|
||||
const run_step = b.step(ex.name, ex.desc);
|
||||
|
||||
run_step.dependOn(&run_cmd.step);
|
||||
examples_step.dependOn(&exe.step);
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
.{
|
||||
.name = "raylib-zig",
|
||||
.version = "5.0.0",
|
||||
.version = "5.1.0",
|
||||
.dependencies = .{
|
||||
.raylib = .{
|
||||
.url = "https://github.com/raysan5/raylib/archive/5.0.tar.gz",
|
||||
.hash = "1220c28847ca8e8756734ae84355802b764c9d9cf4de057dbc6fc2b15c56e726f27b",
|
||||
.url = "https://github.com/raysan5/raylib/archive/e47ebec66134800e734710038ea4e5f070f3ef06.tar.gz",
|
||||
.hash = "12208edb6d35c0aa5f57262014b02392c6ccfd0685a8eff1d961b42a612d3418fa89",
|
||||
},
|
||||
},
|
||||
.minimum_zig_version = "0.11.0",
|
||||
.paths = .{ "lib/raylib.zig", "lib/raylib-ext.zig", "lib/raymath.zig", "lib/raymath-ext.zig", "lib/rlgl.zig", "lib/rlgl-ext.zig" },
|
||||
.minimum_zig_version = "0.12.0",
|
||||
.paths = .{ "build.zig", "build.zig.zon", "emcc.zig", "lib/raylib.zig", "lib/raylib-ext.zig", "lib/raymath.zig", "lib/raymath-ext.zig", "lib/rlgl.zig", "lib/rlgl-ext.zig" },
|
||||
}
|
||||
|
28
emcc.zig
28
emcc.zig
@ -29,7 +29,7 @@ pub fn compileForEmscripten(
|
||||
b: *std.Build,
|
||||
name: []const u8,
|
||||
root_source_file: []const u8,
|
||||
target: std.zig.CrossTarget,
|
||||
target: std.Build.ResolvedTarget,
|
||||
optimize: std.builtin.Mode,
|
||||
) *std.Build.Step.Compile {
|
||||
// TODO: It might be a good idea to create a custom compile step, that does
|
||||
@ -37,13 +37,13 @@ pub fn compileForEmscripten(
|
||||
// the make function of the step. However it might also be a bad idea since
|
||||
// it messes with the build system itself.
|
||||
|
||||
const new_target = updateTargetForWeb(target);
|
||||
//const new_target = updateTargetForWeb(target);
|
||||
|
||||
// The project is built as a library and linked later.
|
||||
const exe_lib = b.addStaticLibrary(.{
|
||||
.name = name,
|
||||
.root_source_file = .{ .path = root_source_file },
|
||||
.target = new_target,
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
@ -123,27 +123,7 @@ fn lastIndexOf(string: []const u8, character: u8) usize {
|
||||
}
|
||||
return string.len - 1;
|
||||
}
|
||||
// TODO: each zig update, remove this and see if everything still works.
|
||||
// https://github.com/ziglang/zig/issues/16776 is where the issue is submitted.
|
||||
fn updateTargetForWeb(target: std.zig.CrossTarget) std.zig.CrossTarget {
|
||||
// Zig building to emscripten doesn't work, because the Zig standard library
|
||||
// is missing some things in the C system. "std/c.zig" is missing fd_t,
|
||||
// which causes compilation to fail. So build to wasi instead, until it gets
|
||||
// fixed.
|
||||
return std.zig.CrossTarget{
|
||||
.cpu_arch = target.cpu_arch,
|
||||
.cpu_model = target.cpu_model,
|
||||
.cpu_features_add = target.cpu_features_add,
|
||||
.cpu_features_sub = target.cpu_features_sub,
|
||||
.os_tag = .wasi,
|
||||
.os_version_min = target.os_version_min,
|
||||
.os_version_max = target.os_version_max,
|
||||
.glibc_version = target.glibc_version,
|
||||
.abi = target.abi,
|
||||
.dynamic_linker = target.dynamic_linker,
|
||||
.ofmt = target.ofmt,
|
||||
};
|
||||
}
|
||||
|
||||
const webhack_c =
|
||||
\\// Zig adds '__stack_chk_guard', '__stack_chk_fail', and 'errno',
|
||||
\\// which emscripten doesn't actually support.
|
||||
|
@ -234,6 +234,10 @@ def parse_header(header_name: str, output_file: str, ext_file: str, prefix: str,
|
||||
zig_c_arguments = []
|
||||
zig_arguments = []
|
||||
zig_call_args = []
|
||||
|
||||
if not arguments:
|
||||
arguments = "void"
|
||||
|
||||
for arg in arguments.split(", "):
|
||||
if arg == "void":
|
||||
break
|
||||
|
@ -795,6 +795,18 @@ pub const FilePathList = extern struct {
|
||||
paths: [*c][*c]u8,
|
||||
};
|
||||
|
||||
pub const AutomationEvent = extern struct {
|
||||
frame: c_uint,
|
||||
@"type": c_uint,
|
||||
params: [4]c_int,
|
||||
};
|
||||
|
||||
pub const AutomationEventList = extern struct {
|
||||
capacity: c_uint,
|
||||
count: c_uint,
|
||||
events: [*c]AutomationEvent
|
||||
};
|
||||
|
||||
pub const ConfigFlags = enum(c_int) {
|
||||
flag_fullscreen_mode = 2,
|
||||
flag_window_resizable = 4,
|
||||
@ -1164,21 +1176,10 @@ pub const LoadFileTextCallback = *const fn ([*c]const u8) callconv(.C) [*c]u8;
|
||||
pub const SaveFileTextCallback = *const fn ([*c]const u8, [*c]u8) callconv(.C) bool;
|
||||
pub const AudioCallback = ?*const fn (?*anyopaque, c_uint) callconv(.C) void;
|
||||
|
||||
pub const AutomationEvent = extern struct {
|
||||
frame: c_uint = @import("std").mem.zeroes(c_uint),
|
||||
type: c_uint = @import("std").mem.zeroes(c_uint),
|
||||
params: [4]c_int = @import("std").mem.zeroes([4]c_int),
|
||||
};
|
||||
pub const AutomationEventList = extern struct {
|
||||
capacity: c_uint = @import("std").mem.zeroes(c_uint),
|
||||
count: c_uint = @import("std").mem.zeroes(c_uint),
|
||||
events: [*c]AutomationEvent = @import("std").mem.zeroes([*c]AutomationEvent),
|
||||
};
|
||||
|
||||
pub const RAYLIB_VERSION_MAJOR = @as(i32, 4);
|
||||
pub const RAYLIB_VERSION_MINOR = @as(i32, 6);
|
||||
pub const RAYLIB_VERSION_MAJOR = @as(i32, 5);
|
||||
pub const RAYLIB_VERSION_MINOR = @as(i32, 1);
|
||||
pub const RAYLIB_VERSION_PATCH = @as(i32, 0);
|
||||
pub const RAYLIB_VERSION = "4.6-dev";
|
||||
pub const RAYLIB_VERSION = "5.1-dev";
|
||||
|
||||
pub const MAX_TOUCH_POINTS = 10;
|
||||
pub const MAX_MATERIAL_MAPS = 12;
|
||||
@ -1271,6 +1272,10 @@ pub fn decodeDataBase64(data: []const u8) []u8 {
|
||||
return res;
|
||||
}
|
||||
|
||||
pub fn loadImageAnimFromMemory(fileType: [:0]const u8, fileData: []const u8, frames: *i32) Image {
|
||||
return cdef.LoadImageAnimFromMemory(@as([*c]const u8, @ptrCast(fileType)), @as([*c]const u8, @ptrCast(fileData)), @as(c_int, @intCast(fileData.len)), @as([*c]c_int, @ptrCast(frames)));
|
||||
}
|
||||
|
||||
pub fn loadImageFromMemory(fileType: [:0]const u8, fileData: []const u8) Image {
|
||||
return cdef.LoadImageFromMemory(@as([*c]const u8, @ptrCast(fileType)), @as([*c]const u8, @ptrCast(fileData)), @as(c_int, @intCast(fileData.len)));
|
||||
}
|
||||
|
@ -14,10 +14,11 @@ pub const rlVertexBuffer = extern struct {
|
||||
elementCount: c_int,
|
||||
vertices: [*c]f32,
|
||||
texcoords: [*c]f32,
|
||||
normals: [*c]f32,
|
||||
colors: [*c]u8,
|
||||
indices: [*c]c_ushort,
|
||||
vaoId: c_uint,
|
||||
vboId: [4]c_uint,
|
||||
vboId: [5]c_uint,
|
||||
};
|
||||
|
||||
pub const rlDrawCall = extern struct {
|
||||
|
@ -85,13 +85,14 @@ pub extern "c" fn SetShaderValueV(shader: rl.Shader, locIndex: c_int, value: *co
|
||||
pub extern "c" fn SetShaderValueMatrix(shader: rl.Shader, locIndex: c_int, mat: rl.Matrix) void;
|
||||
pub extern "c" fn SetShaderValueTexture(shader: rl.Shader, locIndex: c_int, texture: rl.Texture2D) void;
|
||||
pub extern "c" fn UnloadShader(shader: rl.Shader) void;
|
||||
pub extern "c" fn GetMouseRay(mousePosition: rl.Vector2, camera: rl.Camera) rl.Ray;
|
||||
pub extern "c" fn GetCameraMatrix(camera: rl.Camera) rl.Matrix;
|
||||
pub extern "c" fn GetCameraMatrix2D(camera: rl.Camera2D) rl.Matrix;
|
||||
pub extern "c" fn GetScreenToWorldRay(position: rl.Vector2, camera: rl.Camera) rl.Ray;
|
||||
pub extern "c" fn GetScreenToWorldRayEx(position: rl.Vector2, camera: rl.Camera, width: c_int, height: c_int) rl.Ray;
|
||||
pub extern "c" fn GetWorldToScreen(position: rl.Vector3, camera: rl.Camera) rl.Vector2;
|
||||
pub extern "c" fn GetScreenToWorld2D(position: rl.Vector2, camera: rl.Camera2D) rl.Vector2;
|
||||
pub extern "c" fn GetWorldToScreenEx(position: rl.Vector3, camera: rl.Camera, width: c_int, height: c_int) rl.Vector2;
|
||||
pub extern "c" fn GetWorldToScreen2D(position: rl.Vector2, camera: rl.Camera2D) rl.Vector2;
|
||||
pub extern "c" fn GetScreenToWorld2D(position: rl.Vector2, camera: rl.Camera2D) rl.Vector2;
|
||||
pub extern "c" fn GetCameraMatrix(camera: rl.Camera) rl.Matrix;
|
||||
pub extern "c" fn GetCameraMatrix2D(camera: rl.Camera2D) rl.Matrix;
|
||||
pub extern "c" fn SetTargetFPS(fps: c_int) void;
|
||||
pub extern "c" fn GetFrameTime() f32;
|
||||
pub extern "c" fn GetTime() f64;
|
||||
@ -147,7 +148,7 @@ pub extern "c" fn DecompressData(compData: [*c]const u8, compDataSize: c_int, da
|
||||
pub extern "c" fn EncodeDataBase64(data: [*c]const u8, dataSize: c_int, outputSize: [*c]c_int) [*c]u8;
|
||||
pub extern "c" fn DecodeDataBase64(data: [*c]const u8, outputSize: [*c]c_int) [*c]u8;
|
||||
pub extern "c" fn LoadAutomationEventList(fileName: [*c]const u8) rl.AutomationEventList;
|
||||
pub extern "c" fn UnloadAutomationEventList(list: [*c]rl.AutomationEventList) void;
|
||||
pub extern "c" fn UnloadAutomationEventList(list: rl.AutomationEventList) void;
|
||||
pub extern "c" fn ExportAutomationEventList(list: rl.AutomationEventList, fileName: [*c]const u8) bool;
|
||||
pub extern "c" fn SetAutomationEventList(list: [*c]rl.AutomationEventList) void;
|
||||
pub extern "c" fn SetAutomationEventBaseFrame(frame: c_int) void;
|
||||
@ -172,6 +173,7 @@ pub extern "c" fn GetGamepadButtonPressed() rl.GamepadButton;
|
||||
pub extern "c" fn GetGamepadAxisCount(gamepad: c_int) c_int;
|
||||
pub extern "c" fn GetGamepadAxisMovement(gamepad: c_int, axis: c_int) f32;
|
||||
pub extern "c" fn SetGamepadMappings(mappings: [*c]const u8) c_int;
|
||||
pub extern "c" fn SetGamepadVibration(gamepad: c_int, leftMotor: f32, rightMotor: f32) void;
|
||||
pub extern "c" fn IsMouseButtonPressed(button: rl.MouseButton) bool;
|
||||
pub extern "c" fn IsMouseButtonDown(button: rl.MouseButton) bool;
|
||||
pub extern "c" fn IsMouseButtonReleased(button: rl.MouseButton) bool;
|
||||
@ -202,6 +204,8 @@ pub extern "c" fn GetGesturePinchAngle() f32;
|
||||
pub extern "c" fn UpdateCamera(camera: [*c]rl.Camera, mode: rl.CameraMode) void;
|
||||
pub extern "c" fn UpdateCameraPro(camera: [*c]rl.Camera, movement: rl.Vector3, rotation: rl.Vector3, zoom: f32) void;
|
||||
pub extern "c" fn SetShapesTexture(texture: rl.Texture2D, source: rl.Rectangle) void;
|
||||
pub extern "c" fn GetShapesTexture() rl.Texture2D;
|
||||
pub extern "c" fn GetShapesTextureRectangle() rl.Rectangle;
|
||||
pub extern "c" fn DrawPixel(posX: c_int, posY: c_int, color: rl.Color) void;
|
||||
pub extern "c" fn DrawPixelV(position: rl.Vector2, color: rl.Color) void;
|
||||
pub extern "c" fn DrawLine(startPosX: c_int, startPosY: c_int, endPosX: c_int, endPosY: c_int, color: rl.Color) void;
|
||||
@ -230,7 +234,8 @@ pub extern "c" fn DrawRectangleGradientEx(rec: rl.Rectangle, col1: rl.Color, col
|
||||
pub extern "c" fn DrawRectangleLines(posX: c_int, posY: c_int, width: c_int, height: c_int, color: rl.Color) void;
|
||||
pub extern "c" fn DrawRectangleLinesEx(rec: rl.Rectangle, lineThick: f32, color: rl.Color) void;
|
||||
pub extern "c" fn DrawRectangleRounded(rec: rl.Rectangle, roundness: f32, segments: c_int, color: rl.Color) void;
|
||||
pub extern "c" fn DrawRectangleRoundedLines(rec: rl.Rectangle, roundness: f32, segments: c_int, lineThick: f32, color: rl.Color) void;
|
||||
pub extern "c" fn DrawRectangleRoundedLines(rec: rl.Rectangle, roundness: f32, segments: c_int, color: rl.Color) void;
|
||||
pub extern "c" fn DrawRectangleRoundedLinesEx(rec: rl.Rectangle, roundness: f32, segments: c_int, lineThick: f32, color: rl.Color) void;
|
||||
pub extern "c" fn DrawTriangle(v1: rl.Vector2, v2: rl.Vector2, v3: rl.Vector2, color: rl.Color) void;
|
||||
pub extern "c" fn DrawTriangleLines(v1: rl.Vector2, v2: rl.Vector2, v3: rl.Vector2, color: rl.Color) void;
|
||||
pub extern "c" fn DrawTriangleFan(points: [*c]rl.Vector2, pointCount: c_int, color: rl.Color) void;
|
||||
@ -267,6 +272,7 @@ pub extern "c" fn LoadImage(fileName: [*c]const u8) rl.Image;
|
||||
pub extern "c" fn LoadImageRaw(fileName: [*c]const u8, width: c_int, height: c_int, format: c_int, headerSize: c_int) rl.Image;
|
||||
pub extern "c" fn LoadImageSvg(fileNameOrString: [*c]const u8, width: c_int, height: c_int) rl.Image;
|
||||
pub extern "c" fn LoadImageAnim(fileName: [*c]const u8, frames: [*c]c_int) rl.Image;
|
||||
pub extern "c" fn LoadImageAnimFromMemory(fileType: [*c]const u8, fileData: [*c]const u8, dataSize: c_int, frames: [*c]c_int) rl.Image;
|
||||
pub extern "c" fn LoadImageFromMemory(fileType: [*c]const u8, fileData: [*c]const u8, dataSize: c_int) rl.Image;
|
||||
pub extern "c" fn LoadImageFromTexture(texture: rl.Texture2D) rl.Image;
|
||||
pub extern "c" fn LoadImageFromScreen() rl.Image;
|
||||
@ -296,6 +302,7 @@ pub extern "c" fn ImageAlphaClear(image: [*c]rl.Image, color: rl.Color, threshol
|
||||
pub extern "c" fn ImageAlphaMask(image: [*c]rl.Image, alphaMask: rl.Image) void;
|
||||
pub extern "c" fn ImageAlphaPremultiply(image: [*c]rl.Image) void;
|
||||
pub extern "c" fn ImageBlurGaussian(image: [*c]rl.Image, blurSize: c_int) void;
|
||||
pub extern "c" fn ImageKernelConvolution(image: [*c]rl.Image, kernel: [*c]f32, kernelSize: c_int) void;
|
||||
pub extern "c" fn ImageResize(image: [*c]rl.Image, newWidth: c_int, newHeight: c_int) void;
|
||||
pub extern "c" fn ImageResizeNN(image: [*c]rl.Image, newWidth: c_int, newHeight: c_int) void;
|
||||
pub extern "c" fn ImageResizeCanvas(image: [*c]rl.Image, newWidth: c_int, newHeight: c_int, offsetX: c_int, offsetY: c_int, fill: rl.Color) void;
|
||||
@ -353,6 +360,7 @@ pub extern "c" fn DrawTextureEx(texture: rl.Texture2D, position: rl.Vector2, rot
|
||||
pub extern "c" fn DrawTextureRec(texture: rl.Texture2D, source: rl.Rectangle, position: rl.Vector2, tint: rl.Color) void;
|
||||
pub extern "c" fn DrawTexturePro(texture: rl.Texture2D, source: rl.Rectangle, dest: rl.Rectangle, origin: rl.Vector2, rotation: f32, tint: rl.Color) void;
|
||||
pub extern "c" fn DrawTextureNPatch(texture: rl.Texture2D, nPatchInfo: rl.NPatchInfo, dest: rl.Rectangle, origin: rl.Vector2, rotation: f32, tint: rl.Color) void;
|
||||
pub extern "c" fn ColorIsEqual(col1: rl.Color, col2: rl.Color) bool;
|
||||
pub extern "c" fn Fade(color: rl.Color, alpha: f32) rl.Color;
|
||||
pub extern "c" fn ColorToInt(color: rl.Color) c_int;
|
||||
pub extern "c" fn ColorNormalize(color: rl.Color) rl.Vector4;
|
||||
@ -405,7 +413,7 @@ pub extern "c" fn TextIsEqual(text1: [*c]const u8, text2: [*c]const u8) bool;
|
||||
pub extern "c" fn TextLength(text: [*c]const u8) c_uint;
|
||||
pub extern "c" fn TextFormat(text: [*c]const u8, ...) [*c]const u8;
|
||||
pub extern "c" fn TextSubtext(text: [*c]const u8, position: c_int, length: c_int) [*c]const u8;
|
||||
pub extern "c" fn TextReplace(text: [*c]u8, replace: [*c]const u8, by: [*c]const u8) [*c]u8;
|
||||
pub extern "c" fn TextReplace(text: [*c]const u8, replace: [*c]const u8, by: [*c]const u8) [*c]u8;
|
||||
pub extern "c" fn TextInsert(text: [*c]const u8, insert: [*c]const u8, position: c_int) [*c]u8;
|
||||
pub extern "c" fn TextJoin(textList: [*c][*c]const u8, count: c_int, delimiter: [*c]const u8) [*c]const u8;
|
||||
pub extern "c" fn TextSplit(text: [*c]const u8, delimiter: u8, count: [*c]c_int) [*c][*c]const u8;
|
||||
@ -415,6 +423,7 @@ pub extern "c" fn TextToUpper(text: [*c]const u8) [*c]const u8;
|
||||
pub extern "c" fn TextToLower(text: [*c]const u8) [*c]const u8;
|
||||
pub extern "c" fn TextToPascal(text: [*c]const u8) [*c]const u8;
|
||||
pub extern "c" fn TextToInteger(text: [*c]const u8) c_int;
|
||||
pub extern "c" fn TextToFloat(text: [*c]const u8) f32;
|
||||
pub extern "c" fn DrawLine3D(startPos: rl.Vector3, endPos: rl.Vector3, color: rl.Color) void;
|
||||
pub extern "c" fn DrawPoint3D(position: rl.Vector3, color: rl.Color) void;
|
||||
pub extern "c" fn DrawCircle3D(center: rl.Vector3, radius: f32, rotationAxis: rl.Vector3, rotationAngle: f32, color: rl.Color) void;
|
||||
@ -454,9 +463,10 @@ pub extern "c" fn UpdateMeshBuffer(mesh: rl.Mesh, index: c_int, data: *const any
|
||||
pub extern "c" fn UnloadMesh(mesh: rl.Mesh) void;
|
||||
pub extern "c" fn DrawMesh(mesh: rl.Mesh, material: rl.Material, transform: rl.Matrix) void;
|
||||
pub extern "c" fn DrawMeshInstanced(mesh: rl.Mesh, material: rl.Material, transforms: [*c]const rl.Matrix, instances: c_int) void;
|
||||
pub extern "c" fn ExportMesh(mesh: rl.Mesh, fileName: [*c]const u8) bool;
|
||||
pub extern "c" fn GetMeshBoundingBox(mesh: rl.Mesh) rl.BoundingBox;
|
||||
pub extern "c" fn GenMeshTangents(mesh: [*c]rl.Mesh) void;
|
||||
pub extern "c" fn ExportMesh(mesh: rl.Mesh, fileName: [*c]const u8) bool;
|
||||
pub extern "c" fn ExportMeshAsCode(mesh: rl.Mesh, fileName: [*c]const u8) bool;
|
||||
pub extern "c" fn GenMeshPoly(sides: c_int, radius: f32) rl.Mesh;
|
||||
pub extern "c" fn GenMeshPlane(width: f32, length: f32, resX: c_int, resZ: c_int) rl.Mesh;
|
||||
pub extern "c" fn GenMeshCube(width: f32, height: f32, length: f32) rl.Mesh;
|
||||
|
85
lib/raylib.h
85
lib/raylib.h
@ -1,6 +1,6 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* raylib v5.0 - A simple and easy-to-use library to enjoy videogames programming (www.raylib.com)
|
||||
* raylib v5.1-dev - A simple and easy-to-use library to enjoy videogames programming (www.raylib.com)
|
||||
*
|
||||
* FEATURES:
|
||||
* - NO external dependencies, all required libraries included with raylib
|
||||
@ -57,7 +57,7 @@
|
||||
* raylib is 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)
|
||||
* Copyright (c) 2013-2024 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||
* will the authors be held liable for any damages arising from the use of this software.
|
||||
@ -82,21 +82,26 @@
|
||||
#include <stdarg.h> // Required for: va_list - Only used by TraceLogCallback
|
||||
|
||||
#define RAYLIB_VERSION_MAJOR 5
|
||||
#define RAYLIB_VERSION_MINOR 0
|
||||
#define RAYLIB_VERSION_MINOR 1
|
||||
#define RAYLIB_VERSION_PATCH 0
|
||||
#define RAYLIB_VERSION "5.0"
|
||||
#define RAYLIB_VERSION "5.1-dev"
|
||||
|
||||
// Function specifiers in case library is build/used as a shared library (Windows)
|
||||
// Function specifiers in case library is build/used as a shared library
|
||||
// NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll
|
||||
// NOTE: visibility("default") attribute makes symbols "visible" when compiled with -fvisibility=hidden
|
||||
#if defined(_WIN32)
|
||||
#if defined(__TINYC__)
|
||||
#define __declspec(x) __attribute__((x))
|
||||
#endif
|
||||
#if defined(BUILD_LIBTYPE_SHARED)
|
||||
#if defined(__TINYC__)
|
||||
#define __declspec(x) __attribute__((x))
|
||||
#endif
|
||||
#define RLAPI __declspec(dllexport) // We are building the library as a Win32 shared library (.dll)
|
||||
#elif defined(USE_LIBTYPE_SHARED)
|
||||
#define RLAPI __declspec(dllimport) // We are using the library as a Win32 shared library (.dll)
|
||||
#endif
|
||||
#else
|
||||
#if defined(BUILD_LIBTYPE_SHARED)
|
||||
#define RLAPI __attribute__((visibility("default"))) // We are building as a Unix shared library (.so/.dylib)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef RLAPI
|
||||
@ -479,7 +484,6 @@ typedef struct VrDeviceInfo {
|
||||
int vResolution; // Vertical resolution in pixels
|
||||
float hScreenSize; // Horizontal size in meters
|
||||
float vScreenSize; // Vertical size in meters
|
||||
float vScreenCenter; // Screen center in meters
|
||||
float eyeToScreenDistance; // Distance between eye and display in meters
|
||||
float lensSeparationDistance; // Lens separation distance in meters
|
||||
float interpupillaryDistance; // IPD (distance between pupils) in meters
|
||||
@ -673,7 +677,7 @@ typedef enum {
|
||||
KEY_KP_EQUAL = 336, // Key: Keypad =
|
||||
// Android key buttons
|
||||
KEY_BACK = 4, // Key: Android back button
|
||||
KEY_MENU = 82, // Key: Android menu button
|
||||
KEY_MENU = 5, // Key: Android menu button
|
||||
KEY_VOLUME_UP = 24, // Key: Android volume up button
|
||||
KEY_VOLUME_DOWN = 25 // Key: Android volume down button
|
||||
} KeyboardKey;
|
||||
@ -717,9 +721,9 @@ typedef enum {
|
||||
GAMEPAD_BUTTON_LEFT_FACE_DOWN, // Gamepad left DPAD down button
|
||||
GAMEPAD_BUTTON_LEFT_FACE_LEFT, // Gamepad left DPAD left button
|
||||
GAMEPAD_BUTTON_RIGHT_FACE_UP, // Gamepad right button up (i.e. PS3: Triangle, Xbox: Y)
|
||||
GAMEPAD_BUTTON_RIGHT_FACE_RIGHT, // Gamepad right button right (i.e. PS3: Square, Xbox: X)
|
||||
GAMEPAD_BUTTON_RIGHT_FACE_RIGHT, // Gamepad right button right (i.e. PS3: Circle, Xbox: B)
|
||||
GAMEPAD_BUTTON_RIGHT_FACE_DOWN, // Gamepad right button down (i.e. PS3: Cross, Xbox: A)
|
||||
GAMEPAD_BUTTON_RIGHT_FACE_LEFT, // Gamepad right button left (i.e. PS3: Circle, Xbox: B)
|
||||
GAMEPAD_BUTTON_RIGHT_FACE_LEFT, // Gamepad right button left (i.e. PS3: Square, Xbox: X)
|
||||
GAMEPAD_BUTTON_LEFT_TRIGGER_1, // Gamepad top/back trigger left (first), it could be a trailing button
|
||||
GAMEPAD_BUTTON_LEFT_TRIGGER_2, // Gamepad top/back trigger left (second), it could be a trailing button
|
||||
GAMEPAD_BUTTON_RIGHT_TRIGGER_1, // Gamepad top/back trigger right (one), it could be a trailing button
|
||||
@ -1045,13 +1049,15 @@ RLAPI void SetShaderValueTexture(Shader shader, int locIndex, Texture2D texture)
|
||||
RLAPI void UnloadShader(Shader shader); // Unload shader from GPU memory (VRAM)
|
||||
|
||||
// Screen-space-related functions
|
||||
RLAPI Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Get a ray trace from mouse position
|
||||
RLAPI Matrix GetCameraMatrix(Camera camera); // Get camera transform matrix (view matrix)
|
||||
RLAPI Matrix GetCameraMatrix2D(Camera2D camera); // Get camera 2d transform matrix
|
||||
RLAPI Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Get the screen space position for a 3d world space position
|
||||
RLAPI Vector2 GetScreenToWorld2D(Vector2 position, Camera2D camera); // Get the world space position for a 2d camera screen space position
|
||||
#define GetMouseRay GetScreenToWorldRay // Compatibility hack for previous raylib versions
|
||||
RLAPI Ray GetScreenToWorldRay(Vector2 position, Camera camera); // Get a ray trace from screen position (i.e mouse)
|
||||
RLAPI Ray GetScreenToWorldRayEx(Vector2 position, Camera camera, int width, int height); // Get a ray trace from screen position (i.e mouse) in a viewport
|
||||
RLAPI Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Get the screen space position for a 3d world space position
|
||||
RLAPI Vector2 GetWorldToScreenEx(Vector3 position, Camera camera, int width, int height); // Get size position for a 3d world space position
|
||||
RLAPI Vector2 GetWorldToScreen2D(Vector2 position, Camera2D camera); // Get the screen space position for a 2d camera world space position
|
||||
RLAPI Vector2 GetWorldToScreen2D(Vector2 position, Camera2D camera); // Get the screen space position for a 2d camera world space position
|
||||
RLAPI Vector2 GetScreenToWorld2D(Vector2 position, Camera2D camera); // Get the world space position for a 2d camera screen space position
|
||||
RLAPI Matrix GetCameraMatrix(Camera camera); // Get camera transform matrix (view matrix)
|
||||
RLAPI Matrix GetCameraMatrix2D(Camera2D camera); // Get camera 2d transform matrix
|
||||
|
||||
// Timing-related functions
|
||||
RLAPI void SetTargetFPS(int fps); // Set target FPS (maximum)
|
||||
@ -1134,7 +1140,7 @@ RLAPI unsigned char *DecodeDataBase64(const unsigned char *data, int *outputSize
|
||||
|
||||
// Automation events functionality
|
||||
RLAPI AutomationEventList LoadAutomationEventList(const char *fileName); // Load automation events list from file, NULL for empty list, capacity = MAX_AUTOMATION_EVENTS
|
||||
RLAPI void UnloadAutomationEventList(AutomationEventList *list); // Unload automation events list from file
|
||||
RLAPI void UnloadAutomationEventList(AutomationEventList list); // Unload automation events list from file
|
||||
RLAPI bool ExportAutomationEventList(AutomationEventList list, const char *fileName); // Export automation events list as text file
|
||||
RLAPI void SetAutomationEventList(AutomationEventList *list); // Set automation event list to record to
|
||||
RLAPI void SetAutomationEventBaseFrame(int frame); // Set automation event internal base frame to start recording
|
||||
@ -1157,16 +1163,17 @@ RLAPI int GetCharPressed(void); // Get char presse
|
||||
RLAPI void SetExitKey(int key); // Set a custom key to exit program (default is ESC)
|
||||
|
||||
// Input-related functions: gamepads
|
||||
RLAPI bool IsGamepadAvailable(int gamepad); // Check if a gamepad is available
|
||||
RLAPI const char *GetGamepadName(int gamepad); // Get gamepad internal name id
|
||||
RLAPI bool IsGamepadButtonPressed(int gamepad, int button); // Check if a gamepad button has been pressed once
|
||||
RLAPI bool IsGamepadButtonDown(int gamepad, int button); // Check if a gamepad button is being pressed
|
||||
RLAPI bool IsGamepadButtonReleased(int gamepad, int button); // Check if a gamepad button has been released once
|
||||
RLAPI bool IsGamepadButtonUp(int gamepad, int button); // Check if a gamepad button is NOT being pressed
|
||||
RLAPI int GetGamepadButtonPressed(void); // Get the last gamepad button pressed
|
||||
RLAPI int GetGamepadAxisCount(int gamepad); // Get gamepad axis count for a gamepad
|
||||
RLAPI float GetGamepadAxisMovement(int gamepad, int axis); // Get axis movement value for a gamepad axis
|
||||
RLAPI int SetGamepadMappings(const char *mappings); // Set internal gamepad mappings (SDL_GameControllerDB)
|
||||
RLAPI bool IsGamepadAvailable(int gamepad); // Check if a gamepad is available
|
||||
RLAPI const char *GetGamepadName(int gamepad); // Get gamepad internal name id
|
||||
RLAPI bool IsGamepadButtonPressed(int gamepad, int button); // Check if a gamepad button has been pressed once
|
||||
RLAPI bool IsGamepadButtonDown(int gamepad, int button); // Check if a gamepad button is being pressed
|
||||
RLAPI bool IsGamepadButtonReleased(int gamepad, int button); // Check if a gamepad button has been released once
|
||||
RLAPI bool IsGamepadButtonUp(int gamepad, int button); // Check if a gamepad button is NOT being pressed
|
||||
RLAPI int GetGamepadButtonPressed(void); // Get the last gamepad button pressed
|
||||
RLAPI int GetGamepadAxisCount(int gamepad); // Get gamepad axis count for a gamepad
|
||||
RLAPI float GetGamepadAxisMovement(int gamepad, int axis); // Get axis movement value for a gamepad axis
|
||||
RLAPI int SetGamepadMappings(const char *mappings); // Set internal gamepad mappings (SDL_GameControllerDB)
|
||||
RLAPI void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor); // Set gamepad vibration for both motors
|
||||
|
||||
// Input-related functions: mouse
|
||||
RLAPI bool IsMouseButtonPressed(int button); // Check if a mouse button has been pressed once
|
||||
@ -1216,6 +1223,8 @@ RLAPI void UpdateCameraPro(Camera *camera, Vector3 movement, Vector3 rotation, f
|
||||
// NOTE: It can be useful when using basic shapes and one single font,
|
||||
// defining a font char white rectangle would allow drawing everything in a single draw call
|
||||
RLAPI void SetShapesTexture(Texture2D texture, Rectangle source); // Set texture and rectangle to be used on shapes drawing
|
||||
RLAPI Texture2D GetShapesTexture(void); // Get texture that is used for shapes drawing
|
||||
RLAPI Rectangle GetShapesTextureRectangle(void); // Get texture source rectangle that is used for shapes drawing
|
||||
|
||||
// Basic shapes drawing functions
|
||||
RLAPI void DrawPixel(int posX, int posY, Color color); // Draw a pixel
|
||||
@ -1246,7 +1255,8 @@ RLAPI void DrawRectangleGradientEx(Rectangle rec, Color col1, Color col2, Color
|
||||
RLAPI void DrawRectangleLines(int posX, int posY, int width, int height, Color color); // Draw rectangle outline
|
||||
RLAPI void DrawRectangleLinesEx(Rectangle rec, float lineThick, Color color); // Draw rectangle outline with extended parameters
|
||||
RLAPI void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color color); // Draw rectangle with rounded edges
|
||||
RLAPI void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, float lineThick, Color color); // Draw rectangle with rounded edges outline
|
||||
RLAPI void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, Color color); // Draw rectangle lines with rounded edges
|
||||
RLAPI void DrawRectangleRoundedLinesEx(Rectangle rec, float roundness, int segments, float lineThick, Color color); // Draw rectangle with rounded edges outline
|
||||
RLAPI void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw a color-filled triangle (vertex in counter-clockwise order!)
|
||||
RLAPI void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle outline (vertex in counter-clockwise order!)
|
||||
RLAPI void DrawTriangleFan(Vector2 *points, int pointCount, Color color); // Draw a triangle fan defined by points (first vertex is the center)
|
||||
@ -1296,6 +1306,7 @@ RLAPI Image LoadImage(const char *fileName);
|
||||
RLAPI Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize); // Load image from RAW file data
|
||||
RLAPI Image LoadImageSvg(const char *fileNameOrString, int width, int height); // Load image from SVG file data or string with specified size
|
||||
RLAPI Image LoadImageAnim(const char *fileName, int *frames); // Load image sequence from file (frames appended to image.data)
|
||||
RLAPI Image LoadImageAnimFromMemory(const char *fileType, const unsigned char *fileData, int dataSize, int *frames); // Load image sequence from memory buffer
|
||||
RLAPI Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, int dataSize); // Load image from memory buffer, fileType refers to extension: i.e. '.png'
|
||||
RLAPI Image LoadImageFromTexture(Texture2D texture); // Load image from GPU texture data
|
||||
RLAPI Image LoadImageFromScreen(void); // Load image from screen buffer and (screenshot)
|
||||
@ -1329,6 +1340,7 @@ RLAPI void ImageAlphaClear(Image *image, Color color, float threshold);
|
||||
RLAPI void ImageAlphaMask(Image *image, Image alphaMask); // Apply alpha mask to image
|
||||
RLAPI void ImageAlphaPremultiply(Image *image); // Premultiply alpha channel
|
||||
RLAPI void ImageBlurGaussian(Image *image, int blurSize); // Apply Gaussian blur using a box blur approximation
|
||||
RLAPI void ImageKernelConvolution(Image *image, float* kernel, int kernelSize); // Apply Custom Square image convolution kernel
|
||||
RLAPI void ImageResize(Image *image, int newWidth, int newHeight); // Resize image (Bicubic scaling algorithm)
|
||||
RLAPI void ImageResizeNN(Image *image, int newWidth,int newHeight); // Resize image (Nearest-Neighbor scaling algorithm)
|
||||
RLAPI void ImageResizeCanvas(Image *image, int newWidth, int newHeight, int offsetX, int offsetY, Color fill); // Resize canvas and fill with color
|
||||
@ -1398,8 +1410,9 @@ RLAPI void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, V
|
||||
RLAPI void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, Vector2 origin, float rotation, Color tint); // Draws a texture (or part of it) that stretches or shrinks nicely
|
||||
|
||||
// Color/pixel related functions
|
||||
RLAPI bool ColorIsEqual(Color col1, Color col2); // Check if two colors are equal
|
||||
RLAPI Color Fade(Color color, float alpha); // Get color with alpha applied, alpha goes from 0.0f to 1.0f
|
||||
RLAPI int ColorToInt(Color color); // Get hexadecimal value for a Color
|
||||
RLAPI int ColorToInt(Color color); // Get hexadecimal value for a Color (0xRRGGBBAA)
|
||||
RLAPI Vector4 ColorNormalize(Color color); // Get Color normalized as float [0..1]
|
||||
RLAPI Color ColorFromNormalized(Vector4 normalized); // Get Color from normalized values [0..1]
|
||||
RLAPI Vector3 ColorToHSV(Color color); // Get HSV values for a Color, hue [0..360], saturation/value [0..1]
|
||||
@ -1465,7 +1478,7 @@ RLAPI bool TextIsEqual(const char *text1, const char *text2);
|
||||
RLAPI unsigned int TextLength(const char *text); // Get text length, checks for '\0' ending
|
||||
RLAPI const char *TextFormat(const char *text, ...); // Text formatting with variables (sprintf() style)
|
||||
RLAPI const char *TextSubtext(const char *text, int position, int length); // Get a piece of a text string
|
||||
RLAPI char *TextReplace(char *text, const char *replace, const char *by); // Replace text string (WARNING: memory must be freed!)
|
||||
RLAPI char *TextReplace(const char *text, const char *replace, const char *by); // Replace text string (WARNING: memory must be freed!)
|
||||
RLAPI char *TextInsert(const char *text, const char *insert, int position); // Insert text in a position (WARNING: memory must be freed!)
|
||||
RLAPI const char *TextJoin(const char **textList, int count, const char *delimiter); // Join text strings with delimiter
|
||||
RLAPI const char **TextSplit(const char *text, char delimiter, int *count); // Split text into multiple strings
|
||||
@ -1475,6 +1488,7 @@ RLAPI const char *TextToUpper(const char *text); // Get upp
|
||||
RLAPI const char *TextToLower(const char *text); // Get lower case version of provided string
|
||||
RLAPI const char *TextToPascal(const char *text); // Get Pascal case notation version of provided string
|
||||
RLAPI int TextToInteger(const char *text); // Get integer value from text (negative values not supported)
|
||||
RLAPI float TextToFloat(const char *text); // Get float value from text (negative values not supported)
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Basic 3d Shapes Drawing Functions (Module: models)
|
||||
@ -1530,9 +1544,10 @@ RLAPI void UpdateMeshBuffer(Mesh mesh, int index, const void *data, int dataSize
|
||||
RLAPI void UnloadMesh(Mesh mesh); // Unload mesh data from CPU and GPU
|
||||
RLAPI void DrawMesh(Mesh mesh, Material material, Matrix transform); // Draw a 3d mesh with material and transform
|
||||
RLAPI void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, int instances); // Draw multiple mesh instances with material and different transforms
|
||||
RLAPI bool ExportMesh(Mesh mesh, const char *fileName); // Export mesh data to file, returns true on success
|
||||
RLAPI BoundingBox GetMeshBoundingBox(Mesh mesh); // Compute mesh bounding box limits
|
||||
RLAPI void GenMeshTangents(Mesh *mesh); // Compute mesh tangents
|
||||
RLAPI bool ExportMesh(Mesh mesh, const char *fileName); // Export mesh data to file, returns true on success
|
||||
RLAPI bool ExportMeshAsCode(Mesh mesh, const char *fileName); // Export mesh as code file (.h) defining multiple arrays of vertex attributes
|
||||
|
||||
// Mesh generation functions
|
||||
RLAPI Mesh GenMeshPoly(int sides, float radius); // Generate polygonal mesh
|
||||
@ -1649,10 +1664,10 @@ RLAPI void SetAudioStreamPan(AudioStream stream, float pan); // Set pan
|
||||
RLAPI void SetAudioStreamBufferSizeDefault(int size); // Default size for new audio streams
|
||||
RLAPI void SetAudioStreamCallback(AudioStream stream, AudioCallback callback); // Audio thread callback to request new data
|
||||
|
||||
RLAPI void AttachAudioStreamProcessor(AudioStream stream, AudioCallback processor); // Attach audio stream processor to stream, receives the samples as <float>s
|
||||
RLAPI void AttachAudioStreamProcessor(AudioStream stream, AudioCallback processor); // Attach audio stream processor to stream, receives the samples as 'float'
|
||||
RLAPI void DetachAudioStreamProcessor(AudioStream stream, AudioCallback processor); // Detach audio stream processor from stream
|
||||
|
||||
RLAPI void AttachAudioMixedProcessor(AudioCallback processor); // Attach audio stream processor to the entire audio pipeline, receives the samples as <float>s
|
||||
RLAPI void AttachAudioMixedProcessor(AudioCallback processor); // Attach audio stream processor to the entire audio pipeline, receives the samples as 'float'
|
||||
RLAPI void DetachAudioMixedProcessor(AudioCallback processor); // Detach audio stream processor from the entire audio pipeline
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
113
lib/raylib.zig
113
lib/raylib.zig
@ -795,6 +795,18 @@ pub const FilePathList = extern struct {
|
||||
paths: [*c][*c]u8,
|
||||
};
|
||||
|
||||
pub const AutomationEvent = extern struct {
|
||||
frame: c_uint,
|
||||
@"type": c_uint,
|
||||
params: [4]c_int,
|
||||
};
|
||||
|
||||
pub const AutomationEventList = extern struct {
|
||||
capacity: c_uint,
|
||||
count: c_uint,
|
||||
events: [*c]AutomationEvent
|
||||
};
|
||||
|
||||
pub const ConfigFlags = enum(c_int) {
|
||||
flag_fullscreen_mode = 2,
|
||||
flag_window_resizable = 4,
|
||||
@ -1164,21 +1176,10 @@ pub const LoadFileTextCallback = *const fn ([*c]const u8) callconv(.C) [*c]u8;
|
||||
pub const SaveFileTextCallback = *const fn ([*c]const u8, [*c]u8) callconv(.C) bool;
|
||||
pub const AudioCallback = ?*const fn (?*anyopaque, c_uint) callconv(.C) void;
|
||||
|
||||
pub const AutomationEvent = extern struct {
|
||||
frame: c_uint = @import("std").mem.zeroes(c_uint),
|
||||
type: c_uint = @import("std").mem.zeroes(c_uint),
|
||||
params: [4]c_int = @import("std").mem.zeroes([4]c_int),
|
||||
};
|
||||
pub const AutomationEventList = extern struct {
|
||||
capacity: c_uint = @import("std").mem.zeroes(c_uint),
|
||||
count: c_uint = @import("std").mem.zeroes(c_uint),
|
||||
events: [*c]AutomationEvent = @import("std").mem.zeroes([*c]AutomationEvent),
|
||||
};
|
||||
|
||||
pub const RAYLIB_VERSION_MAJOR = @as(i32, 4);
|
||||
pub const RAYLIB_VERSION_MINOR = @as(i32, 6);
|
||||
pub const RAYLIB_VERSION_MAJOR = @as(i32, 5);
|
||||
pub const RAYLIB_VERSION_MINOR = @as(i32, 1);
|
||||
pub const RAYLIB_VERSION_PATCH = @as(i32, 0);
|
||||
pub const RAYLIB_VERSION = "4.6-dev";
|
||||
pub const RAYLIB_VERSION = "5.1-dev";
|
||||
|
||||
pub const MAX_TOUCH_POINTS = 10;
|
||||
pub const MAX_MATERIAL_MAPS = 12;
|
||||
@ -1271,6 +1272,10 @@ pub fn decodeDataBase64(data: []const u8) []u8 {
|
||||
return res;
|
||||
}
|
||||
|
||||
pub fn loadImageAnimFromMemory(fileType: [:0]const u8, fileData: []const u8, frames: *i32) Image {
|
||||
return cdef.LoadImageAnimFromMemory(@as([*c]const u8, @ptrCast(fileType)), @as([*c]const u8, @ptrCast(fileData)), @as(c_int, @intCast(fileData.len)), @as([*c]c_int, @ptrCast(frames)));
|
||||
}
|
||||
|
||||
pub fn loadImageFromMemory(fileType: [:0]const u8, fileData: []const u8) Image {
|
||||
return cdef.LoadImageFromMemory(@as([*c]const u8, @ptrCast(fileType)), @as([*c]const u8, @ptrCast(fileData)), @as(c_int, @intCast(fileData.len)));
|
||||
}
|
||||
@ -1753,26 +1758,18 @@ pub fn unloadShader(shader: Shader) void {
|
||||
cdef.UnloadShader(shader);
|
||||
}
|
||||
|
||||
pub fn getMouseRay(mousePosition: Vector2, camera: Camera) Ray {
|
||||
return cdef.GetMouseRay(mousePosition, camera);
|
||||
pub fn getScreenToWorldRay(position: Vector2, camera: Camera) Ray {
|
||||
return cdef.GetScreenToWorldRay(position, camera);
|
||||
}
|
||||
|
||||
pub fn getCameraMatrix(camera: Camera) Matrix {
|
||||
return cdef.GetCameraMatrix(camera);
|
||||
}
|
||||
|
||||
pub fn getCameraMatrix2D(camera: Camera2D) Matrix {
|
||||
return cdef.GetCameraMatrix2D(camera);
|
||||
pub fn getScreenToWorldRayEx(position: Vector2, camera: Camera, width: i32, height: i32) Ray {
|
||||
return cdef.GetScreenToWorldRayEx(position, camera, @as(c_int, width), @as(c_int, height));
|
||||
}
|
||||
|
||||
pub fn getWorldToScreen(position: Vector3, camera: Camera) Vector2 {
|
||||
return cdef.GetWorldToScreen(position, camera);
|
||||
}
|
||||
|
||||
pub fn getScreenToWorld2D(position: Vector2, camera: Camera2D) Vector2 {
|
||||
return cdef.GetScreenToWorld2D(position, camera);
|
||||
}
|
||||
|
||||
pub fn getWorldToScreenEx(position: Vector3, camera: Camera, width: i32, height: i32) Vector2 {
|
||||
return cdef.GetWorldToScreenEx(position, camera, @as(c_int, width), @as(c_int, height));
|
||||
}
|
||||
@ -1781,6 +1778,18 @@ pub fn getWorldToScreen2D(position: Vector2, camera: Camera2D) Vector2 {
|
||||
return cdef.GetWorldToScreen2D(position, camera);
|
||||
}
|
||||
|
||||
pub fn getScreenToWorld2D(position: Vector2, camera: Camera2D) Vector2 {
|
||||
return cdef.GetScreenToWorld2D(position, camera);
|
||||
}
|
||||
|
||||
pub fn getCameraMatrix(camera: Camera) Matrix {
|
||||
return cdef.GetCameraMatrix(camera);
|
||||
}
|
||||
|
||||
pub fn getCameraMatrix2D(camera: Camera2D) Matrix {
|
||||
return cdef.GetCameraMatrix2D(camera);
|
||||
}
|
||||
|
||||
pub fn setTargetFPS(fps: i32) void {
|
||||
cdef.SetTargetFPS(@as(c_int, fps));
|
||||
}
|
||||
@ -1969,8 +1978,8 @@ pub fn loadAutomationEventList(fileName: [:0]const u8) AutomationEventList {
|
||||
return cdef.LoadAutomationEventList(@as([*c]const u8, @ptrCast(fileName)));
|
||||
}
|
||||
|
||||
pub fn unloadAutomationEventList(list: *AutomationEventList) void {
|
||||
cdef.UnloadAutomationEventList(@as([*c]AutomationEventList, @ptrCast(list)));
|
||||
pub fn unloadAutomationEventList(list: AutomationEventList) void {
|
||||
cdef.UnloadAutomationEventList(list);
|
||||
}
|
||||
|
||||
pub fn exportAutomationEventList(list: AutomationEventList, fileName: [:0]const u8) bool {
|
||||
@ -2069,6 +2078,10 @@ pub fn setGamepadMappings(mappings: [:0]const u8) i32 {
|
||||
return @as(i32, cdef.SetGamepadMappings(@as([*c]const u8, @ptrCast(mappings))));
|
||||
}
|
||||
|
||||
pub fn setGamepadVibration(gamepad: i32, leftMotor: f32, rightMotor: f32) void {
|
||||
cdef.SetGamepadVibration(@as(c_int, gamepad), leftMotor, rightMotor);
|
||||
}
|
||||
|
||||
pub fn isMouseButtonPressed(button: MouseButton) bool {
|
||||
return cdef.IsMouseButtonPressed(button);
|
||||
}
|
||||
@ -2189,6 +2202,14 @@ pub fn setShapesTexture(texture: Texture2D, source: Rectangle) void {
|
||||
cdef.SetShapesTexture(texture, source);
|
||||
}
|
||||
|
||||
pub fn getShapesTexture() Texture2D {
|
||||
return cdef.GetShapesTexture();
|
||||
}
|
||||
|
||||
pub fn getShapesTextureRectangle() Rectangle {
|
||||
return cdef.GetShapesTextureRectangle();
|
||||
}
|
||||
|
||||
pub fn drawPixel(posX: i32, posY: i32, color: Color) void {
|
||||
cdef.DrawPixel(@as(c_int, posX), @as(c_int, posY), color);
|
||||
}
|
||||
@ -2297,8 +2318,12 @@ pub fn drawRectangleRounded(rec: Rectangle, roundness: f32, segments: i32, color
|
||||
cdef.DrawRectangleRounded(rec, roundness, @as(c_int, segments), color);
|
||||
}
|
||||
|
||||
pub fn drawRectangleRoundedLines(rec: Rectangle, roundness: f32, segments: i32, lineThick: f32, color: Color) void {
|
||||
cdef.DrawRectangleRoundedLines(rec, roundness, @as(c_int, segments), lineThick, color);
|
||||
pub fn drawRectangleRoundedLines(rec: Rectangle, roundness: f32, segments: i32, color: Color) void {
|
||||
cdef.DrawRectangleRoundedLines(rec, roundness, @as(c_int, segments), color);
|
||||
}
|
||||
|
||||
pub fn drawRectangleRoundedLinesEx(rec: Rectangle, roundness: f32, segments: i32, lineThick: f32, color: Color) void {
|
||||
cdef.DrawRectangleRoundedLinesEx(rec, roundness, @as(c_int, segments), lineThick, color);
|
||||
}
|
||||
|
||||
pub fn drawTriangle(v1: Vector2, v2: Vector2, v3: Vector2, color: Color) void {
|
||||
@ -2545,6 +2570,10 @@ pub fn imageBlurGaussian(image: *Image, blurSize: i32) void {
|
||||
cdef.ImageBlurGaussian(@as([*c]Image, @ptrCast(image)), @as(c_int, blurSize));
|
||||
}
|
||||
|
||||
pub fn imageKernelConvolution(image: *Image, kernel: []f32, kernelSize: i32) void {
|
||||
cdef.ImageKernelConvolution(@as([*c]Image, @ptrCast(image)), @as([*c]f32, @ptrCast(kernel)), @as(c_int, kernelSize));
|
||||
}
|
||||
|
||||
pub fn imageResize(image: *Image, newWidth: i32, newHeight: i32) void {
|
||||
cdef.ImageResize(@as([*c]Image, @ptrCast(image)), @as(c_int, newWidth), @as(c_int, newHeight));
|
||||
}
|
||||
@ -2765,6 +2794,10 @@ pub fn drawTextureNPatch(texture: Texture2D, nPatchInfo: NPatchInfo, dest: Recta
|
||||
cdef.DrawTextureNPatch(texture, nPatchInfo, dest, origin, rotation, tint);
|
||||
}
|
||||
|
||||
pub fn colorIsEqual(col1: Color, col2: Color) bool {
|
||||
return cdef.ColorIsEqual(col1, col2);
|
||||
}
|
||||
|
||||
pub fn fade(color: Color, alpha: f32) Color {
|
||||
return cdef.Fade(color, alpha);
|
||||
}
|
||||
@ -2937,8 +2970,8 @@ pub fn textSubtext(text: [:0]const u8, position: i32, length: i32) [:0]const u8
|
||||
return std.mem.span(cdef.TextSubtext(@as([*c]const u8, @ptrCast(text)), @as(c_int, position), @as(c_int, length)));
|
||||
}
|
||||
|
||||
pub fn textReplace(text: [:0]u8, replace: [:0]const u8, by: [:0]const u8) [:0]u8 {
|
||||
return std.mem.span(cdef.TextReplace(@as([*c]u8, @ptrCast(text)), @as([*c]const u8, @ptrCast(replace)), @as([*c]const u8, @ptrCast(by))));
|
||||
pub fn textReplace(text: [:0]const u8, replace: [:0]const u8, by: [:0]const u8) [:0]u8 {
|
||||
return std.mem.span(cdef.TextReplace(@as([*c]const u8, @ptrCast(text)), @as([*c]const u8, @ptrCast(replace)), @as([*c]const u8, @ptrCast(by))));
|
||||
}
|
||||
|
||||
pub fn textInsert(text: [:0]const u8, insert: [:0]const u8, position: i32) [:0]u8 {
|
||||
@ -2969,6 +3002,10 @@ pub fn textToInteger(text: [:0]const u8) i32 {
|
||||
return @as(i32, cdef.TextToInteger(@as([*c]const u8, @ptrCast(text))));
|
||||
}
|
||||
|
||||
pub fn textToFloat(text: [:0]const u8) f32 {
|
||||
return cdef.TextToFloat(@as([*c]const u8, @ptrCast(text)));
|
||||
}
|
||||
|
||||
pub fn drawLine3D(startPos: Vector3, endPos: Vector3, color: Color) void {
|
||||
cdef.DrawLine3D(startPos, endPos, color);
|
||||
}
|
||||
@ -3117,10 +3154,6 @@ pub fn drawMesh(mesh: Mesh, material: Material, transform: Matrix) void {
|
||||
cdef.DrawMesh(mesh, material, transform);
|
||||
}
|
||||
|
||||
pub fn exportMesh(mesh: Mesh, fileName: [:0]const u8) bool {
|
||||
return cdef.ExportMesh(mesh, @as([*c]const u8, @ptrCast(fileName)));
|
||||
}
|
||||
|
||||
pub fn getMeshBoundingBox(mesh: Mesh) BoundingBox {
|
||||
return cdef.GetMeshBoundingBox(mesh);
|
||||
}
|
||||
@ -3129,6 +3162,14 @@ pub fn genMeshTangents(mesh: *Mesh) void {
|
||||
cdef.GenMeshTangents(@as([*c]Mesh, @ptrCast(mesh)));
|
||||
}
|
||||
|
||||
pub fn exportMesh(mesh: Mesh, fileName: [:0]const u8) bool {
|
||||
return cdef.ExportMesh(mesh, @as([*c]const u8, @ptrCast(fileName)));
|
||||
}
|
||||
|
||||
pub fn exportMeshAsCode(mesh: Mesh, fileName: [:0]const u8) bool {
|
||||
return cdef.ExportMeshAsCode(mesh, @as([*c]const u8, @ptrCast(fileName)));
|
||||
}
|
||||
|
||||
pub fn genMeshPoly(sides: i32, radius: f32) Mesh {
|
||||
return cdef.GenMeshPoly(@as(c_int, sides), radius);
|
||||
}
|
||||
|
@ -30,12 +30,15 @@ pub extern "c" fn Vector2Normalize(v: rl.Vector2) rl.Vector2;
|
||||
pub extern "c" fn Vector2Transform(v: rl.Vector2, mat: rl.Matrix) rl.Vector2;
|
||||
pub extern "c" fn Vector2Lerp(v1: rl.Vector2, v2: rl.Vector2, amount: f32) rl.Vector2;
|
||||
pub extern "c" fn Vector2Reflect(v: rl.Vector2, normal: rl.Vector2) rl.Vector2;
|
||||
pub extern "c" fn Vector2Min(v1: rl.Vector2, v2: rl.Vector2) rl.Vector2;
|
||||
pub extern "c" fn Vector2Max(v1: rl.Vector2, v2: rl.Vector2) rl.Vector2;
|
||||
pub extern "c" fn Vector2Rotate(v: rl.Vector2, angle: f32) rl.Vector2;
|
||||
pub extern "c" fn Vector2MoveTowards(v: rl.Vector2, target: rl.Vector2, maxDistance: f32) rl.Vector2;
|
||||
pub extern "c" fn Vector2Invert(v: rl.Vector2) rl.Vector2;
|
||||
pub extern "c" fn Vector2Clamp(v: rl.Vector2, min: rl.Vector2, max: rl.Vector2) rl.Vector2;
|
||||
pub extern "c" fn Vector2ClampValue(v: rl.Vector2, min: f32, max: f32) rl.Vector2;
|
||||
pub extern "c" fn Vector2Equals(p: rl.Vector2, q: rl.Vector2) c_int;
|
||||
pub extern "c" fn Vector2Refract(v: rl.Vector2, n: rl.Vector2, r: f32) rl.Vector2;
|
||||
pub extern "c" fn Vector3Zero() rl.Vector3;
|
||||
pub extern "c" fn Vector3One() rl.Vector3;
|
||||
pub extern "c" fn Vector3Add(v1: rl.Vector3, v2: rl.Vector3) rl.Vector3;
|
||||
@ -61,7 +64,9 @@ pub extern "c" fn Vector3OrthoNormalize(v1: [*c]rl.Vector3, v2: [*c]rl.Vector3)
|
||||
pub extern "c" fn Vector3Transform(v: rl.Vector3, mat: rl.Matrix) rl.Vector3;
|
||||
pub extern "c" fn Vector3RotateByQuaternion(v: rl.Vector3, q: rl.Quaternion) rl.Vector3;
|
||||
pub extern "c" fn Vector3RotateByAxisAngle(v: rl.Vector3, axis: rl.Vector3, angle: f32) rl.Vector3;
|
||||
pub extern "c" fn Vector3MoveTowards(v: rl.Vector3, target: rl.Vector3, maxDistance: f32) rl.Vector3;
|
||||
pub extern "c" fn Vector3Lerp(v1: rl.Vector3, v2: rl.Vector3, amount: f32) rl.Vector3;
|
||||
pub extern "c" fn Vector3CubicHermite(v1: rl.Vector3, tangent1: rl.Vector3, v2: rl.Vector3, tangent2: rl.Vector3, amount: f32) rl.Vector3;
|
||||
pub extern "c" fn Vector3Reflect(v: rl.Vector3, normal: rl.Vector3) rl.Vector3;
|
||||
pub extern "c" fn Vector3Min(v1: rl.Vector3, v2: rl.Vector3) rl.Vector3;
|
||||
pub extern "c" fn Vector3Max(v1: rl.Vector3, v2: rl.Vector3) rl.Vector3;
|
||||
@ -73,6 +78,28 @@ pub extern "c" fn Vector3Clamp(v: rl.Vector3, min: rl.Vector3, max: rl.Vector3)
|
||||
pub extern "c" fn Vector3ClampValue(v: rl.Vector3, min: f32, max: f32) rl.Vector3;
|
||||
pub extern "c" fn Vector3Equals(p: rl.Vector3, q: rl.Vector3) c_int;
|
||||
pub extern "c" fn Vector3Refract(v: rl.Vector3, n: rl.Vector3, r: f32) rl.Vector3;
|
||||
pub extern "c" fn Vector4Zero() rl.Vector4;
|
||||
pub extern "c" fn Vector4One() rl.Vector4;
|
||||
pub extern "c" fn Vector4Add(v1: rl.Vector4, v2: rl.Vector4) rl.Vector4;
|
||||
pub extern "c" fn Vector4AddValue(v: rl.Vector4, add: f32) rl.Vector4;
|
||||
pub extern "c" fn Vector4Subtract(v1: rl.Vector4, v2: rl.Vector4) rl.Vector4;
|
||||
pub extern "c" fn Vector4SubtractValue(v: rl.Vector4, add: f32) rl.Vector4;
|
||||
pub extern "c" fn Vector4Length(v: rl.Vector4) f32;
|
||||
pub extern "c" fn Vector4LengthSqr(v: rl.Vector4) f32;
|
||||
pub extern "c" fn Vector4DotProduct(v1: rl.Vector4, v2: rl.Vector4) f32;
|
||||
pub extern "c" fn Vector4Distance(v1: rl.Vector4, v2: rl.Vector4) f32;
|
||||
pub extern "c" fn Vector4DistanceSqr(v1: rl.Vector4, v2: rl.Vector4) f32;
|
||||
pub extern "c" fn Vector4Scale(v: rl.Vector4, scale: f32) rl.Vector4;
|
||||
pub extern "c" fn Vector4Multiply(v1: rl.Vector4, v2: rl.Vector4) rl.Vector4;
|
||||
pub extern "c" fn Vector4Negate(v: rl.Vector4) rl.Vector4;
|
||||
pub extern "c" fn Vector4Divide(v1: rl.Vector4, v2: rl.Vector4) rl.Vector4;
|
||||
pub extern "c" fn Vector4Normalize(v: rl.Vector4) rl.Vector4;
|
||||
pub extern "c" fn Vector4Min(v1: rl.Vector4, v2: rl.Vector4) rl.Vector4;
|
||||
pub extern "c" fn Vector4Max(v1: rl.Vector4, v2: rl.Vector4) rl.Vector4;
|
||||
pub extern "c" fn Vector4Lerp(v1: rl.Vector4, v2: rl.Vector4, amount: f32) rl.Vector4;
|
||||
pub extern "c" fn Vector4MoveTowards(v: rl.Vector4, target: rl.Vector4, maxDistance: f32) rl.Vector4;
|
||||
pub extern "c" fn Vector4Invert(v: rl.Vector4) rl.Vector4;
|
||||
pub extern "c" fn Vector4Equals(p: rl.Vector4, q: rl.Vector4) c_int;
|
||||
pub extern "c" fn MatrixDeterminant(mat: rl.Matrix) f32;
|
||||
pub extern "c" fn MatrixTrace(mat: rl.Matrix) f32;
|
||||
pub extern "c" fn MatrixTranspose(mat: rl.Matrix) rl.Matrix;
|
||||
@ -108,6 +135,7 @@ pub extern "c" fn QuaternionDivide(q1: rl.Quaternion, q2: rl.Quaternion) rl.Quat
|
||||
pub extern "c" fn QuaternionLerp(q1: rl.Quaternion, q2: rl.Quaternion, amount: f32) rl.Quaternion;
|
||||
pub extern "c" fn QuaternionNlerp(q1: rl.Quaternion, q2: rl.Quaternion, amount: f32) rl.Quaternion;
|
||||
pub extern "c" fn QuaternionSlerp(q1: rl.Quaternion, q2: rl.Quaternion, amount: f32) rl.Quaternion;
|
||||
pub extern "c" fn QuaternionCubicHermiteSpline(q1: rl.Quaternion, outTangent1: rl.Quaternion, q2: rl.Quaternion, inTangent2: rl.Quaternion, t: f32) rl.Quaternion;
|
||||
pub extern "c" fn QuaternionFromVector3ToVector3(from: rl.Vector3, to: rl.Vector3) rl.Quaternion;
|
||||
pub extern "c" fn QuaternionFromMatrix(mat: rl.Matrix) rl.Quaternion;
|
||||
pub extern "c" fn QuaternionToMatrix(q: rl.Quaternion) rl.Matrix;
|
||||
|
389
lib/raymath.h
389
lib/raymath.h
@ -30,7 +30,7 @@
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2015-2023 Ramon Santamaria (@raysan5)
|
||||
* Copyright (c) 2015-2024 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||
* will the authors be held liable for any damages arising from the use of this software.
|
||||
@ -59,7 +59,9 @@
|
||||
// Function specifiers definition
|
||||
#if defined(RAYMATH_IMPLEMENTATION)
|
||||
#if defined(_WIN32) && defined(BUILD_LIBTYPE_SHARED)
|
||||
#define RMAPI __declspec(dllexport) extern inline // We are building raylib as a Win32 shared library (.dll).
|
||||
#define RMAPI __declspec(dllexport) extern inline // We are building raylib as a Win32 shared library (.dll)
|
||||
#elif defined(BUILD_LIBTYPE_SHARED)
|
||||
#define RMAPI __attribute__((visibility("default"))) // We are building raylib as a Unix shared library (.so/.dylib)
|
||||
#elif defined(_WIN32) && defined(USE_LIBTYPE_SHARED)
|
||||
#define RMAPI __declspec(dllimport) // We are using raylib as a Win32 shared library (.dll)
|
||||
#else
|
||||
@ -163,7 +165,7 @@ typedef struct float16 {
|
||||
float v[16];
|
||||
} float16;
|
||||
|
||||
#include <math.h> // Required for: sinf(), cosf(), tan(), atan2f(), sqrtf(), floor(), fminf(), fmaxf(), fabs()
|
||||
#include <math.h> // Required for: sinf(), cosf(), tan(), atan2f(), sqrtf(), floor(), fminf(), fmaxf(), fabsf()
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition - Utils math
|
||||
@ -172,7 +174,7 @@ typedef struct float16 {
|
||||
// Clamp float value
|
||||
RMAPI float Clamp(float value, float min, float max)
|
||||
{
|
||||
float result = (value < min)? min : value;
|
||||
float result = (value < min) ? min : value;
|
||||
|
||||
if (result > max) result = max;
|
||||
|
||||
@ -429,6 +431,28 @@ RMAPI Vector2 Vector2Reflect(Vector2 v, Vector2 normal)
|
||||
return result;
|
||||
}
|
||||
|
||||
// Get min value for each pair of components
|
||||
RMAPI Vector2 Vector2Min(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
Vector2 result = { 0 };
|
||||
|
||||
result.x = fminf(v1.x, v2.x);
|
||||
result.y = fminf(v1.y, v2.y);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Get max value for each pair of components
|
||||
RMAPI Vector2 Vector2Max(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
Vector2 result = { 0 };
|
||||
|
||||
result.x = fmaxf(v1.x, v2.x);
|
||||
result.y = fmaxf(v1.y, v2.y);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Rotate vector by angle
|
||||
RMAPI Vector2 Vector2Rotate(Vector2 v, float angle)
|
||||
{
|
||||
@ -492,18 +516,18 @@ RMAPI Vector2 Vector2ClampValue(Vector2 v, float min, float max)
|
||||
{
|
||||
length = sqrtf(length);
|
||||
|
||||
float scale = 1; // By default, 1 as the neutral element.
|
||||
if (length < min)
|
||||
{
|
||||
float scale = min/length;
|
||||
result.x = v.x*scale;
|
||||
result.y = v.y*scale;
|
||||
scale = min/length;
|
||||
}
|
||||
else if (length > max)
|
||||
{
|
||||
float scale = max/length;
|
||||
result.x = v.x*scale;
|
||||
result.y = v.y*scale;
|
||||
scale = max/length;
|
||||
}
|
||||
|
||||
result.x = v.x*scale;
|
||||
result.y = v.y*scale;
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -522,6 +546,31 @@ RMAPI int Vector2Equals(Vector2 p, Vector2 q)
|
||||
return result;
|
||||
}
|
||||
|
||||
// Compute the direction of a refracted ray
|
||||
// v: normalized direction of the incoming ray
|
||||
// n: normalized normal vector of the interface of two optical media
|
||||
// r: ratio of the refractive index of the medium from where the ray comes
|
||||
// to the refractive index of the medium on the other side of the surface
|
||||
RMAPI Vector2 Vector2Refract(Vector2 v, Vector2 n, float r)
|
||||
{
|
||||
Vector2 result = { 0 };
|
||||
|
||||
float dot = v.x*n.x + v.y*n.y;
|
||||
float d = 1.0f - r*r*(1.0f - dot*dot);
|
||||
|
||||
if (d >= 0.0f)
|
||||
{
|
||||
d = sqrtf(d);
|
||||
v.x = r*v.x - (r*dot + d)*n.x;
|
||||
v.y = r*v.y - (r*dot + d)*n.y;
|
||||
|
||||
result = v;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition - Vector3 math
|
||||
//----------------------------------------------------------------------------------
|
||||
@ -603,12 +652,12 @@ RMAPI Vector3 Vector3Perpendicular(Vector3 v)
|
||||
{
|
||||
Vector3 result = { 0 };
|
||||
|
||||
float min = (float) fabs(v.x);
|
||||
float min = fabsf(v.x);
|
||||
Vector3 cardinalAxis = {1.0f, 0.0f, 0.0f};
|
||||
|
||||
if (fabsf(v.y) < min)
|
||||
{
|
||||
min = (float) fabs(v.y);
|
||||
min = fabsf(v.y);
|
||||
Vector3 tmp = {0.0f, 1.0f, 0.0f};
|
||||
cardinalAxis = tmp;
|
||||
}
|
||||
@ -728,7 +777,7 @@ RMAPI Vector3 Vector3Normalize(Vector3 v)
|
||||
RMAPI Vector3 Vector3Project(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
Vector3 result = { 0 };
|
||||
|
||||
|
||||
float v1dv2 = (v1.x*v2.x + v1.y*v2.y + v1.z*v2.z);
|
||||
float v2dv2 = (v2.x*v2.x + v2.y*v2.y + v2.z*v2.z);
|
||||
|
||||
@ -745,7 +794,7 @@ RMAPI Vector3 Vector3Project(Vector3 v1, Vector3 v2)
|
||||
RMAPI Vector3 Vector3Reject(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
Vector3 result = { 0 };
|
||||
|
||||
|
||||
float v1dv2 = (v1.x*v2.x + v1.y*v2.y + v1.z*v2.z);
|
||||
float v2dv2 = (v2.x*v2.x + v2.y*v2.y + v2.z*v2.z);
|
||||
|
||||
@ -832,7 +881,7 @@ RMAPI Vector3 Vector3RotateByAxisAngle(Vector3 v, Vector3 axis, float angle)
|
||||
// Vector3Normalize(axis);
|
||||
float length = sqrtf(axis.x*axis.x + axis.y*axis.y + axis.z*axis.z);
|
||||
if (length == 0.0f) length = 1.0f;
|
||||
float ilength = 1.0f / length;
|
||||
float ilength = 1.0f/length;
|
||||
axis.x *= ilength;
|
||||
axis.y *= ilength;
|
||||
axis.z *= ilength;
|
||||
@ -873,6 +922,27 @@ RMAPI Vector3 Vector3RotateByAxisAngle(Vector3 v, Vector3 axis, float angle)
|
||||
return result;
|
||||
}
|
||||
|
||||
// Move Vector towards target
|
||||
RMAPI Vector3 Vector3MoveTowards(Vector3 v, Vector3 target, float maxDistance)
|
||||
{
|
||||
Vector3 result = { 0 };
|
||||
|
||||
float dx = target.x - v.x;
|
||||
float dy = target.y - v.y;
|
||||
float dz = target.z - v.z;
|
||||
float value = (dx*dx) + (dy*dy) + (dz*dz);
|
||||
|
||||
if ((value == 0) || ((maxDistance >= 0) && (value <= maxDistance*maxDistance))) return target;
|
||||
|
||||
float dist = sqrtf(value);
|
||||
|
||||
result.x = v.x + dx/dist*maxDistance;
|
||||
result.y = v.y + dy/dist*maxDistance;
|
||||
result.z = v.z + dz/dist*maxDistance;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Calculate linear interpolation between two vectors
|
||||
RMAPI Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount)
|
||||
{
|
||||
@ -885,6 +955,22 @@ RMAPI Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount)
|
||||
return result;
|
||||
}
|
||||
|
||||
// Calculate cubic hermite interpolation between two vectors and their tangents
|
||||
// as described in the GLTF 2.0 specification: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#interpolation-cubic
|
||||
RMAPI Vector3 Vector3CubicHermite(Vector3 v1, Vector3 tangent1, Vector3 v2, Vector3 tangent2, float amount)
|
||||
{
|
||||
Vector3 result = { 0 };
|
||||
|
||||
float amountPow2 = amount * amount;
|
||||
float amountPow3 = amount * amount * amount;
|
||||
|
||||
result.x = (2 * amountPow3 - 3 * amountPow2 + 1) * v1.x + (amountPow3 - 2 * amountPow2 + amount) * tangent1.x + (-2 * amountPow3 + 3 * amountPow2) * v2.x + (amountPow3 - amountPow2) * tangent2.x;
|
||||
result.y = (2 * amountPow3 - 3 * amountPow2 + 1) * v1.y + (amountPow3 - 2 * amountPow2 + amount) * tangent1.y + (-2 * amountPow3 + 3 * amountPow2) * v2.y + (amountPow3 - amountPow2) * tangent2.y;
|
||||
result.z = (2 * amountPow3 - 3 * amountPow2 + 1) * v1.z + (amountPow3 - 2 * amountPow2 + amount) * tangent1.z + (-2 * amountPow3 + 3 * amountPow2) * v2.z + (amountPow3 - amountPow2) * tangent2.z;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Calculate reflected vector to normal
|
||||
RMAPI Vector3 Vector3Reflect(Vector3 v, Vector3 normal)
|
||||
{
|
||||
@ -1078,20 +1164,19 @@ RMAPI Vector3 Vector3ClampValue(Vector3 v, float min, float max)
|
||||
{
|
||||
length = sqrtf(length);
|
||||
|
||||
float scale = 1; // By default, 1 as the neutral element.
|
||||
if (length < min)
|
||||
{
|
||||
float scale = min/length;
|
||||
result.x = v.x*scale;
|
||||
result.y = v.y*scale;
|
||||
result.z = v.z*scale;
|
||||
scale = min/length;
|
||||
}
|
||||
else if (length > max)
|
||||
{
|
||||
float scale = max/length;
|
||||
result.x = v.x*scale;
|
||||
result.y = v.y*scale;
|
||||
result.z = v.z*scale;
|
||||
scale = max/length;
|
||||
}
|
||||
|
||||
result.x = v.x*scale;
|
||||
result.y = v.y*scale;
|
||||
result.z = v.z*scale;
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -1136,6 +1221,233 @@ RMAPI Vector3 Vector3Refract(Vector3 v, Vector3 n, float r)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition - Vector4 math
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
RMAPI Vector4 Vector4Zero(void)
|
||||
{
|
||||
Vector4 result = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
return result;
|
||||
}
|
||||
|
||||
RMAPI Vector4 Vector4One(void)
|
||||
{
|
||||
Vector4 result = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
return result;
|
||||
}
|
||||
|
||||
RMAPI Vector4 Vector4Add(Vector4 v1, Vector4 v2)
|
||||
{
|
||||
Vector4 result = {
|
||||
v1.x + v2.x,
|
||||
v1.y + v2.y,
|
||||
v1.z + v2.z,
|
||||
v1.w + v2.w
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
RMAPI Vector4 Vector4AddValue(Vector4 v, float add)
|
||||
{
|
||||
Vector4 result = {
|
||||
v.x + add,
|
||||
v.y + add,
|
||||
v.z + add,
|
||||
v.w + add
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
RMAPI Vector4 Vector4Subtract(Vector4 v1, Vector4 v2)
|
||||
{
|
||||
Vector4 result = {
|
||||
v1.x - v2.x,
|
||||
v1.y - v2.y,
|
||||
v1.z - v2.z,
|
||||
v1.w - v2.w
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
RMAPI Vector4 Vector4SubtractValue(Vector4 v, float add)
|
||||
{
|
||||
Vector4 result = {
|
||||
v.x - add,
|
||||
v.y - add,
|
||||
v.z - add,
|
||||
v.w - add
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
RMAPI float Vector4Length(Vector4 v)
|
||||
{
|
||||
float result = sqrtf((v.x*v.x) + (v.y*v.y) + (v.z*v.z) + (v.w*v.w));
|
||||
return result;
|
||||
}
|
||||
|
||||
RMAPI float Vector4LengthSqr(Vector4 v)
|
||||
{
|
||||
float result = (v.x*v.x) + (v.y*v.y) + (v.z*v.z) + (v.w*v.w);
|
||||
return result;
|
||||
}
|
||||
|
||||
RMAPI float Vector4DotProduct(Vector4 v1, Vector4 v2)
|
||||
{
|
||||
float result = (v1.x*v2.x + v1.y*v2.y + v1.z*v2.z + v1.w*v2.w);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Calculate distance between two vectors
|
||||
RMAPI float Vector4Distance(Vector4 v1, Vector4 v2)
|
||||
{
|
||||
float result = sqrtf(
|
||||
(v1.x - v2.x)*(v1.x - v2.x) + (v1.y - v2.y)*(v1.y - v2.y) +
|
||||
(v1.z - v2.z)*(v1.z - v2.z) + (v1.w - v2.w)*(v1.w - v2.w));
|
||||
return result;
|
||||
}
|
||||
|
||||
// Calculate square distance between two vectors
|
||||
RMAPI float Vector4DistanceSqr(Vector4 v1, Vector4 v2)
|
||||
{
|
||||
float result =
|
||||
(v1.x - v2.x)*(v1.x - v2.x) + (v1.y - v2.y)*(v1.y - v2.y) +
|
||||
(v1.z - v2.z)*(v1.z - v2.z) + (v1.w - v2.w)*(v1.w - v2.w);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
RMAPI Vector4 Vector4Scale(Vector4 v, float scale)
|
||||
{
|
||||
Vector4 result = { v.x*scale, v.y*scale, v.z*scale, v.w*scale };
|
||||
return result;
|
||||
}
|
||||
|
||||
// Multiply vector by vector
|
||||
RMAPI Vector4 Vector4Multiply(Vector4 v1, Vector4 v2)
|
||||
{
|
||||
Vector4 result = { v1.x*v2.x, v1.y*v2.y, v1.z*v2.z, v1.w*v2.w };
|
||||
return result;
|
||||
}
|
||||
|
||||
// Negate vector
|
||||
RMAPI Vector4 Vector4Negate(Vector4 v)
|
||||
{
|
||||
Vector4 result = { -v.x, -v.y, -v.z, -v.w };
|
||||
return result;
|
||||
}
|
||||
|
||||
// Divide vector by vector
|
||||
RMAPI Vector4 Vector4Divide(Vector4 v1, Vector4 v2)
|
||||
{
|
||||
Vector4 result = { v1.x/v2.x, v1.y/v2.y, v1.z/v2.z, v1.w/v2.w };
|
||||
return result;
|
||||
}
|
||||
|
||||
// Normalize provided vector
|
||||
RMAPI Vector4 Vector4Normalize(Vector4 v)
|
||||
{
|
||||
Vector4 result = { 0 };
|
||||
float length = sqrtf((v.x*v.x) + (v.y*v.y) + (v.z*v.z) + (v.w*v.w));
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
float ilength = 1.0f/length;
|
||||
result.x = v.x*ilength;
|
||||
result.y = v.y*ilength;
|
||||
result.z = v.z*ilength;
|
||||
result.w = v.w*ilength;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Get min value for each pair of components
|
||||
RMAPI Vector4 Vector4Min(Vector4 v1, Vector4 v2)
|
||||
{
|
||||
Vector4 result = { 0 };
|
||||
|
||||
result.x = fminf(v1.x, v2.x);
|
||||
result.y = fminf(v1.y, v2.y);
|
||||
result.z = fminf(v1.z, v2.z);
|
||||
result.w = fminf(v1.w, v2.w);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Get max value for each pair of components
|
||||
RMAPI Vector4 Vector4Max(Vector4 v1, Vector4 v2)
|
||||
{
|
||||
Vector4 result = { 0 };
|
||||
|
||||
result.x = fmaxf(v1.x, v2.x);
|
||||
result.y = fmaxf(v1.y, v2.y);
|
||||
result.z = fmaxf(v1.z, v2.z);
|
||||
result.w = fmaxf(v1.w, v2.w);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Calculate linear interpolation between two vectors
|
||||
RMAPI Vector4 Vector4Lerp(Vector4 v1, Vector4 v2, float amount)
|
||||
{
|
||||
Vector4 result = { 0 };
|
||||
|
||||
result.x = v1.x + amount*(v2.x - v1.x);
|
||||
result.y = v1.y + amount*(v2.y - v1.y);
|
||||
result.z = v1.z + amount*(v2.z - v1.z);
|
||||
result.w = v1.w + amount*(v2.w - v1.w);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Move Vector towards target
|
||||
RMAPI Vector4 Vector4MoveTowards(Vector4 v, Vector4 target, float maxDistance)
|
||||
{
|
||||
Vector4 result = { 0 };
|
||||
|
||||
float dx = target.x - v.x;
|
||||
float dy = target.y - v.y;
|
||||
float dz = target.z - v.z;
|
||||
float dw = target.w - v.w;
|
||||
float value = (dx*dx) + (dy*dy) + (dz*dz) + (dw*dw);
|
||||
|
||||
if ((value == 0) || ((maxDistance >= 0) && (value <= maxDistance*maxDistance))) return target;
|
||||
|
||||
float dist = sqrtf(value);
|
||||
|
||||
result.x = v.x + dx/dist*maxDistance;
|
||||
result.y = v.y + dy/dist*maxDistance;
|
||||
result.z = v.z + dz/dist*maxDistance;
|
||||
result.w = v.w + dw/dist*maxDistance;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Invert the given vector
|
||||
RMAPI Vector4 Vector4Invert(Vector4 v)
|
||||
{
|
||||
Vector4 result = { 1.0f/v.x, 1.0f/v.y, 1.0f/v.z, 1.0f/v.w };
|
||||
return result;
|
||||
}
|
||||
|
||||
// Check whether two given vectors are almost equal
|
||||
RMAPI int Vector4Equals(Vector4 p, Vector4 q)
|
||||
{
|
||||
#if !defined(EPSILON)
|
||||
#define EPSILON 0.000001f
|
||||
#endif
|
||||
|
||||
int result = ((fabsf(p.x - q.x)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.x), fabsf(q.x))))) &&
|
||||
((fabsf(p.y - q.y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.y), fabsf(q.y))))) &&
|
||||
((fabsf(p.z - q.z)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.z), fabsf(q.z))))) &&
|
||||
((fabsf(p.w - q.w)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.w), fabsf(q.w)))));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition - Matrix math
|
||||
//----------------------------------------------------------------------------------
|
||||
@ -1901,6 +2213,32 @@ RMAPI Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount)
|
||||
return result;
|
||||
}
|
||||
|
||||
// Calculate quaternion cubic spline interpolation using Cubic Hermite Spline algorithm
|
||||
// as described in the GLTF 2.0 specification: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#interpolation-cubic
|
||||
RMAPI Quaternion QuaternionCubicHermiteSpline(Quaternion q1, Quaternion outTangent1, Quaternion q2, Quaternion inTangent2, float t)
|
||||
{
|
||||
float t2 = t * t;
|
||||
float t3 = t2 * t;
|
||||
float h00 = 2 * t3 - 3 * t2 + 1;
|
||||
float h10 = t3 - 2 * t2 + t;
|
||||
float h01 = -2 * t3 + 3 * t2;
|
||||
float h11 = t3 - t2;
|
||||
|
||||
Quaternion p0 = QuaternionScale(q1, h00);
|
||||
Quaternion m0 = QuaternionScale(outTangent1, h10);
|
||||
Quaternion p1 = QuaternionScale(q2, h01);
|
||||
Quaternion m1 = QuaternionScale(inTangent2, h11);
|
||||
|
||||
Quaternion result = { 0 };
|
||||
|
||||
result = QuaternionAdd(p0, m0);
|
||||
result = QuaternionAdd(result, p1);
|
||||
result = QuaternionAdd(result, m1);
|
||||
result = QuaternionNormalize(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Calculate quaternion based on the rotation from one vector to another
|
||||
RMAPI Quaternion QuaternionFromVector3ToVector3(Vector3 from, Vector3 to)
|
||||
{
|
||||
@ -1960,7 +2298,7 @@ RMAPI Quaternion QuaternionFromMatrix(Matrix mat)
|
||||
}
|
||||
|
||||
float biggestVal = sqrtf(fourBiggestSquaredMinus1 + 1.0f)*0.5f;
|
||||
float mult = 0.25f / biggestVal;
|
||||
float mult = 0.25f/biggestVal;
|
||||
|
||||
switch (biggestIndex)
|
||||
{
|
||||
@ -2042,8 +2380,7 @@ RMAPI Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle)
|
||||
float ilength = 0.0f;
|
||||
|
||||
// Vector3Normalize(axis)
|
||||
Vector3 v = axis;
|
||||
length = sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
|
||||
length = axisLength;
|
||||
if (length == 0.0f) length = 1.0f;
|
||||
ilength = 1.0f/length;
|
||||
axis.x *= ilength;
|
||||
|
112
lib/raymath.zig
112
lib/raymath.zig
@ -130,6 +130,14 @@ pub fn vector2Reflect(v: Vector2, normal: Vector2) Vector2 {
|
||||
return cdef.Vector2Reflect(v, normal);
|
||||
}
|
||||
|
||||
pub fn vector2Min(v1: Vector2, v2: Vector2) Vector2 {
|
||||
return cdef.Vector2Min(v1, v2);
|
||||
}
|
||||
|
||||
pub fn vector2Max(v1: Vector2, v2: Vector2) Vector2 {
|
||||
return cdef.Vector2Max(v1, v2);
|
||||
}
|
||||
|
||||
pub fn vector2Rotate(v: Vector2, angle: f32) Vector2 {
|
||||
return cdef.Vector2Rotate(v, angle);
|
||||
}
|
||||
@ -154,6 +162,10 @@ pub fn vector2Equals(p: Vector2, q: Vector2) i32 {
|
||||
return @as(i32, cdef.Vector2Equals(p, q));
|
||||
}
|
||||
|
||||
pub fn vector2Refract(v: Vector2, n: Vector2, r: f32) Vector2 {
|
||||
return cdef.Vector2Refract(v, n, r);
|
||||
}
|
||||
|
||||
pub fn vector3Zero() Vector3 {
|
||||
return cdef.Vector3Zero();
|
||||
}
|
||||
@ -254,10 +266,18 @@ pub fn vector3RotateByAxisAngle(v: Vector3, axis: Vector3, angle: f32) Vector3 {
|
||||
return cdef.Vector3RotateByAxisAngle(v, axis, angle);
|
||||
}
|
||||
|
||||
pub fn vector3MoveTowards(v: Vector3, target: Vector3, maxDistance: f32) Vector3 {
|
||||
return cdef.Vector3MoveTowards(v, target, maxDistance);
|
||||
}
|
||||
|
||||
pub fn vector3Lerp(v1: Vector3, v2: Vector3, amount: f32) Vector3 {
|
||||
return cdef.Vector3Lerp(v1, v2, amount);
|
||||
}
|
||||
|
||||
pub fn vector3CubicHermite(v1: Vector3, tangent1: Vector3, v2: Vector3, tangent2: Vector3, amount: f32) Vector3 {
|
||||
return cdef.Vector3CubicHermite(v1, tangent1, v2, tangent2, amount);
|
||||
}
|
||||
|
||||
pub fn vector3Reflect(v: Vector3, normal: Vector3) Vector3 {
|
||||
return cdef.Vector3Reflect(v, normal);
|
||||
}
|
||||
@ -302,6 +322,94 @@ pub fn vector3Refract(v: Vector3, n: Vector3, r: f32) Vector3 {
|
||||
return cdef.Vector3Refract(v, n, r);
|
||||
}
|
||||
|
||||
pub fn vector4Zero() Vector4 {
|
||||
return cdef.Vector4Zero();
|
||||
}
|
||||
|
||||
pub fn vector4One() Vector4 {
|
||||
return cdef.Vector4One();
|
||||
}
|
||||
|
||||
pub fn vector4Add(v1: Vector4, v2: Vector4) Vector4 {
|
||||
return cdef.Vector4Add(v1, v2);
|
||||
}
|
||||
|
||||
pub fn vector4AddValue(v: Vector4, add: f32) Vector4 {
|
||||
return cdef.Vector4AddValue(v, add);
|
||||
}
|
||||
|
||||
pub fn vector4Subtract(v1: Vector4, v2: Vector4) Vector4 {
|
||||
return cdef.Vector4Subtract(v1, v2);
|
||||
}
|
||||
|
||||
pub fn vector4SubtractValue(v: Vector4, add: f32) Vector4 {
|
||||
return cdef.Vector4SubtractValue(v, add);
|
||||
}
|
||||
|
||||
pub fn vector4Length(v: Vector4) f32 {
|
||||
return cdef.Vector4Length(v);
|
||||
}
|
||||
|
||||
pub fn vector4LengthSqr(v: Vector4) f32 {
|
||||
return cdef.Vector4LengthSqr(v);
|
||||
}
|
||||
|
||||
pub fn vector4DotProduct(v1: Vector4, v2: Vector4) f32 {
|
||||
return cdef.Vector4DotProduct(v1, v2);
|
||||
}
|
||||
|
||||
pub fn vector4Distance(v1: Vector4, v2: Vector4) f32 {
|
||||
return cdef.Vector4Distance(v1, v2);
|
||||
}
|
||||
|
||||
pub fn vector4DistanceSqr(v1: Vector4, v2: Vector4) f32 {
|
||||
return cdef.Vector4DistanceSqr(v1, v2);
|
||||
}
|
||||
|
||||
pub fn vector4Scale(v: Vector4, scale: f32) Vector4 {
|
||||
return cdef.Vector4Scale(v, scale);
|
||||
}
|
||||
|
||||
pub fn vector4Multiply(v1: Vector4, v2: Vector4) Vector4 {
|
||||
return cdef.Vector4Multiply(v1, v2);
|
||||
}
|
||||
|
||||
pub fn vector4Negate(v: Vector4) Vector4 {
|
||||
return cdef.Vector4Negate(v);
|
||||
}
|
||||
|
||||
pub fn vector4Divide(v1: Vector4, v2: Vector4) Vector4 {
|
||||
return cdef.Vector4Divide(v1, v2);
|
||||
}
|
||||
|
||||
pub fn vector4Normalize(v: Vector4) Vector4 {
|
||||
return cdef.Vector4Normalize(v);
|
||||
}
|
||||
|
||||
pub fn vector4Min(v1: Vector4, v2: Vector4) Vector4 {
|
||||
return cdef.Vector4Min(v1, v2);
|
||||
}
|
||||
|
||||
pub fn vector4Max(v1: Vector4, v2: Vector4) Vector4 {
|
||||
return cdef.Vector4Max(v1, v2);
|
||||
}
|
||||
|
||||
pub fn vector4Lerp(v1: Vector4, v2: Vector4, amount: f32) Vector4 {
|
||||
return cdef.Vector4Lerp(v1, v2, amount);
|
||||
}
|
||||
|
||||
pub fn vector4MoveTowards(v: Vector4, target: Vector4, maxDistance: f32) Vector4 {
|
||||
return cdef.Vector4MoveTowards(v, target, maxDistance);
|
||||
}
|
||||
|
||||
pub fn vector4Invert(v: Vector4) Vector4 {
|
||||
return cdef.Vector4Invert(v);
|
||||
}
|
||||
|
||||
pub fn vector4Equals(p: Vector4, q: Vector4) i32 {
|
||||
return @as(i32, cdef.Vector4Equals(p, q));
|
||||
}
|
||||
|
||||
pub fn matrixDeterminant(mat: Matrix) f32 {
|
||||
return cdef.MatrixDeterminant(mat);
|
||||
}
|
||||
@ -442,6 +550,10 @@ pub fn quaternionSlerp(q1: Quaternion, q2: Quaternion, amount: f32) Quaternion {
|
||||
return cdef.QuaternionSlerp(q1, q2, amount);
|
||||
}
|
||||
|
||||
pub fn quaternionCubicHermiteSpline(q1: Quaternion, outTangent1: Quaternion, q2: Quaternion, inTangent2: Quaternion, t: f32) Quaternion {
|
||||
return cdef.QuaternionCubicHermiteSpline(q1, outTangent1, q2, inTangent2, t);
|
||||
}
|
||||
|
||||
pub fn quaternionFromVector3ToVector3(from: Vector3, to: Vector3) Quaternion {
|
||||
return cdef.QuaternionFromVector3ToVector3(from, to);
|
||||
}
|
||||
|
@ -14,6 +14,9 @@ pub extern "c" fn rlMultMatrixf(matf: [*c]const f32) void;
|
||||
pub extern "c" fn rlFrustum(left: f64, right: f64, bottom: f64, top: f64, znear: f64, zfar: f64) void;
|
||||
pub extern "c" fn rlOrtho(left: f64, right: f64, bottom: f64, top: f64, znear: f64, zfar: f64) void;
|
||||
pub extern "c" fn rlViewport(x: c_int, y: c_int, width: c_int, height: c_int) void;
|
||||
pub extern "c" fn rlSetClipPlanes(near: f64, far: f64) void;
|
||||
pub extern "c" fn rlGetCullDistanceNear() f64;
|
||||
pub extern "c" fn rlGetCullDistanceFar() f64;
|
||||
pub extern "c" fn rlBegin(mode: c_int) void;
|
||||
pub extern "c" fn rlEnd() void;
|
||||
pub extern "c" fn rlVertex2i(x: c_int, y: c_int) void;
|
||||
@ -45,8 +48,10 @@ pub extern "c" fn rlEnableShader(id: c_uint) void;
|
||||
pub extern "c" fn rlDisableShader() void;
|
||||
pub extern "c" fn rlEnableFramebuffer(id: c_uint) void;
|
||||
pub extern "c" fn rlDisableFramebuffer() void;
|
||||
pub extern "c" fn rlGetActiveFramebuffer() c_uint;
|
||||
pub extern "c" fn rlActiveDrawBuffers(count: c_int) void;
|
||||
pub extern "c" fn rlBlitFramebuffer(srcX: c_int, srcY: c_int, srcWidth: c_int, srcHeight: c_int, dstX: c_int, dstY: c_int, dstWidth: c_int, dstHeight: c_int, bufferMask: c_int) void;
|
||||
pub extern "c" fn rlBindFramebuffer(target: c_uint, framebuffer: c_uint) void;
|
||||
pub extern "c" fn rlEnableColorBlend() void;
|
||||
pub extern "c" fn rlDisableColorBlend() void;
|
||||
pub extern "c" fn rlEnableDepthTest() void;
|
||||
@ -55,6 +60,7 @@ pub extern "c" fn rlEnableDepthMask() void;
|
||||
pub extern "c" fn rlDisableDepthMask() void;
|
||||
pub extern "c" fn rlEnableBackfaceCulling() void;
|
||||
pub extern "c" fn rlDisableBackfaceCulling() void;
|
||||
pub extern "c" fn rlColorMask(r: bool, g: bool, b: bool, a: bool) void;
|
||||
pub extern "c" fn rlSetCullFace(mode: c_int) void;
|
||||
pub extern "c" fn rlEnableScissorTest() void;
|
||||
pub extern "c" fn rlDisableScissorTest() void;
|
||||
@ -100,7 +106,7 @@ pub extern "c" fn rlUpdateVertexBuffer(bufferId: c_uint, data: *const anyopaque,
|
||||
pub extern "c" fn rlUpdateVertexBufferElements(id: c_uint, data: *const anyopaque, dataSize: c_int, offset: c_int) void;
|
||||
pub extern "c" fn rlUnloadVertexArray(vaoId: c_uint) void;
|
||||
pub extern "c" fn rlUnloadVertexBuffer(vboId: c_uint) void;
|
||||
pub extern "c" fn rlSetVertexAttribute(index: c_uint, compSize: c_int, ty: c_int, normalized: bool, stride: c_int, pointer: *const anyopaque) void;
|
||||
pub extern "c" fn rlSetVertexAttribute(index: c_uint, compSize: c_int, ty: c_int, normalized: bool, stride: c_int, offset: c_int) void;
|
||||
pub extern "c" fn rlSetVertexAttributeDivisor(index: c_uint, divisor: c_int) void;
|
||||
pub extern "c" fn rlSetVertexAttributeDefault(locIndex: c_int, value: *const anyopaque, attribType: c_int, count: c_int) void;
|
||||
pub extern "c" fn rlDrawVertexArray(offset: c_int, count: c_int) void;
|
||||
@ -117,7 +123,7 @@ pub extern "c" fn rlUnloadTexture(id: c_uint) void;
|
||||
pub extern "c" fn rlGenTextureMipmaps(id: c_uint, width: c_int, height: c_int, format: c_int, mipmaps: [*c]c_int) void;
|
||||
pub extern "c" fn rlReadTexturePixels(id: c_uint, width: c_int, height: c_int, format: c_int) *anyopaque;
|
||||
pub extern "c" fn rlReadScreenPixels(width: c_int, height: c_int) [*c]u8;
|
||||
pub extern "c" fn rlLoadFramebuffer(width: c_int, height: c_int) c_uint;
|
||||
pub extern "c" fn rlLoadFramebuffer() c_uint;
|
||||
pub extern "c" fn rlFramebufferAttach(fboId: c_uint, texId: c_uint, attachType: c_int, texType: c_int, mipLevel: c_int) void;
|
||||
pub extern "c" fn rlFramebufferComplete(id: c_uint) bool;
|
||||
pub extern "c" fn rlUnloadFramebuffer(id: c_uint) void;
|
||||
|
514
lib/rlgl.h
514
lib/rlgl.h
@ -1,6 +1,6 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* rlgl v4.5 - A multi-OpenGL abstraction layer with an immediate-mode style API
|
||||
* rlgl v5.0 - A multi-OpenGL abstraction layer with an immediate-mode style API
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* An abstraction layer for multiple OpenGL versions (1.1, 2.1, 3.3 Core, 4.3 Core, ES 2.0)
|
||||
@ -62,17 +62,17 @@
|
||||
* When loading a shader, the following vertex attributes and uniform
|
||||
* location names are tried to be set automatically:
|
||||
*
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Bound by default to shader location: 0
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Bound by default to shader location: 1
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Bound by default to shader location: 2
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Bound by default to shader location: 3
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Bound by default to shader location: 4
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Bound by default to shader location: 5
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2
|
||||
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix
|
||||
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW "matView" // view matrix
|
||||
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION "matProjection" // projection matrix
|
||||
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL "matModel" // model matrix
|
||||
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL "matNormal" // normal matrix (transpose(inverse(matModelView))
|
||||
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL "matNormal" // normal matrix (transpose(inverse(matModelView)))
|
||||
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR "colDiffuse" // color diffuse (base tint color, multiplied by texture color)
|
||||
* #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0 "texture0" // texture0 (texture slot active 0)
|
||||
* #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1 "texture1" // texture1 (texture slot active 1)
|
||||
@ -85,7 +85,7 @@
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2014-2023 Ramon Santamaria (@raysan5)
|
||||
* Copyright (c) 2014-2024 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||
* will the authors be held liable for any damages arising from the use of this software.
|
||||
@ -107,16 +107,17 @@
|
||||
#ifndef RLGL_H
|
||||
#define RLGL_H
|
||||
|
||||
#define RLGL_VERSION "4.5"
|
||||
#define RLGL_VERSION "5.0"
|
||||
|
||||
// Function specifiers in case library is build/used as a shared library (Windows)
|
||||
// Function specifiers in case library is build/used as a shared library
|
||||
// NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll
|
||||
#if defined(_WIN32)
|
||||
#if defined(BUILD_LIBTYPE_SHARED)
|
||||
#define RLAPI __declspec(dllexport) // We are building the library as a Win32 shared library (.dll)
|
||||
#elif defined(USE_LIBTYPE_SHARED)
|
||||
#define RLAPI __declspec(dllimport) // We are using the library as a Win32 shared library (.dll)
|
||||
#endif
|
||||
// NOTE: visibility(default) attribute makes symbols "visible" when compiled with -fvisibility=hidden
|
||||
#if defined(_WIN32) && defined(BUILD_LIBTYPE_SHARED)
|
||||
#define RLAPI __declspec(dllexport) // We are building the library as a Win32 shared library (.dll)
|
||||
#elif defined(BUILD_LIBTYPE_SHARED)
|
||||
#define RLAPI __attribute__((visibility("default"))) // We are building the library as a Unix shared library (.so/.dylib)
|
||||
#elif defined(_WIN32) && defined(USE_LIBTYPE_SHARED)
|
||||
#define RLAPI __declspec(dllimport) // We are using the library as a Win32 shared library (.dll)
|
||||
#endif
|
||||
|
||||
// Function specifiers definition
|
||||
@ -318,6 +319,8 @@
|
||||
#define RL_BLEND_SRC_ALPHA 0x80CB // GL_BLEND_SRC_ALPHA
|
||||
#define RL_BLEND_COLOR 0x8005 // GL_BLEND_COLOR
|
||||
|
||||
#define RL_READ_FRAMEBUFFER 0x8CA8 // GL_READ_FRAMEBUFFER
|
||||
#define RL_DRAW_FRAMEBUFFER 0x8CA9 // GL_DRAW_FRAMEBUFFER
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
@ -346,6 +349,7 @@ typedef struct rlVertexBuffer {
|
||||
|
||||
float *vertices; // Vertex position (XYZ - 3 components per vertex) (shader-location = 0)
|
||||
float *texcoords; // Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
|
||||
float *normals; // Vertex normal (XYZ - 3 components per vertex) (shader-location = 2)
|
||||
unsigned char *colors; // Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
|
||||
#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
|
||||
unsigned int *indices; // Vertex indices (in case vertex data comes indexed) (6 indices per quad)
|
||||
@ -354,7 +358,7 @@ typedef struct rlVertexBuffer {
|
||||
unsigned short *indices; // Vertex indices (in case vertex data comes indexed) (6 indices per quad)
|
||||
#endif
|
||||
unsigned int vaoId; // OpenGL Vertex Array Object id
|
||||
unsigned int vboId[4]; // OpenGL Vertex Buffer Objects id (4 types of vertex data)
|
||||
unsigned int vboId[5]; // OpenGL Vertex Buffer Objects id (5 types of vertex data)
|
||||
} rlVertexBuffer;
|
||||
|
||||
// Draw call type
|
||||
@ -555,30 +559,33 @@ typedef enum {
|
||||
extern "C" { // Prevents name mangling of functions
|
||||
#endif
|
||||
|
||||
RLAPI void rlMatrixMode(int mode); // Choose the current matrix to be transformed
|
||||
RLAPI void rlPushMatrix(void); // Push the current matrix to stack
|
||||
RLAPI void rlPopMatrix(void); // Pop latest inserted matrix from stack
|
||||
RLAPI void rlLoadIdentity(void); // Reset current matrix to identity matrix
|
||||
RLAPI void rlTranslatef(float x, float y, float z); // Multiply the current matrix by a translation matrix
|
||||
RLAPI void rlRotatef(float angle, float x, float y, float z); // Multiply the current matrix by a rotation matrix
|
||||
RLAPI void rlScalef(float x, float y, float z); // Multiply the current matrix by a scaling matrix
|
||||
RLAPI void rlMultMatrixf(const float *matf); // Multiply the current matrix by another matrix
|
||||
RLAPI void rlMatrixMode(int mode); // Choose the current matrix to be transformed
|
||||
RLAPI void rlPushMatrix(void); // Push the current matrix to stack
|
||||
RLAPI void rlPopMatrix(void); // Pop latest inserted matrix from stack
|
||||
RLAPI void rlLoadIdentity(void); // Reset current matrix to identity matrix
|
||||
RLAPI void rlTranslatef(float x, float y, float z); // Multiply the current matrix by a translation matrix
|
||||
RLAPI void rlRotatef(float angle, float x, float y, float z); // Multiply the current matrix by a rotation matrix
|
||||
RLAPI void rlScalef(float x, float y, float z); // Multiply the current matrix by a scaling matrix
|
||||
RLAPI void rlMultMatrixf(const float *matf); // Multiply the current matrix by another matrix
|
||||
RLAPI void rlFrustum(double left, double right, double bottom, double top, double znear, double zfar);
|
||||
RLAPI void rlOrtho(double left, double right, double bottom, double top, double znear, double zfar);
|
||||
RLAPI void rlViewport(int x, int y, int width, int height); // Set the viewport area
|
||||
RLAPI void rlSetClipPlanes(double near, double far); // Set clip planes distances
|
||||
RLAPI double rlGetCullDistanceNear(); // Get cull plane distance near
|
||||
RLAPI double rlGetCullDistanceFar(); // Get cull plane distance far
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Functions Declaration - Vertex level operations
|
||||
//------------------------------------------------------------------------------------
|
||||
RLAPI void rlBegin(int mode); // Initialize drawing mode (how to organize vertex)
|
||||
RLAPI void rlEnd(void); // Finish vertex providing
|
||||
RLAPI void rlVertex2i(int x, int y); // Define one vertex (position) - 2 int
|
||||
RLAPI void rlVertex2f(float x, float y); // Define one vertex (position) - 2 float
|
||||
RLAPI void rlVertex3f(float x, float y, float z); // Define one vertex (position) - 3 float
|
||||
RLAPI void rlTexCoord2f(float x, float y); // Define one vertex (texture coordinate) - 2 float
|
||||
RLAPI void rlNormal3f(float x, float y, float z); // Define one vertex (normal) - 3 float
|
||||
RLAPI void rlColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a); // Define one vertex (color) - 4 byte
|
||||
RLAPI void rlColor3f(float x, float y, float z); // Define one vertex (color) - 3 float
|
||||
RLAPI void rlBegin(int mode); // Initialize drawing mode (how to organize vertex)
|
||||
RLAPI void rlEnd(void); // Finish vertex providing
|
||||
RLAPI void rlVertex2i(int x, int y); // Define one vertex (position) - 2 int
|
||||
RLAPI void rlVertex2f(float x, float y); // Define one vertex (position) - 2 float
|
||||
RLAPI void rlVertex3f(float x, float y, float z); // Define one vertex (position) - 3 float
|
||||
RLAPI void rlTexCoord2f(float x, float y); // Define one vertex (texture coordinate) - 2 float
|
||||
RLAPI void rlNormal3f(float x, float y, float z); // Define one vertex (normal) - 3 float
|
||||
RLAPI void rlColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a); // Define one vertex (color) - 4 byte
|
||||
RLAPI void rlColor3f(float x, float y, float z); // Define one vertex (color) - 3 float
|
||||
RLAPI void rlColor4f(float x, float y, float z, float w); // Define one vertex (color) - 4 float
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
@ -592,13 +599,13 @@ RLAPI bool rlEnableVertexArray(unsigned int vaoId); // Enable vertex array (
|
||||
RLAPI void rlDisableVertexArray(void); // Disable vertex array (VAO, if supported)
|
||||
RLAPI void rlEnableVertexBuffer(unsigned int id); // Enable vertex buffer (VBO)
|
||||
RLAPI void rlDisableVertexBuffer(void); // Disable vertex buffer (VBO)
|
||||
RLAPI void rlEnableVertexBufferElement(unsigned int id);// Enable vertex buffer element (VBO element)
|
||||
RLAPI void rlEnableVertexBufferElement(unsigned int id); // Enable vertex buffer element (VBO element)
|
||||
RLAPI void rlDisableVertexBufferElement(void); // Disable vertex buffer element (VBO element)
|
||||
RLAPI void rlEnableVertexAttribute(unsigned int index); // Enable vertex attribute index
|
||||
RLAPI void rlDisableVertexAttribute(unsigned int index);// Disable vertex attribute index
|
||||
RLAPI void rlDisableVertexAttribute(unsigned int index); // Disable vertex attribute index
|
||||
#if defined(GRAPHICS_API_OPENGL_11)
|
||||
RLAPI void rlEnableStatePointer(int vertexAttribType, void *buffer); // Enable attribute state pointer
|
||||
RLAPI void rlDisableStatePointer(int vertexAttribType); // Disable attribute state pointer
|
||||
RLAPI void rlEnableStatePointer(int vertexAttribType, void *buffer); // Enable attribute state pointer
|
||||
RLAPI void rlDisableStatePointer(int vertexAttribType); // Disable attribute state pointer
|
||||
#endif
|
||||
|
||||
// Textures state
|
||||
@ -617,11 +624,13 @@ RLAPI void rlDisableShader(void); // Disable shader progra
|
||||
// Framebuffer state
|
||||
RLAPI void rlEnableFramebuffer(unsigned int id); // Enable render texture (fbo)
|
||||
RLAPI void rlDisableFramebuffer(void); // Disable render texture (fbo), return to default framebuffer
|
||||
RLAPI unsigned int rlGetActiveFramebuffer(void); // Get the currently active render texture (fbo), 0 for default framebuffer
|
||||
RLAPI void rlActiveDrawBuffers(int count); // Activate multiple draw color buffers
|
||||
RLAPI void rlBlitFramebuffer(int srcX, int srcY, int srcWidth, int srcHeight, int dstX, int dstY, int dstWidth, int dstHeight, int bufferMask); // Blit active framebuffer to main framebuffer
|
||||
RLAPI void rlBindFramebuffer(unsigned int target, unsigned int framebuffer); // Bind framebuffer (FBO)
|
||||
|
||||
// General render state
|
||||
RLAPI void rlEnableColorBlend(void); // Enable color blending
|
||||
RLAPI void rlEnableColorBlend(void); // Enable color blending
|
||||
RLAPI void rlDisableColorBlend(void); // Disable color blending
|
||||
RLAPI void rlEnableDepthTest(void); // Enable depth test
|
||||
RLAPI void rlDisableDepthTest(void); // Disable depth test
|
||||
@ -629,12 +638,13 @@ RLAPI void rlEnableDepthMask(void); // Enable depth write
|
||||
RLAPI void rlDisableDepthMask(void); // Disable depth write
|
||||
RLAPI void rlEnableBackfaceCulling(void); // Enable backface culling
|
||||
RLAPI void rlDisableBackfaceCulling(void); // Disable backface culling
|
||||
RLAPI void rlColorMask(bool r, bool g, bool b, bool a); // Color mask control
|
||||
RLAPI void rlSetCullFace(int mode); // Set face culling mode
|
||||
RLAPI void rlEnableScissorTest(void); // Enable scissor test
|
||||
RLAPI void rlDisableScissorTest(void); // Disable scissor test
|
||||
RLAPI void rlScissor(int x, int y, int width, int height); // Scissor test
|
||||
RLAPI void rlEnableWireMode(void); // Enable wire mode
|
||||
RLAPI void rlEnablePointMode(void); // Enable point mode
|
||||
RLAPI void rlEnablePointMode(void); // Enable point mode
|
||||
RLAPI void rlDisableWireMode(void); // Disable wire mode ( and point ) maybe rename
|
||||
RLAPI void rlSetLineWidth(float width); // Set the line drawing width
|
||||
RLAPI float rlGetLineWidth(void); // Get the line drawing width
|
||||
@ -671,48 +681,48 @@ RLAPI int *rlGetShaderLocsDefault(void); // Get default shader lo
|
||||
// Render batch management
|
||||
// NOTE: rlgl provides a default render batch to behave like OpenGL 1.1 immediate mode
|
||||
// but this render batch API is exposed in case of custom batches are required
|
||||
RLAPI rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements); // Load a render batch system
|
||||
RLAPI void rlUnloadRenderBatch(rlRenderBatch batch); // Unload render batch system
|
||||
RLAPI void rlDrawRenderBatch(rlRenderBatch *batch); // Draw render batch data (Update->Draw->Reset)
|
||||
RLAPI void rlSetRenderBatchActive(rlRenderBatch *batch); // Set the active render batch for rlgl (NULL for default internal)
|
||||
RLAPI void rlDrawRenderBatchActive(void); // Update and draw internal render batch
|
||||
RLAPI bool rlCheckRenderBatchLimit(int vCount); // Check internal buffer overflow for a given number of vertex
|
||||
RLAPI rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements); // Load a render batch system
|
||||
RLAPI void rlUnloadRenderBatch(rlRenderBatch batch); // Unload render batch system
|
||||
RLAPI void rlDrawRenderBatch(rlRenderBatch *batch); // Draw render batch data (Update->Draw->Reset)
|
||||
RLAPI void rlSetRenderBatchActive(rlRenderBatch *batch); // Set the active render batch for rlgl (NULL for default internal)
|
||||
RLAPI void rlDrawRenderBatchActive(void); // Update and draw internal render batch
|
||||
RLAPI bool rlCheckRenderBatchLimit(int vCount); // Check internal buffer overflow for a given number of vertex
|
||||
|
||||
RLAPI void rlSetTexture(unsigned int id); // Set current texture for render batch and check buffers limits
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// Vertex buffers management
|
||||
RLAPI unsigned int rlLoadVertexArray(void); // Load vertex array (vao) if supported
|
||||
RLAPI unsigned int rlLoadVertexBuffer(const void *buffer, int size, bool dynamic); // Load a vertex buffer attribute
|
||||
RLAPI unsigned int rlLoadVertexBufferElement(const void *buffer, int size, bool dynamic); // Load a new attributes element buffer
|
||||
RLAPI void rlUpdateVertexBuffer(unsigned int bufferId, const void *data, int dataSize, int offset); // Update GPU buffer with new data
|
||||
RLAPI void rlUpdateVertexBufferElements(unsigned int id, const void *data, int dataSize, int offset); // Update vertex buffer elements with new data
|
||||
RLAPI void rlUnloadVertexArray(unsigned int vaoId);
|
||||
RLAPI void rlUnloadVertexBuffer(unsigned int vboId);
|
||||
RLAPI void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, const void *pointer);
|
||||
RLAPI void rlSetVertexAttributeDivisor(unsigned int index, int divisor);
|
||||
RLAPI void rlSetVertexAttributeDefault(int locIndex, const void *value, int attribType, int count); // Set vertex attribute default value
|
||||
RLAPI void rlDrawVertexArray(int offset, int count);
|
||||
RLAPI void rlDrawVertexArrayElements(int offset, int count, const void *buffer);
|
||||
RLAPI void rlDrawVertexArrayInstanced(int offset, int count, int instances);
|
||||
RLAPI void rlDrawVertexArrayElementsInstanced(int offset, int count, const void *buffer, int instances);
|
||||
RLAPI unsigned int rlLoadVertexArray(void); // Load vertex array (vao) if supported
|
||||
RLAPI unsigned int rlLoadVertexBuffer(const void *buffer, int size, bool dynamic); // Load a vertex buffer object
|
||||
RLAPI unsigned int rlLoadVertexBufferElement(const void *buffer, int size, bool dynamic); // Load vertex buffer elements object
|
||||
RLAPI void rlUpdateVertexBuffer(unsigned int bufferId, const void *data, int dataSize, int offset); // Update vertex buffer object data on GPU buffer
|
||||
RLAPI void rlUpdateVertexBufferElements(unsigned int id, const void *data, int dataSize, int offset); // Update vertex buffer elements data on GPU buffer
|
||||
RLAPI void rlUnloadVertexArray(unsigned int vaoId); // Unload vertex array (vao)
|
||||
RLAPI void rlUnloadVertexBuffer(unsigned int vboId); // Unload vertex buffer object
|
||||
RLAPI void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, int offset); // Set vertex attribute data configuration
|
||||
RLAPI void rlSetVertexAttributeDivisor(unsigned int index, int divisor); // Set vertex attribute data divisor
|
||||
RLAPI void rlSetVertexAttributeDefault(int locIndex, const void *value, int attribType, int count); // Set vertex attribute default value, when attribute to provided
|
||||
RLAPI void rlDrawVertexArray(int offset, int count); // Draw vertex array (currently active vao)
|
||||
RLAPI void rlDrawVertexArrayElements(int offset, int count, const void *buffer); // Draw vertex array elements
|
||||
RLAPI void rlDrawVertexArrayInstanced(int offset, int count, int instances); // Draw vertex array (currently active vao) with instancing
|
||||
RLAPI void rlDrawVertexArrayElementsInstanced(int offset, int count, const void *buffer, int instances); // Draw vertex array elements with instancing
|
||||
|
||||
// Textures management
|
||||
RLAPI unsigned int rlLoadTexture(const void *data, int width, int height, int format, int mipmapCount); // Load texture in GPU
|
||||
RLAPI unsigned int rlLoadTextureDepth(int width, int height, bool useRenderBuffer); // Load depth texture/renderbuffer (to be attached to fbo)
|
||||
RLAPI unsigned int rlLoadTextureCubemap(const void *data, int size, int format); // Load texture cubemap
|
||||
RLAPI void rlUpdateTexture(unsigned int id, int offsetX, int offsetY, int width, int height, int format, const void *data); // Update GPU texture with new data
|
||||
RLAPI void rlGetGlTextureFormats(int format, unsigned int *glInternalFormat, unsigned int *glFormat, unsigned int *glType); // Get OpenGL internal formats
|
||||
RLAPI unsigned int rlLoadTexture(const void *data, int width, int height, int format, int mipmapCount); // Load texture data
|
||||
RLAPI unsigned int rlLoadTextureDepth(int width, int height, bool useRenderBuffer); // Load depth texture/renderbuffer (to be attached to fbo)
|
||||
RLAPI unsigned int rlLoadTextureCubemap(const void *data, int size, int format); // Load texture cubemap data
|
||||
RLAPI void rlUpdateTexture(unsigned int id, int offsetX, int offsetY, int width, int height, int format, const void *data); // Update texture with new data on GPU
|
||||
RLAPI void rlGetGlTextureFormats(int format, unsigned int *glInternalFormat, unsigned int *glFormat, unsigned int *glType); // Get OpenGL internal formats
|
||||
RLAPI const char *rlGetPixelFormatName(unsigned int format); // Get name string for pixel format
|
||||
RLAPI void rlUnloadTexture(unsigned int id); // Unload texture from GPU memory
|
||||
RLAPI void rlGenTextureMipmaps(unsigned int id, int width, int height, int format, int *mipmaps); // Generate mipmap data for selected texture
|
||||
RLAPI void *rlReadTexturePixels(unsigned int id, int width, int height, int format); // Read texture pixel data
|
||||
RLAPI void *rlReadTexturePixels(unsigned int id, int width, int height, int format); // Read texture pixel data
|
||||
RLAPI unsigned char *rlReadScreenPixels(int width, int height); // Read screen pixel data (color buffer)
|
||||
|
||||
// Framebuffer management (fbo)
|
||||
RLAPI unsigned int rlLoadFramebuffer(int width, int height); // Load an empty framebuffer
|
||||
RLAPI void rlFramebufferAttach(unsigned int fboId, unsigned int texId, int attachType, int texType, int mipLevel); // Attach texture/renderbuffer to a framebuffer
|
||||
RLAPI unsigned int rlLoadFramebuffer(void); // Load an empty framebuffer
|
||||
RLAPI void rlFramebufferAttach(unsigned int fboId, unsigned int texId, int attachType, int texType, int mipLevel); // Attach texture/renderbuffer to a framebuffer
|
||||
RLAPI bool rlFramebufferComplete(unsigned int id); // Verify framebuffer is complete
|
||||
RLAPI void rlUnloadFramebuffer(unsigned int id); // Delete framebuffer from GPU
|
||||
|
||||
@ -723,14 +733,14 @@ RLAPI unsigned int rlLoadShaderProgram(unsigned int vShaderId, unsigned int fSha
|
||||
RLAPI void rlUnloadShaderProgram(unsigned int id); // Unload shader program
|
||||
RLAPI int rlGetLocationUniform(unsigned int shaderId, const char *uniformName); // Get shader location uniform
|
||||
RLAPI int rlGetLocationAttrib(unsigned int shaderId, const char *attribName); // Get shader location attribute
|
||||
RLAPI void rlSetUniform(int locIndex, const void *value, int uniformType, int count); // Set shader value uniform
|
||||
RLAPI void rlSetUniform(int locIndex, const void *value, int uniformType, int count); // Set shader value uniform
|
||||
RLAPI void rlSetUniformMatrix(int locIndex, Matrix mat); // Set shader value matrix
|
||||
RLAPI void rlSetUniformSampler(int locIndex, unsigned int textureId); // Set shader value sampler
|
||||
RLAPI void rlSetShader(unsigned int id, int *locs); // Set shader currently active (id and locations)
|
||||
|
||||
// Compute shader management
|
||||
RLAPI unsigned int rlLoadComputeShaderProgram(unsigned int shaderId); // Load compute shader program
|
||||
RLAPI void rlComputeShaderDispatch(unsigned int groupX, unsigned int groupY, unsigned int groupZ); // Dispatch compute shader (equivalent to *draw* for graphics pipeline)
|
||||
RLAPI void rlComputeShaderDispatch(unsigned int groupX, unsigned int groupY, unsigned int groupZ); // Dispatch compute shader (equivalent to *draw* for graphics pipeline)
|
||||
|
||||
// Shader buffer storage object management (ssbo)
|
||||
RLAPI unsigned int rlLoadShaderBuffer(unsigned int size, const void *data, int usageHint); // Load shader storage buffer object (SSBO)
|
||||
@ -773,6 +783,12 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
|
||||
|
||||
#if defined(RLGL_IMPLEMENTATION)
|
||||
|
||||
// Expose OpenGL functions from glad in raylib
|
||||
#if defined(BUILD_LIBTYPE_SHARED)
|
||||
#define GLAD_API_CALL_EXPORT
|
||||
#define GLAD_API_CALL_EXPORT_BUILD
|
||||
#endif
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_11)
|
||||
#if defined(__APPLE__)
|
||||
#include <OpenGL/gl.h> // OpenGL 1.1 library for OSX
|
||||
@ -891,6 +907,14 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
|
||||
#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
|
||||
#endif
|
||||
|
||||
#ifndef GL_PROGRAM_POINT_SIZE
|
||||
#define GL_PROGRAM_POINT_SIZE 0x8642
|
||||
#endif
|
||||
|
||||
#ifndef GL_LINE_WIDTH
|
||||
#define GL_LINE_WIDTH 0x0B21
|
||||
#endif
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_11)
|
||||
#define GL_UNSIGNED_SHORT_5_6_5 0x8363
|
||||
#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
|
||||
@ -910,24 +934,44 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Default shader vertex attribute locations
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION 0
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD 1
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL 2
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR 3
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT 4
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2 5
|
||||
#endif
|
||||
|
||||
// Default shader vertex attribute names to set location points
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Bound by default to shader location: 0
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Bound by default to shader location: 1
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Bound by default to shader location: 2
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Bound by default to shader location: 3
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Bound by default to shader location: 4
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Bound by default to shader location: 5
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2
|
||||
#endif
|
||||
|
||||
#ifndef RL_DEFAULT_SHADER_UNIFORM_NAME_MVP
|
||||
@ -1042,6 +1086,9 @@ typedef void *(*rlglLoadProc)(const char *name); // OpenGL extension functions
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
static double rlCullDistanceNear = RL_CULL_DISTANCE_NEAR;
|
||||
static double rlCullDistanceFar = RL_CULL_DISTANCE_FAR;
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
static rlglData RLGL = { 0 };
|
||||
#endif // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
|
||||
@ -1072,8 +1119,15 @@ static const char *rlGetCompressedFormatName(int format); // Get compressed form
|
||||
static int rlGetPixelDataSize(int width, int height, int format); // Get pixel data size in bytes (image or texture)
|
||||
|
||||
// Auxiliar matrix math functions
|
||||
typedef struct rl_float16 {
|
||||
float v[16];
|
||||
} rl_float16;
|
||||
static rl_float16 rlMatrixToFloatV(Matrix mat); // Get float array of matrix data
|
||||
#define rlMatrixToFloat(mat) (rlMatrixToFloatV(mat).v) // Get float vector for Matrix
|
||||
static Matrix rlMatrixIdentity(void); // Get identity matrix
|
||||
static Matrix rlMatrixMultiply(Matrix left, Matrix right); // Multiply two matrices
|
||||
static Matrix rlMatrixTranspose(Matrix mat); // Transposes provided matrix
|
||||
static Matrix rlMatrixInvert(Matrix mat); // Invert provided matrix
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition - Matrix operations
|
||||
@ -1316,6 +1370,25 @@ void rlViewport(int x, int y, int width, int height)
|
||||
glViewport(x, y, width, height);
|
||||
}
|
||||
|
||||
// Set clip planes distances
|
||||
void rlSetClipPlanes(double near, double far)
|
||||
{
|
||||
rlCullDistanceNear = near;
|
||||
rlCullDistanceFar = far;
|
||||
}
|
||||
|
||||
// Get cull plane distance near
|
||||
double rlGetCullDistanceNear(void)
|
||||
{
|
||||
return rlCullDistanceNear;
|
||||
}
|
||||
|
||||
// Get cull plane distance far
|
||||
double rlGetCullDistanceFar(void)
|
||||
{
|
||||
return rlCullDistanceFar;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition - Vertex level operations
|
||||
//----------------------------------------------------------------------------------
|
||||
@ -1436,7 +1509,10 @@ void rlVertex3f(float x, float y, float z)
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].texcoords[2*RLGL.State.vertexCounter] = RLGL.State.texcoordx;
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].texcoords[2*RLGL.State.vertexCounter + 1] = RLGL.State.texcoordy;
|
||||
|
||||
// WARNING: By default rlVertexBuffer struct does not store normals
|
||||
// Add current normal
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].normals[3*RLGL.State.vertexCounter] = RLGL.State.normalx;
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].normals[3*RLGL.State.vertexCounter + 1] = RLGL.State.normaly;
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].normals[3*RLGL.State.vertexCounter + 2] = RLGL.State.normalz;
|
||||
|
||||
// Add current color
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].colors[4*RLGL.State.vertexCounter] = RLGL.State.colorr;
|
||||
@ -1472,9 +1548,26 @@ void rlTexCoord2f(float x, float y)
|
||||
// NOTE: Normals limited to TRIANGLES only?
|
||||
void rlNormal3f(float x, float y, float z)
|
||||
{
|
||||
RLGL.State.normalx = x;
|
||||
RLGL.State.normaly = y;
|
||||
RLGL.State.normalz = z;
|
||||
float normalx = x;
|
||||
float normaly = y;
|
||||
float normalz = z;
|
||||
if (RLGL.State.transformRequired)
|
||||
{
|
||||
normalx = RLGL.State.transform.m0*x + RLGL.State.transform.m4*y + RLGL.State.transform.m8*z;
|
||||
normaly = RLGL.State.transform.m1*x + RLGL.State.transform.m5*y + RLGL.State.transform.m9*z;
|
||||
normalz = RLGL.State.transform.m2*x + RLGL.State.transform.m6*y + RLGL.State.transform.m10*z;
|
||||
}
|
||||
float length = sqrtf(normalx*normalx + normaly*normaly + normalz*normalz);
|
||||
if (length != 0.0f)
|
||||
{
|
||||
float ilength = 1.0f / length;
|
||||
normalx *= ilength;
|
||||
normaly *= ilength;
|
||||
normalz *= ilength;
|
||||
}
|
||||
RLGL.State.normalx = normalx;
|
||||
RLGL.State.normaly = normaly;
|
||||
RLGL.State.normalz = normalz;
|
||||
}
|
||||
|
||||
// Define one vertex (color)
|
||||
@ -1713,6 +1806,16 @@ void rlEnableFramebuffer(unsigned int id)
|
||||
#endif
|
||||
}
|
||||
|
||||
// return the active render texture (fbo)
|
||||
unsigned int rlGetActiveFramebuffer(void)
|
||||
{
|
||||
GLint fboId = 0;
|
||||
#if (defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES3)) && defined(RLGL_RENDER_TEXTURES_HINT)
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &fboId);
|
||||
#endif
|
||||
return fboId;
|
||||
}
|
||||
|
||||
// Disable rendering to texture
|
||||
void rlDisableFramebuffer(void)
|
||||
{
|
||||
@ -1729,6 +1832,14 @@ void rlBlitFramebuffer(int srcX, int srcY, int srcWidth, int srcHeight, int dstX
|
||||
#endif
|
||||
}
|
||||
|
||||
// Bind framebuffer object (fbo)
|
||||
void rlBindFramebuffer(unsigned int target, unsigned int framebuffer)
|
||||
{
|
||||
#if (defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)) && defined(RLGL_RENDER_TEXTURES_HINT)
|
||||
glBindFramebuffer(target, framebuffer);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Activate multiple draw color buffers
|
||||
// NOTE: One color buffer is always active by default
|
||||
void rlActiveDrawBuffers(int count)
|
||||
@ -1805,6 +1916,9 @@ void rlEnableBackfaceCulling(void) { glEnable(GL_CULL_FACE); }
|
||||
// Disable backface culling
|
||||
void rlDisableBackfaceCulling(void) { glDisable(GL_CULL_FACE); }
|
||||
|
||||
// Set color mask active for screen read/draw
|
||||
void rlColorMask(bool r, bool g, bool b, bool a) { glColorMask(r, g, b, a); }
|
||||
|
||||
// Set face culling mode
|
||||
void rlSetCullFace(int mode)
|
||||
{
|
||||
@ -2122,7 +2236,10 @@ void rlglInit(int width, int height)
|
||||
RLGL.State.currentShaderLocs = RLGL.State.defaultShaderLocs;
|
||||
|
||||
// Init default vertex arrays buffers
|
||||
// Simulate that the default shader has the location RL_SHADER_LOC_VERTEX_NORMAL to bind the normal buffer for the default render batch
|
||||
RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_NORMAL] = RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL;
|
||||
RLGL.defaultBatch = rlLoadRenderBatch(RL_DEFAULT_BATCH_BUFFERS, RL_DEFAULT_BATCH_BUFFER_ELEMENTS);
|
||||
RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_NORMAL] = -1;
|
||||
RLGL.currentBatch = &RLGL.defaultBatch;
|
||||
|
||||
// Init stack matrices (emulating OpenGL 1.1)
|
||||
@ -2567,6 +2684,7 @@ rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements)
|
||||
|
||||
batch.vertexBuffer[i].vertices = (float *)RL_MALLOC(bufferElements*3*4*sizeof(float)); // 3 float by vertex, 4 vertex by quad
|
||||
batch.vertexBuffer[i].texcoords = (float *)RL_MALLOC(bufferElements*2*4*sizeof(float)); // 2 float by texcoord, 4 texcoord by quad
|
||||
batch.vertexBuffer[i].normals = (float *)RL_MALLOC(bufferElements*3*4*sizeof(float)); // 3 float by vertex, 4 vertex by quad
|
||||
batch.vertexBuffer[i].colors = (unsigned char *)RL_MALLOC(bufferElements*4*4*sizeof(unsigned char)); // 4 float by color, 4 colors by quad
|
||||
#if defined(GRAPHICS_API_OPENGL_33)
|
||||
batch.vertexBuffer[i].indices = (unsigned int *)RL_MALLOC(bufferElements*6*sizeof(unsigned int)); // 6 int by quad (indices)
|
||||
@ -2577,6 +2695,7 @@ rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements)
|
||||
|
||||
for (int j = 0; j < (3*4*bufferElements); j++) batch.vertexBuffer[i].vertices[j] = 0.0f;
|
||||
for (int j = 0; j < (2*4*bufferElements); j++) batch.vertexBuffer[i].texcoords[j] = 0.0f;
|
||||
for (int j = 0; j < (3*4*bufferElements); j++) batch.vertexBuffer[i].normals[j] = 0.0f;
|
||||
for (int j = 0; j < (4*4*bufferElements); j++) batch.vertexBuffer[i].colors[j] = 0;
|
||||
|
||||
int k = 0;
|
||||
@ -2626,16 +2745,23 @@ rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements)
|
||||
glEnableVertexAttribArray(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_TEXCOORD01]);
|
||||
glVertexAttribPointer(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_TEXCOORD01], 2, GL_FLOAT, 0, 0, 0);
|
||||
|
||||
// Vertex color buffer (shader-location = 3)
|
||||
// Vertex normal buffer (shader-location = 2)
|
||||
glGenBuffers(1, &batch.vertexBuffer[i].vboId[2]);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, batch.vertexBuffer[i].vboId[2]);
|
||||
glBufferData(GL_ARRAY_BUFFER, bufferElements*3*4*sizeof(float), batch.vertexBuffer[i].normals, GL_DYNAMIC_DRAW);
|
||||
glEnableVertexAttribArray(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_NORMAL]);
|
||||
glVertexAttribPointer(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_NORMAL], 3, GL_FLOAT, 0, 0, 0);
|
||||
|
||||
// Vertex color buffer (shader-location = 3)
|
||||
glGenBuffers(1, &batch.vertexBuffer[i].vboId[3]);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, batch.vertexBuffer[i].vboId[3]);
|
||||
glBufferData(GL_ARRAY_BUFFER, bufferElements*4*4*sizeof(unsigned char), batch.vertexBuffer[i].colors, GL_DYNAMIC_DRAW);
|
||||
glEnableVertexAttribArray(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_COLOR]);
|
||||
glVertexAttribPointer(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_COLOR], 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||
|
||||
// Fill index buffer
|
||||
glGenBuffers(1, &batch.vertexBuffer[i].vboId[3]);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, batch.vertexBuffer[i].vboId[3]);
|
||||
glGenBuffers(1, &batch.vertexBuffer[i].vboId[4]);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, batch.vertexBuffer[i].vboId[4]);
|
||||
#if defined(GRAPHICS_API_OPENGL_33)
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, bufferElements*6*sizeof(int), batch.vertexBuffer[i].indices, GL_STATIC_DRAW);
|
||||
#endif
|
||||
@ -2690,10 +2816,10 @@ void rlUnloadRenderBatch(rlRenderBatch batch)
|
||||
if (RLGL.ExtSupported.vao)
|
||||
{
|
||||
glBindVertexArray(batch.vertexBuffer[i].vaoId);
|
||||
glDisableVertexAttribArray(0);
|
||||
glDisableVertexAttribArray(1);
|
||||
glDisableVertexAttribArray(2);
|
||||
glDisableVertexAttribArray(3);
|
||||
glDisableVertexAttribArray(RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION);
|
||||
glDisableVertexAttribArray(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD);
|
||||
glDisableVertexAttribArray(RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL);
|
||||
glDisableVertexAttribArray(RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
@ -2702,6 +2828,7 @@ void rlUnloadRenderBatch(rlRenderBatch batch)
|
||||
glDeleteBuffers(1, &batch.vertexBuffer[i].vboId[1]);
|
||||
glDeleteBuffers(1, &batch.vertexBuffer[i].vboId[2]);
|
||||
glDeleteBuffers(1, &batch.vertexBuffer[i].vboId[3]);
|
||||
glDeleteBuffers(1, &batch.vertexBuffer[i].vboId[4]);
|
||||
|
||||
// Delete VAOs from GPU (VRAM)
|
||||
if (RLGL.ExtSupported.vao) glDeleteVertexArrays(1, &batch.vertexBuffer[i].vaoId);
|
||||
@ -2709,6 +2836,7 @@ void rlUnloadRenderBatch(rlRenderBatch batch)
|
||||
// Free vertex arrays memory from CPU (RAM)
|
||||
RL_FREE(batch.vertexBuffer[i].vertices);
|
||||
RL_FREE(batch.vertexBuffer[i].texcoords);
|
||||
RL_FREE(batch.vertexBuffer[i].normals);
|
||||
RL_FREE(batch.vertexBuffer[i].colors);
|
||||
RL_FREE(batch.vertexBuffer[i].indices);
|
||||
}
|
||||
@ -2743,8 +2871,13 @@ void rlDrawRenderBatch(rlRenderBatch *batch)
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, RLGL.State.vertexCounter*2*sizeof(float), batch->vertexBuffer[batch->currentBuffer].texcoords);
|
||||
//glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].texcoords, GL_DYNAMIC_DRAW); // Update all buffer
|
||||
|
||||
// Colors buffer
|
||||
// Normals buffer
|
||||
glBindBuffer(GL_ARRAY_BUFFER, batch->vertexBuffer[batch->currentBuffer].vboId[2]);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, RLGL.State.vertexCounter*3*sizeof(float), batch->vertexBuffer[batch->currentBuffer].normals);
|
||||
//glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].normals, GL_DYNAMIC_DRAW); // Update all buffer
|
||||
|
||||
// Colors buffer
|
||||
glBindBuffer(GL_ARRAY_BUFFER, batch->vertexBuffer[batch->currentBuffer].vboId[3]);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, RLGL.State.vertexCounter*4*sizeof(unsigned char), batch->vertexBuffer[batch->currentBuffer].colors);
|
||||
//glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].colors, GL_DYNAMIC_DRAW); // Update all buffer
|
||||
|
||||
@ -2797,13 +2930,30 @@ void rlDrawRenderBatch(rlRenderBatch *batch)
|
||||
|
||||
// Create modelview-projection matrix and upload to shader
|
||||
Matrix matMVP = rlMatrixMultiply(RLGL.State.modelview, RLGL.State.projection);
|
||||
float matMVPfloat[16] = {
|
||||
matMVP.m0, matMVP.m1, matMVP.m2, matMVP.m3,
|
||||
matMVP.m4, matMVP.m5, matMVP.m6, matMVP.m7,
|
||||
matMVP.m8, matMVP.m9, matMVP.m10, matMVP.m11,
|
||||
matMVP.m12, matMVP.m13, matMVP.m14, matMVP.m15
|
||||
};
|
||||
glUniformMatrix4fv(RLGL.State.currentShaderLocs[RL_SHADER_LOC_MATRIX_MVP], 1, false, matMVPfloat);
|
||||
glUniformMatrix4fv(RLGL.State.currentShaderLocs[RL_SHADER_LOC_MATRIX_MVP], 1, false, rlMatrixToFloat(matMVP));
|
||||
|
||||
if (RLGL.State.currentShaderLocs[RL_SHADER_LOC_MATRIX_PROJECTION] != -1)
|
||||
{
|
||||
glUniformMatrix4fv(RLGL.State.currentShaderLocs[RL_SHADER_LOC_MATRIX_PROJECTION], 1, false, rlMatrixToFloat(RLGL.State.projection));
|
||||
}
|
||||
|
||||
// WARNING: For the following setup of the view, model, and normal matrices, it is expected that
|
||||
// transformations and rendering occur between rlPushMatrix and rlPopMatrix.
|
||||
|
||||
if (RLGL.State.currentShaderLocs[RL_SHADER_LOC_MATRIX_VIEW] != -1)
|
||||
{
|
||||
glUniformMatrix4fv(RLGL.State.currentShaderLocs[RL_SHADER_LOC_MATRIX_VIEW], 1, false, rlMatrixToFloat(RLGL.State.modelview));
|
||||
}
|
||||
|
||||
if (RLGL.State.currentShaderLocs[RL_SHADER_LOC_MATRIX_MODEL] != -1)
|
||||
{
|
||||
glUniformMatrix4fv(RLGL.State.currentShaderLocs[RL_SHADER_LOC_MATRIX_MODEL], 1, false, rlMatrixToFloat(RLGL.State.transform));
|
||||
}
|
||||
|
||||
if (RLGL.State.currentShaderLocs[RL_SHADER_LOC_MATRIX_NORMAL] != -1)
|
||||
{
|
||||
glUniformMatrix4fv(RLGL.State.currentShaderLocs[RL_SHADER_LOC_MATRIX_NORMAL], 1, false, rlMatrixToFloat(rlMatrixTranspose(rlMatrixInvert(RLGL.State.transform))));
|
||||
}
|
||||
|
||||
if (RLGL.ExtSupported.vao) glBindVertexArray(batch->vertexBuffer[batch->currentBuffer].vaoId);
|
||||
else
|
||||
@ -2818,12 +2968,17 @@ void rlDrawRenderBatch(rlRenderBatch *batch)
|
||||
glVertexAttribPointer(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_TEXCOORD01], 2, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_TEXCOORD01]);
|
||||
|
||||
// Bind vertex attrib: color (shader-location = 3)
|
||||
// Bind vertex attrib: normal (shader-location = 2)
|
||||
glBindBuffer(GL_ARRAY_BUFFER, batch->vertexBuffer[batch->currentBuffer].vboId[2]);
|
||||
glVertexAttribPointer(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_NORMAL], 3, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_NORMAL]);
|
||||
|
||||
// Bind vertex attrib: color (shader-location = 3)
|
||||
glBindBuffer(GL_ARRAY_BUFFER, batch->vertexBuffer[batch->currentBuffer].vboId[3]);
|
||||
glVertexAttribPointer(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_COLOR], 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||
glEnableVertexAttribArray(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_COLOR]);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, batch->vertexBuffer[batch->currentBuffer].vboId[3]);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, batch->vertexBuffer[batch->currentBuffer].vboId[4]);
|
||||
}
|
||||
|
||||
// Setup some default shader values
|
||||
@ -3378,7 +3533,6 @@ void rlGenTextureMipmaps(unsigned int id, int width, int height, int format, int
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// Read texture pixel data
|
||||
void *rlReadTexturePixels(unsigned int id, int width, int height, int format)
|
||||
{
|
||||
@ -3422,7 +3576,7 @@ void *rlReadTexturePixels(unsigned int id, int width, int height, int format)
|
||||
// 2 - Create an fbo, activate it, render quad with texture, glReadPixels()
|
||||
// We are using Option 1, just need to care for texture format on retrieval
|
||||
// NOTE: This behaviour could be conditioned by graphic driver...
|
||||
unsigned int fboId = rlLoadFramebuffer(width, height);
|
||||
unsigned int fboId = rlLoadFramebuffer();
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fboId);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
@ -3476,7 +3630,7 @@ unsigned char *rlReadScreenPixels(int width, int height)
|
||||
//-----------------------------------------------------------------------------------------
|
||||
// Load a framebuffer to be used for rendering
|
||||
// NOTE: No textures attached
|
||||
unsigned int rlLoadFramebuffer(int width, int height)
|
||||
unsigned int rlLoadFramebuffer(void)
|
||||
{
|
||||
unsigned int fboId = 0;
|
||||
|
||||
@ -3784,10 +3938,14 @@ unsigned int rlLoadVertexArray(void)
|
||||
}
|
||||
|
||||
// Set vertex attribute
|
||||
void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, const void *pointer)
|
||||
void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, int offset)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
glVertexAttribPointer(index, compSize, type, normalized, stride, pointer);
|
||||
// NOTE: Data type could be: GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_INT, GL_UNSIGNED_INT
|
||||
// Additional types (depends on OpenGL version or extensions):
|
||||
// - GL_HALF_FLOAT, GL_FLOAT, GL_DOUBLE, GL_FIXED,
|
||||
// - GL_INT_2_10_10_10_REV, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_10F_11F_11F_REV
|
||||
glVertexAttribPointer(index, compSize, type, normalized, stride, (void *)offset);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -3970,12 +4128,12 @@ unsigned int rlLoadShaderProgram(unsigned int vShaderId, unsigned int fShaderId)
|
||||
glAttachShader(program, fShaderId);
|
||||
|
||||
// NOTE: Default attribute shader locations must be Bound before linking
|
||||
glBindAttribLocation(program, 0, RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION);
|
||||
glBindAttribLocation(program, 1, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD);
|
||||
glBindAttribLocation(program, 2, RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL);
|
||||
glBindAttribLocation(program, 3, RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR);
|
||||
glBindAttribLocation(program, 4, RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT);
|
||||
glBindAttribLocation(program, 5, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2);
|
||||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION, RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION);
|
||||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD);
|
||||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL, RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL);
|
||||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR, RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR);
|
||||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT, RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT);
|
||||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2);
|
||||
|
||||
// NOTE: If some attrib name is no found on the shader, it locations becomes -1
|
||||
|
||||
@ -4108,7 +4266,14 @@ void rlSetUniformSampler(int locIndex, unsigned int textureId)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
// Check if texture is already active
|
||||
for (int i = 0; i < RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS; i++) if (RLGL.State.activeTextureId[i] == textureId) return;
|
||||
for (int i = 0; i < RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS; i++)
|
||||
{
|
||||
if (RLGL.State.activeTextureId[i] == textureId)
|
||||
{
|
||||
glUniform1i(locIndex, 1 + i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Register a new active texture for the internal batch system
|
||||
// NOTE: Default texture is always activated as GL_TEXTURE0
|
||||
@ -4431,10 +4596,10 @@ void rlLoadDrawQuad(void)
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), &vertices, GL_STATIC_DRAW);
|
||||
|
||||
// Bind vertex attributes (position, texcoords)
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5*sizeof(float), (void *)0); // Positions
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5*sizeof(float), (void *)(3*sizeof(float))); // Texcoords
|
||||
glEnableVertexAttribArray(RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION);
|
||||
glVertexAttribPointer(RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION, 3, GL_FLOAT, GL_FALSE, 5*sizeof(float), (void *)0); // Positions
|
||||
glEnableVertexAttribArray(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD);
|
||||
glVertexAttribPointer(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 5*sizeof(float), (void *)(3*sizeof(float))); // Texcoords
|
||||
|
||||
// Draw quad
|
||||
glBindVertexArray(quadVAO);
|
||||
@ -4505,12 +4670,12 @@ void rlLoadDrawCube(void)
|
||||
|
||||
// Bind vertex attributes (position, normals, texcoords)
|
||||
glBindVertexArray(cubeVAO);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)0); // Positions
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)(3*sizeof(float))); // Normals
|
||||
glEnableVertexAttribArray(2);
|
||||
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)(6*sizeof(float))); // Texcoords
|
||||
glEnableVertexAttribArray(RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION);
|
||||
glVertexAttribPointer(RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION, 3, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)0); // Positions
|
||||
glEnableVertexAttribArray(RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL);
|
||||
glVertexAttribPointer(RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL, 3, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)(3*sizeof(float))); // Normals
|
||||
glEnableVertexAttribArray(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD);
|
||||
glVertexAttribPointer(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)(6*sizeof(float))); // Texcoords
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
@ -4658,14 +4823,14 @@ static void rlLoadShaderDefault(void)
|
||||
TRACELOG(RL_LOG_INFO, "SHADER: [ID %i] Default shader loaded successfully", RLGL.State.defaultShaderId);
|
||||
|
||||
// Set default shader locations: attributes locations
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_VERTEX_POSITION] = glGetAttribLocation(RLGL.State.defaultShaderId, "vertexPosition");
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_VERTEX_TEXCOORD01] = glGetAttribLocation(RLGL.State.defaultShaderId, "vertexTexCoord");
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_VERTEX_COLOR] = glGetAttribLocation(RLGL.State.defaultShaderId, "vertexColor");
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_VERTEX_POSITION] = glGetAttribLocation(RLGL.State.defaultShaderId, RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION);
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_VERTEX_TEXCOORD01] = glGetAttribLocation(RLGL.State.defaultShaderId, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD);
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_VERTEX_COLOR] = glGetAttribLocation(RLGL.State.defaultShaderId, RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR);
|
||||
|
||||
// Set default shader locations: uniform locations
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_MATRIX_MVP] = glGetUniformLocation(RLGL.State.defaultShaderId, "mvp");
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_COLOR_DIFFUSE] = glGetUniformLocation(RLGL.State.defaultShaderId, "colDiffuse");
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_MAP_DIFFUSE] = glGetUniformLocation(RLGL.State.defaultShaderId, "texture0");
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_MATRIX_MVP] = glGetUniformLocation(RLGL.State.defaultShaderId, RL_DEFAULT_SHADER_UNIFORM_NAME_MVP);
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_COLOR_DIFFUSE] = glGetUniformLocation(RLGL.State.defaultShaderId, RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR);
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_MAP_DIFFUSE] = glGetUniformLocation(RLGL.State.defaultShaderId, RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0);
|
||||
}
|
||||
else TRACELOG(RL_LOG_WARNING, "SHADER: [ID %i] Failed to load default shader", RLGL.State.defaultShaderId);
|
||||
}
|
||||
@ -4817,6 +4982,31 @@ static int rlGetPixelDataSize(int width, int height, int format)
|
||||
|
||||
// Auxiliar math functions
|
||||
|
||||
// Get float array of matrix data
|
||||
static rl_float16 rlMatrixToFloatV(Matrix mat)
|
||||
{
|
||||
rl_float16 result = { 0 };
|
||||
|
||||
result.v[0] = mat.m0;
|
||||
result.v[1] = mat.m1;
|
||||
result.v[2] = mat.m2;
|
||||
result.v[3] = mat.m3;
|
||||
result.v[4] = mat.m4;
|
||||
result.v[5] = mat.m5;
|
||||
result.v[6] = mat.m6;
|
||||
result.v[7] = mat.m7;
|
||||
result.v[8] = mat.m8;
|
||||
result.v[9] = mat.m9;
|
||||
result.v[10] = mat.m10;
|
||||
result.v[11] = mat.m11;
|
||||
result.v[12] = mat.m12;
|
||||
result.v[13] = mat.m13;
|
||||
result.v[14] = mat.m14;
|
||||
result.v[15] = mat.m15;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Get identity matrix
|
||||
static Matrix rlMatrixIdentity(void)
|
||||
{
|
||||
@ -4856,4 +5046,76 @@ static Matrix rlMatrixMultiply(Matrix left, Matrix right)
|
||||
return result;
|
||||
}
|
||||
|
||||
// Transposes provided matrix
|
||||
static Matrix rlMatrixTranspose(Matrix mat)
|
||||
{
|
||||
Matrix result = { 0 };
|
||||
|
||||
result.m0 = mat.m0;
|
||||
result.m1 = mat.m4;
|
||||
result.m2 = mat.m8;
|
||||
result.m3 = mat.m12;
|
||||
result.m4 = mat.m1;
|
||||
result.m5 = mat.m5;
|
||||
result.m6 = mat.m9;
|
||||
result.m7 = mat.m13;
|
||||
result.m8 = mat.m2;
|
||||
result.m9 = mat.m6;
|
||||
result.m10 = mat.m10;
|
||||
result.m11 = mat.m14;
|
||||
result.m12 = mat.m3;
|
||||
result.m13 = mat.m7;
|
||||
result.m14 = mat.m11;
|
||||
result.m15 = mat.m15;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Invert provided matrix
|
||||
static Matrix rlMatrixInvert(Matrix mat)
|
||||
{
|
||||
Matrix result = { 0 };
|
||||
|
||||
// Cache the matrix values (speed optimization)
|
||||
float a00 = mat.m0, a01 = mat.m1, a02 = mat.m2, a03 = mat.m3;
|
||||
float a10 = mat.m4, a11 = mat.m5, a12 = mat.m6, a13 = mat.m7;
|
||||
float a20 = mat.m8, a21 = mat.m9, a22 = mat.m10, a23 = mat.m11;
|
||||
float a30 = mat.m12, a31 = mat.m13, a32 = mat.m14, a33 = mat.m15;
|
||||
|
||||
float b00 = a00*a11 - a01*a10;
|
||||
float b01 = a00*a12 - a02*a10;
|
||||
float b02 = a00*a13 - a03*a10;
|
||||
float b03 = a01*a12 - a02*a11;
|
||||
float b04 = a01*a13 - a03*a11;
|
||||
float b05 = a02*a13 - a03*a12;
|
||||
float b06 = a20*a31 - a21*a30;
|
||||
float b07 = a20*a32 - a22*a30;
|
||||
float b08 = a20*a33 - a23*a30;
|
||||
float b09 = a21*a32 - a22*a31;
|
||||
float b10 = a21*a33 - a23*a31;
|
||||
float b11 = a22*a33 - a23*a32;
|
||||
|
||||
// Calculate the invert determinant (inlined to avoid double-caching)
|
||||
float invDet = 1.0f/(b00*b11 - b01*b10 + b02*b09 + b03*b08 - b04*b07 + b05*b06);
|
||||
|
||||
result.m0 = (a11*b11 - a12*b10 + a13*b09)*invDet;
|
||||
result.m1 = (-a01*b11 + a02*b10 - a03*b09)*invDet;
|
||||
result.m2 = (a31*b05 - a32*b04 + a33*b03)*invDet;
|
||||
result.m3 = (-a21*b05 + a22*b04 - a23*b03)*invDet;
|
||||
result.m4 = (-a10*b11 + a12*b08 - a13*b07)*invDet;
|
||||
result.m5 = (a00*b11 - a02*b08 + a03*b07)*invDet;
|
||||
result.m6 = (-a30*b05 + a32*b02 - a33*b01)*invDet;
|
||||
result.m7 = (a20*b05 - a22*b02 + a23*b01)*invDet;
|
||||
result.m8 = (a10*b10 - a11*b08 + a13*b06)*invDet;
|
||||
result.m9 = (-a00*b10 + a01*b08 - a03*b06)*invDet;
|
||||
result.m10 = (a30*b04 - a31*b02 + a33*b00)*invDet;
|
||||
result.m11 = (-a20*b04 + a21*b02 - a23*b00)*invDet;
|
||||
result.m12 = (-a10*b09 + a11*b07 - a12*b06)*invDet;
|
||||
result.m13 = (a00*b09 - a01*b07 + a02*b06)*invDet;
|
||||
result.m14 = (-a30*b03 + a31*b01 - a32*b00)*invDet;
|
||||
result.m15 = (a20*b03 - a21*b01 + a22*b00)*invDet;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif // RLGL_IMPLEMENTATION
|
||||
|
35
lib/rlgl.zig
35
lib/rlgl.zig
@ -14,10 +14,11 @@ pub const rlVertexBuffer = extern struct {
|
||||
elementCount: c_int,
|
||||
vertices: [*c]f32,
|
||||
texcoords: [*c]f32,
|
||||
normals: [*c]f32,
|
||||
colors: [*c]u8,
|
||||
indices: [*c]c_ushort,
|
||||
vaoId: c_uint,
|
||||
vboId: [4]c_uint,
|
||||
vboId: [5]c_uint,
|
||||
};
|
||||
|
||||
pub const rlDrawCall = extern struct {
|
||||
@ -225,6 +226,18 @@ pub fn rlViewport(x: i32, y: i32, width: i32, height: i32) void {
|
||||
cdef.rlViewport(@as(c_int, x), @as(c_int, y), @as(c_int, width), @as(c_int, height));
|
||||
}
|
||||
|
||||
pub fn rlSetClipPlanes(near: f64, far: f64) void {
|
||||
cdef.rlSetClipPlanes(near, far);
|
||||
}
|
||||
|
||||
pub fn rlGetCullDistanceNear() f64 {
|
||||
return cdef.rlGetCullDistanceNear();
|
||||
}
|
||||
|
||||
pub fn rlGetCullDistanceFar() f64 {
|
||||
return cdef.rlGetCullDistanceFar();
|
||||
}
|
||||
|
||||
pub fn rlBegin(mode: i32) void {
|
||||
cdef.rlBegin(@as(c_int, mode));
|
||||
}
|
||||
@ -349,6 +362,10 @@ pub fn rlDisableFramebuffer() void {
|
||||
cdef.rlDisableFramebuffer();
|
||||
}
|
||||
|
||||
pub fn rlGetActiveFramebuffer() u32 {
|
||||
return @as(u32, cdef.rlGetActiveFramebuffer());
|
||||
}
|
||||
|
||||
pub fn rlActiveDrawBuffers(count: i32) void {
|
||||
cdef.rlActiveDrawBuffers(@as(c_int, count));
|
||||
}
|
||||
@ -357,6 +374,10 @@ pub fn rlBlitFramebuffer(srcX: i32, srcY: i32, srcWidth: i32, srcHeight: i32, ds
|
||||
cdef.rlBlitFramebuffer(@as(c_int, srcX), @as(c_int, srcY), @as(c_int, srcWidth), @as(c_int, srcHeight), @as(c_int, dstX), @as(c_int, dstY), @as(c_int, dstWidth), @as(c_int, dstHeight), @as(c_int, bufferMask));
|
||||
}
|
||||
|
||||
pub fn rlBindFramebuffer(target: u32, framebuffer: u32) void {
|
||||
cdef.rlBindFramebuffer(@as(c_uint, target), @as(c_uint, framebuffer));
|
||||
}
|
||||
|
||||
pub fn rlEnableColorBlend() void {
|
||||
cdef.rlEnableColorBlend();
|
||||
}
|
||||
@ -389,6 +410,10 @@ pub fn rlDisableBackfaceCulling() void {
|
||||
cdef.rlDisableBackfaceCulling();
|
||||
}
|
||||
|
||||
pub fn rlColorMask(r: bool, g: bool, b: bool, a: bool) void {
|
||||
cdef.rlColorMask(r, g, b, a);
|
||||
}
|
||||
|
||||
pub fn rlSetCullFace(mode: i32) void {
|
||||
cdef.rlSetCullFace(@as(c_int, mode));
|
||||
}
|
||||
@ -565,8 +590,8 @@ pub fn rlUnloadVertexBuffer(vboId: u32) void {
|
||||
cdef.rlUnloadVertexBuffer(@as(c_uint, vboId));
|
||||
}
|
||||
|
||||
pub fn rlSetVertexAttribute(index: u32, compSize: i32, ty: i32, normalized: bool, stride: i32, pointer: *const anyopaque) void {
|
||||
cdef.rlSetVertexAttribute(@as(c_uint, index), @as(c_int, compSize), @as(c_int, ty), normalized, @as(c_int, stride), pointer);
|
||||
pub fn rlSetVertexAttribute(index: u32, compSize: i32, ty: i32, normalized: bool, stride: i32, offset: i32) void {
|
||||
cdef.rlSetVertexAttribute(@as(c_uint, index), @as(c_int, compSize), @as(c_int, ty), normalized, @as(c_int, stride), @as(c_int, offset));
|
||||
}
|
||||
|
||||
pub fn rlSetVertexAttributeDivisor(index: u32, divisor: i32) void {
|
||||
@ -633,8 +658,8 @@ pub fn rlReadScreenPixels(width: i32, height: i32) [:0]u8 {
|
||||
return std.mem.span(cdef.rlReadScreenPixels(@as(c_int, width), @as(c_int, height)));
|
||||
}
|
||||
|
||||
pub fn rlLoadFramebuffer(width: i32, height: i32) u32 {
|
||||
return @as(u32, cdef.rlLoadFramebuffer(@as(c_int, width), @as(c_int, height)));
|
||||
pub fn rlLoadFramebuffer() u32 {
|
||||
return @as(u32, cdef.rlLoadFramebuffer());
|
||||
}
|
||||
|
||||
pub fn rlFramebufferAttach(fboId: u32, texId: u32, attachType: i32, texType: i32, mipLevel: i32) void {
|
||||
|
@ -26,12 +26,12 @@ pub fn build(b: *std.Build) !void {
|
||||
const raylib_artifact = raylib_dep.artifact("raylib");
|
||||
|
||||
//web exports are completely separate
|
||||
if (target.getOsTag() == .emscripten) {
|
||||
if (target.query.os_tag == .emscripten) {
|
||||
const exe_lib = emcc.compileForEmscripten(b, "'$PROJECT_NAME'", "src/main.zig", target, optimize);
|
||||
|
||||
exe_lib.linkLibrary(raylib_artifact);
|
||||
exe_lib.addModule("raylib", raylib);
|
||||
exe_lib.addModule("raylib-math", raylib_math);
|
||||
exe_lib.root_module.addImport("raylib", raylib);
|
||||
exe_lib.root_module.addImport("raylib-math", raylib_math);
|
||||
|
||||
// Note that raylib itself is not actually added to the exe_lib output file, so it also needs to be linked with emscripten.
|
||||
const link_step = try emcc.linkWithEmscripten(b, &[_]*std.Build.Step.Compile{ exe_lib, raylib_artifact });
|
||||
@ -47,8 +47,8 @@ pub fn build(b: *std.Build) !void {
|
||||
const exe = b.addExecutable(.{ .name = "'$PROJECT_NAME'", .root_source_file = .{ .path = "src/main.zig" }, .optimize = optimize, .target = target });
|
||||
|
||||
exe.linkLibrary(raylib_artifact);
|
||||
exe.addModule("raylib", raylib);
|
||||
exe.addModule("raylib-math", raylib_math);
|
||||
exe.root_module.addImport("raylib", raylib);
|
||||
exe.root_module.addImport("raylib-math", raylib_math);
|
||||
|
||||
const run_cmd = b.addRunArtifact(exe);
|
||||
const run_step = b.step("run", "Run '$PROJECT_NAME'");
|
||||
|
Loading…
x
Reference in New Issue
Block a user