From f4b5622ba3a89bf1044ab7ba72384fb27c4837fe Mon Sep 17 00:00:00 2001 From: Alexei Mozaidze Date: Mon, 13 May 2024 02:27:02 +0400 Subject: [PATCH 1/8] feat(zig): add `opengl_version` option (#3979) Added `opengl_version` option to `src/build.zig`. --- src/build.zig | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/build.zig b/src/build.zig index 9fa1c57cd..e111d6388 100644 --- a/src/build.zig +++ b/src/build.zig @@ -88,6 +88,10 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std. try c_source_files.append("rtextures.c"); } + if (options.opengl_version != .auto) { + raylib.defineCMacro(options.opengl_version.toCMacroStr(), null); + } + switch (target.result.os.tag) { .windows => { try c_source_files.append("rglfw.c"); @@ -134,7 +138,11 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std. raylib.defineCMacro("PLATFORM_DESKTOP", null); } else { - raylib.linkSystemLibrary("GLESv2"); + if (options.opengl_version == .auto) { + raylib.linkSystemLibrary("GLESv2"); + raylib.defineCMacro("GRAPHICS_API_OPENGL_ES2", null); + } + raylib.linkSystemLibrary("EGL"); raylib.linkSystemLibrary("drm"); raylib.linkSystemLibrary("gbm"); @@ -145,7 +153,6 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std. raylib.addIncludePath(.{ .cwd_relative = "/usr/include/libdrm" }); raylib.defineCMacro("PLATFORM_DRM", null); - raylib.defineCMacro("GRAPHICS_API_OPENGL_ES2", null); raylib.defineCMacro("EGL_NO_X11", null); raylib.defineCMacro("DEFAULT_BATCH_BUFFER_ELEMENT", "2048"); } @@ -183,7 +190,9 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std. }, .emscripten => { raylib.defineCMacro("PLATFORM_WEB", null); - raylib.defineCMacro("GRAPHICS_API_OPENGL_ES2", null); + if (options.opengl_version == .auto) { + raylib.defineCMacro("GRAPHICS_API_OPENGL_ES2", null); + } if (b.sysroot == null) { @panic("Pass '--sysroot \"$EMSDK/upstream/emscripten\"'"); @@ -239,11 +248,34 @@ pub const Options = struct { platform_drm: bool = false, shared: bool = false, linux_display_backend: LinuxDisplayBackend = .X11, + opengl_version: OpenglVersion = .auto, raylib_dependency_name: []const u8 = "raylib", raygui_dependency_name: []const u8 = "raygui", }; +pub const OpenglVersion = enum { + auto, + gl_1_1, + gl_2_1, + gl_3_3, + gl_4_3, + gles_2, + gles_3, + + pub fn toCMacroStr(self: @This()) []const u8 { + switch (self) { + .auto => @panic("OpenglVersion.auto cannot be turned into a C macro string"), + .gl_1_1 => return "GRAPHICS_API_OPENGL_11", + .gl_2_1 => return "GRAPHICS_API_OPENGL_21", + .gl_3_3 => return "GRAPHICS_API_OPENGL_33", + .gl_4_3 => return "GRAPHICS_API_OPENGL_43", + .gles_2 => return "GRAPHICS_API_OPENGL_ES2", + .gles_3 => return "GRAPHICS_API_OPENGL_ES3", + } + } +}; + pub const LinuxDisplayBackend = enum { X11, Wayland, @@ -270,6 +302,7 @@ pub fn build(b: *std.Build) !void { .rshapes = b.option(bool, "rshapes", "Compile with shapes support") orelse defaults.rshapes, .shared = b.option(bool, "shared", "Compile as shared library") orelse defaults.shared, .linux_display_backend = b.option(LinuxDisplayBackend, "linux_display_backend", "Linux display backend to use") orelse defaults.linux_display_backend, + .opengl_version = b.option(OpenglVersion, "opengl_version", "OpenGL version to use") orelse defaults.opengl_version, }; const lib = try compileRaylib(b, target, optimize, options); From 3f13f7921dc9eed92e450d0cc25e43241213db92 Mon Sep 17 00:00:00 2001 From: Filyus Date: Mon, 13 May 2024 03:33:09 +0500 Subject: [PATCH 2/8] Fix parsing of empty parentheses (#3974) Co-authored-by: Filyus --- parser/raylib_parser.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/parser/raylib_parser.c b/parser/raylib_parser.c index 9b8fd8b13..ec1d490e8 100644 --- a/parser/raylib_parser.c +++ b/parser/raylib_parser.c @@ -1006,8 +1006,14 @@ int main(int argc, char* argv[]) { funcEnd = c + 2; - // Check if previous word is void - if ((linePtr[c - 4] == 'v') && (linePtr[c - 3] == 'o') && (linePtr[c - 2] == 'i') && (linePtr[c - 1] == 'd')) break; + // Check if there are no parameters + if ((funcEnd - funcParamsStart == 2) || + ((linePtr[c - 4] == 'v') && + (linePtr[c - 3] == 'o') && + (linePtr[c - 2] == 'i') && + (linePtr[c - 1] == 'd'))) { + break; + } // Get parameter type + name, extract info char funcParamTypeName[128] = { 0 }; From 3d885ef9195825b03c9657f136293077e61ee503 Mon Sep 17 00:00:00 2001 From: Jeffery Myers Date: Sun, 12 May 2024 15:36:23 -0700 Subject: [PATCH 3/8] [raymath] Add extern "C" to raymath header for C++ (#3978) * Update raylib_api.* by CI * Add an extern C to raymath to prevent warnings in C++ --------- Co-authored-by: github-actions[bot] --- src/raymath.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/raymath.h b/src/raymath.h index 19625f10a..7a2f09296 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -77,6 +77,11 @@ #endif #endif + +#if defined(__cplusplus) +extern "C" { // Prevents name mangling of functions +#endif + //---------------------------------------------------------------------------------- // Defines and Macros //---------------------------------------------------------------------------------- @@ -2523,5 +2528,8 @@ RMAPI int QuaternionEquals(Quaternion p, Quaternion q) return result; } +#if defined(__cplusplus) +} +#endif #endif // RAYMATH_H From bf5eecc71f63d1bca76fdb377a1d231066f9258d Mon Sep 17 00:00:00 2001 From: Peter0x44 Date: Wed, 15 May 2024 07:16:45 -0700 Subject: [PATCH 4/8] [parser] Don't crash for files that don't end in newlines (#3981) The parser assumes all lines end in newlines, but sometimes this isn't true. Check for a null terminator along with '\n' when stripping leading spaces. --- parser/raylib_parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parser/raylib_parser.c b/parser/raylib_parser.c index ec1d490e8..3e36f41f1 100644 --- a/parser/raylib_parser.c +++ b/parser/raylib_parser.c @@ -1243,7 +1243,7 @@ static char **GetTextLines(const char *buffer, int length, int *linesCount) while ((bufferPtr[index] == ' ') || (bufferPtr[index] == '\t')) index++; int j = 0; - while (bufferPtr[index + j] != '\n') + while (bufferPtr[index + j] != '\n' && bufferPtr[index + j] != '\0') { lines[i][j] = bufferPtr[index + j]; j++; From 46f98063597648227cfa6fbe96c189ed970faea8 Mon Sep 17 00:00:00 2001 From: Mike Will Date: Wed, 15 May 2024 10:19:22 -0400 Subject: [PATCH 5/8] Use logarithmic scaling for a 2d example with zoom functionality (#3977) --- examples/core/core_2d_camera_mouse_zoom.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/core/core_2d_camera_mouse_zoom.c b/examples/core/core_2d_camera_mouse_zoom.c index abc6a6d14..b96a3db43 100644 --- a/examples/core/core_2d_camera_mouse_zoom.c +++ b/examples/core/core_2d_camera_mouse_zoom.c @@ -63,10 +63,9 @@ int main () camera.target = mouseWorldPos; // Zoom increment - const float zoomIncrement = 0.125f; - - camera.zoom += (wheel*zoomIncrement); - if (camera.zoom < zoomIncrement) camera.zoom = zoomIncrement; + float scaleFactor = 1.0f + (0.25f * fabsf(wheel)); + if (wheel < 0) scaleFactor = 1.0f / scaleFactor; + camera.zoom = Clamp(camera.zoom * scaleFactor, 0.125, 64); } //---------------------------------------------------------------------------------- From 479bd84400d2da4af4f1c902db2f579611d36b99 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 15 May 2024 16:19:53 +0200 Subject: [PATCH 6/8] Update shaders_palette_switch.c --- examples/shaders/shaders_palette_switch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/shaders/shaders_palette_switch.c b/examples/shaders/shaders_palette_switch.c index 3d7d409db..9ff86d83d 100644 --- a/examples/shaders/shaders_palette_switch.c +++ b/examples/shaders/shaders_palette_switch.c @@ -109,7 +109,7 @@ int main(void) if (currentPalette >= MAX_PALETTES) currentPalette = 0; else if (currentPalette < 0) currentPalette = MAX_PALETTES - 1; - // Send new value to the shader to be used on drawing. + // Send palette data to the shader to be used on drawing // NOTE: We are sending RGB triplets w/o the alpha channel SetShaderValueV(shader, paletteLoc, palettes[currentPalette], SHADER_UNIFORM_IVEC3, COLORS_PER_PALETTE); //---------------------------------------------------------------------------------- From 02d98a3e44b13584c98a7aaee0ca6fc5fb55a975 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 15 May 2024 16:33:06 +0200 Subject: [PATCH 7/8] REVIEWED: 2d camera zoom, add alternative method #3977 --- examples/core/core_2d_camera_mouse_zoom.c | 70 +++++++++++++++++------ 1 file changed, 51 insertions(+), 19 deletions(-) diff --git a/examples/core/core_2d_camera_mouse_zoom.c b/examples/core/core_2d_camera_mouse_zoom.c index b96a3db43..8af94440d 100644 --- a/examples/core/core_2d_camera_mouse_zoom.c +++ b/examples/core/core_2d_camera_mouse_zoom.c @@ -31,6 +31,8 @@ int main () Camera2D camera = { 0 }; camera.zoom = 1.0f; + int zoomMode = 0; // 0-Mouse Wheel, 1-Mouse Move + SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -39,41 +41,69 @@ int main () { // Update //---------------------------------------------------------------------------------- + if (IsKeyPressed(KEY_ONE)) zoomMode = 0; + else if (IsKeyPressed(KEY_TWO)) zoomMode = 1; + // Translate based on mouse right click if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) { Vector2 delta = GetMouseDelta(); delta = Vector2Scale(delta, -1.0f/camera.zoom); - camera.target = Vector2Add(camera.target, delta); } - // Zoom based on mouse wheel - float wheel = GetMouseWheelMove(); - if (wheel != 0) + if (zoomMode == 0) { - // Get the world point that is under the mouse - Vector2 mouseWorldPos = GetScreenToWorld2D(GetMousePosition(), camera); - - // Set the offset to where the mouse is - camera.offset = GetMousePosition(); + // Zoom based on mouse wheel + float wheel = GetMouseWheelMove(); + if (wheel != 0) + { + // Get the world point that is under the mouse + Vector2 mouseWorldPos = GetScreenToWorld2D(GetMousePosition(), camera); - // Set the target to match, so that the camera maps the world space point - // under the cursor to the screen space point under the cursor at any zoom - camera.target = mouseWorldPos; + // Set the offset to where the mouse is + camera.offset = GetMousePosition(); - // Zoom increment - float scaleFactor = 1.0f + (0.25f * fabsf(wheel)); - if (wheel < 0) scaleFactor = 1.0f / scaleFactor; - camera.zoom = Clamp(camera.zoom * scaleFactor, 0.125, 64); + // Set the target to match, so that the camera maps the world space point + // under the cursor to the screen space point under the cursor at any zoom + camera.target = mouseWorldPos; + + // Zoom increment + float scaleFactor = 1.0f + (0.25f*fabsf(wheel)); + if (wheel < 0) scaleFactor = 1.0f/scaleFactor; + camera.zoom = Clamp(camera.zoom*scaleFactor, 0.125f, 64.0f); + } } + else + { + // Zoom based on mouse left click + if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) + { + // Get the world point that is under the mouse + Vector2 mouseWorldPos = GetScreenToWorld2D(GetMousePosition(), camera); + // Set the offset to where the mouse is + camera.offset = GetMousePosition(); + + // Set the target to match, so that the camera maps the world space point + // under the cursor to the screen space point under the cursor at any zoom + camera.target = mouseWorldPos; + } + if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) + { + // Zoom increment + float deltaX = GetMouseDelta().x; + float scaleFactor = 1.0f + (0.01f*fabsf(deltaX)); + if (deltaX < 0) scaleFactor = 1.0f/scaleFactor; + camera.zoom = Clamp(camera.zoom*scaleFactor, 0.125f, 64.0f); + } + } //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); - ClearBackground(BLACK); + ClearBackground(RAYWHITE); BeginMode2D(camera); @@ -86,11 +116,13 @@ int main () rlPopMatrix(); // Draw a reference circle - DrawCircle(100, 100, 50, YELLOW); + DrawCircle(GetScreenWidth()/2, GetScreenHeight()/2, 50, MAROON); EndMode2D(); - DrawText("Mouse right button drag to move, mouse wheel to zoom", 10, 10, 20, WHITE); + DrawText("[1][2] Select mouse zoom mode (Wheel or Move)", 20, 20, 20, DARKGRAY); + if (zoomMode == 0) DrawText("Mouse right button drag to move, mouse wheel to zoom", 20, 50, 20, DARKGRAY); + else DrawText("Mouse right button drag to move, mouse press and move to zoom", 20, 50, 20, DARKGRAY); EndDrawing(); //---------------------------------------------------------------------------------- From d6b22b17aecd2346d4fd1fc8ebaea8212e40008f Mon Sep 17 00:00:00 2001 From: CosmicBagel <854116+CosmicBagel@users.noreply.github.com> Date: Wed, 15 May 2024 15:20:34 -0600 Subject: [PATCH 8/8] LazyPath.path has been deprecated, using b.path() (#3983) This works in zig 0.12, LazyPath.path has been removed in zig 0.13 Co-authored-by: CosmicBagel <> --- src/build.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build.zig b/src/build.zig index e111d6388..d172b3c2a 100644 --- a/src/build.zig +++ b/src/build.zig @@ -204,7 +204,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std. var dir = std.fs.openDirAbsolute(cache_include, std.fs.Dir.OpenDirOptions{ .access_sub_paths = true, .no_follow = true }) catch @panic("No emscripten cache. Generate it!"); dir.close(); - raylib.addIncludePath(.{ .path = cache_include }); + raylib.addIncludePath(b.path(cache_include)); }, else => { @panic("Unsupported OS");