From f19d4c71ab071d089327d974e0af94ef0a988de0 Mon Sep 17 00:00:00 2001 From: Jonathan Marler Date: Mon, 31 Mar 2025 10:23:34 -0600 Subject: [PATCH 1/7] core_window_flags example: add borderless windowed toggle --- examples/core/core_window_flags.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/examples/core/core_window_flags.c b/examples/core/core_window_flags.c index bb5543b1d..fb4058a9f 100644 --- a/examples/core/core_window_flags.c +++ b/examples/core/core_window_flags.c @@ -134,6 +134,9 @@ int main(void) else SetWindowState(FLAG_VSYNC_HINT); } + if (IsKeyPressed(KEY_B)) ToggleBorderlessWindowed(); + + // Bouncing ball logic ballPosition.x += ballSpeed.x; ballPosition.y += ballSpeed.y; @@ -179,14 +182,16 @@ int main(void) else DrawText("[A] FLAG_WINDOW_ALWAYS_RUN: off", 10, 240, 10, MAROON); if (IsWindowState(FLAG_VSYNC_HINT)) DrawText("[V] FLAG_VSYNC_HINT: on", 10, 260, 10, LIME); else DrawText("[V] FLAG_VSYNC_HINT: off", 10, 260, 10, MAROON); + if (IsWindowState(FLAG_BORDERLESS_WINDOWED_MODE)) DrawText("[B] FLAG_BORDERLESS_WINDOWED_MODE: on", 10, 280, 10, LIME); + else DrawText("[B] FLAG_BORDERLESS_WINDOWED_MODE: off", 10, 280, 10, MAROON); - DrawText("Following flags can only be set before window creation:", 10, 300, 10, GRAY); - if (IsWindowState(FLAG_WINDOW_HIGHDPI)) DrawText("FLAG_WINDOW_HIGHDPI: on", 10, 320, 10, LIME); - else DrawText("FLAG_WINDOW_HIGHDPI: off", 10, 320, 10, MAROON); - if (IsWindowState(FLAG_WINDOW_TRANSPARENT)) DrawText("FLAG_WINDOW_TRANSPARENT: on", 10, 340, 10, LIME); - else DrawText("FLAG_WINDOW_TRANSPARENT: off", 10, 340, 10, MAROON); - if (IsWindowState(FLAG_MSAA_4X_HINT)) DrawText("FLAG_MSAA_4X_HINT: on", 10, 360, 10, LIME); - else DrawText("FLAG_MSAA_4X_HINT: off", 10, 360, 10, MAROON); + DrawText("Following flags can only be set before window creation:", 10, 320, 10, GRAY); + if (IsWindowState(FLAG_WINDOW_HIGHDPI)) DrawText("FLAG_WINDOW_HIGHDPI: on", 10, 340, 10, LIME); + else DrawText("FLAG_WINDOW_HIGHDPI: off", 10, 340, 10, MAROON); + if (IsWindowState(FLAG_WINDOW_TRANSPARENT)) DrawText("FLAG_WINDOW_TRANSPARENT: on", 10, 360, 10, LIME); + else DrawText("FLAG_WINDOW_TRANSPARENT: off", 10, 360, 10, MAROON); + if (IsWindowState(FLAG_MSAA_4X_HINT)) DrawText("FLAG_MSAA_4X_HINT: on", 10, 380, 10, LIME); + else DrawText("FLAG_MSAA_4X_HINT: off", 10, 380, 10, MAROON); EndDrawing(); //----------------------------------------------------- From d52687eeee6697336c084ada437b98fb2ebbdd7c Mon Sep 17 00:00:00 2001 From: Lumen Keyes Date: Mon, 31 Mar 2025 13:36:51 -0600 Subject: [PATCH 2/7] Add Android Target to build.zig Added an Android target to the zig build script. This allows a user to easily build with only Android-supported libraries. Library paths are automatically inferred as much as possible. --- build.zig | 88 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 72 insertions(+), 16 deletions(-) diff --git a/build.zig b/build.zig index b67ff49d9..a5f88d2b5 100644 --- a/build.zig +++ b/build.zig @@ -16,6 +16,7 @@ fn setDesktopPlatform(raylib: *std.Build.Step.Compile, platform: PlatformBackend .glfw => raylib.root_module.addCMacro("PLATFORM_DESKTOP_GLFW", ""), .rgfw => raylib.root_module.addCMacro("PLATFORM_DESKTOP_RGFW", ""), .sdl => raylib.root_module.addCMacro("PLATFORM_DESKTOP_SDL", ""), + .android => raylib.root_module.addCMacro("PLATFORM_ANDROID", ""), else => {}, } } @@ -181,7 +182,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std. .windows => { switch (options.platform) { .glfw => try c_source_files.append("src/rglfw.c"), - .rgfw, .sdl, .drm => {}, + .rgfw, .sdl, .drm, .android => {}, } raylib.linkSystemLibrary("winmm"); @@ -191,7 +192,71 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std. setDesktopPlatform(raylib, options.platform); }, .linux => { - if (options.platform != .drm) { + + if (options.platform == .drm) { + if (options.opengl_version == .auto) { + raylib.linkSystemLibrary("GLESv2"); + raylib.root_module.addCMacro("GRAPHICS_API_OPENGL_ES2", ""); + } + + raylib.linkSystemLibrary("EGL"); + raylib.linkSystemLibrary("gbm"); + raylib.linkSystemLibrary2("libdrm", .{ .use_pkg_config = .force }); + + raylib.root_module.addCMacro("PLATFORM_DRM", ""); + raylib.root_module.addCMacro("EGL_NO_X11", ""); + raylib.root_module.addCMacro("DEFAULT_BATCH_BUFFER_ELEMENT", ""); + } else if (target.result.abi == .android) { + + //these are the only tag options per https://developer.android.com/ndk/guides/other_build_systems + const hostTuple = switch(builtin.target.os.tag) { + .linux => "linux-x86_64", + .windows => "windows-x86_64", + .macos => "darwin-x86_64", + else => { + @panic("unsupported host OS"); + } + }; + + const androidTriple = try target.result.linuxTriple(b.allocator); + const androidNdkPathString: []const u8 = options.android_ndk; + if(androidNdkPathString.len < 1) @panic("no ndk path provided and ANDROID_NDK_HOME is not set"); + const androidApiLevel: []const u8 = options.android_api_version; + + const androidSysroot = try std.fs.path.join(b.allocator, &.{androidNdkPathString, "/toolchains/llvm/prebuilt/", hostTuple, "/sysroot"}); + const androidLibPath = try std.fs.path.join(b.allocator, &.{androidSysroot, "/usr/lib/", androidTriple}); + const androidApiSpecificPath = try std.fs.path.join(b.allocator, &.{androidLibPath, androidApiLevel}); + const androidIncludePath = try std.fs.path.join(b.allocator, &.{androidSysroot, "/usr/include"}); + const androidArchIncludePath = try std.fs.path.join(b.allocator, &.{androidIncludePath, androidTriple}); + const androidAsmPath = try std.fs.path.join(b.allocator, &.{androidIncludePath, "/asm-generic"}); + const androidGluePath = try std.fs.path.join(b.allocator, &.{androidNdkPathString, "/sources/android/native_app_glue/"}); + + raylib.addLibraryPath(.{ .cwd_relative = androidLibPath}); + raylib.root_module.addLibraryPath(.{ .cwd_relative = androidApiSpecificPath }); + raylib.addSystemIncludePath(.{ .cwd_relative = androidIncludePath }); + raylib.addSystemIncludePath(.{ .cwd_relative = androidArchIncludePath}); + raylib.addSystemIncludePath( .{ .cwd_relative = androidAsmPath}); + raylib.addSystemIncludePath(.{ .cwd_relative = androidGluePath}); + + const libcFile = try std.fs.cwd().createFile("android-libc.txt", .{}); + const writer = libcFile.writer(); + const libc = std.zig.LibCInstallation{ + .include_dir = androidIncludePath, + .sys_include_dir = androidIncludePath, + .crt_dir = androidApiSpecificPath, + }; + try libc.render(writer); + libcFile.close(); + + raylib.setLibCFile(b.path("android-libc.txt")); + + if (options.opengl_version == .auto) { + raylib.root_module.linkSystemLibrary("GLESv2", .{}); + raylib.root_module.addCMacro("GRAPHICS_API_OPENGL_ES2", ""); + } + + setDesktopPlatform(raylib, .android); + } else { try c_source_files.append("src/rglfw.c"); if (options.linux_display_backend == .X11 or options.linux_display_backend == .Both) { @@ -229,21 +294,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std. waylandGenerate(b, raylib, "xdg-activation-v1.xml", "xdg-activation-v1-client-protocol"); waylandGenerate(b, raylib, "idle-inhibit-unstable-v1.xml", "idle-inhibit-unstable-v1-client-protocol"); } - setDesktopPlatform(raylib, options.platform); - } else { - if (options.opengl_version == .auto) { - raylib.linkSystemLibrary("GLESv2"); - raylib.root_module.addCMacro("GRAPHICS_API_OPENGL_ES2", ""); - } - - raylib.linkSystemLibrary("EGL"); - raylib.linkSystemLibrary("gbm"); - raylib.linkSystemLibrary2("libdrm", .{ .use_pkg_config = .force }); - - raylib.root_module.addCMacro("PLATFORM_DRM", ""); - raylib.root_module.addCMacro("EGL_NO_X11", ""); - raylib.root_module.addCMacro("DEFAULT_BATCH_BUFFER_ELEMENT", ""); } }, .freebsd, .openbsd, .netbsd, .dragonfly => { @@ -335,6 +386,8 @@ pub const Options = struct { shared: bool = false, linux_display_backend: LinuxDisplayBackend = .Both, opengl_version: OpenglVersion = .auto, + android_ndk: []const u8 = "", + android_api_version: []const u8 = "35", /// config should be a list of space-separated cflags, eg, "-DSUPPORT_CUSTOM_FRAME_CONTROL" config: []const u8 = &.{}, @@ -352,6 +405,8 @@ pub const Options = struct { .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, .config = b.option([]const u8, "config", "Compile with custom define macros overriding config.h") orelse &.{}, + .android_ndk = b.option([]const u8, "android_ndk", "specify path to android ndk") orelse std.process.getEnvVarOwned(b.allocator, "ANDROID_NDK_HOME") catch "", + .android_api_version = b.option([]const u8, "android_api_version", "specify target android API level") orelse defaults.android_api_version, }; } }; @@ -389,6 +444,7 @@ pub const PlatformBackend = enum { rgfw, sdl, drm, + android }; pub fn build(b: *std.Build) !void { From 1a67dcb578b26479254713b21cff07091077ed20 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 1 Apr 2025 01:26:51 +0200 Subject: [PATCH 3/7] REVIEWED: RGB order on SDL3 #3568 --- src/platforms/rcore_desktop_sdl.c | 46 ++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/platforms/rcore_desktop_sdl.c b/src/platforms/rcore_desktop_sdl.c index 6e62838e3..0164d15d9 100644 --- a/src/platforms/rcore_desktop_sdl.c +++ b/src/platforms/rcore_desktop_sdl.c @@ -702,70 +702,84 @@ void SetWindowIcon(Image image) switch (image.format) { case PIXELFORMAT_UNCOMPRESSED_GRAYSCALE: + { rmask = 0xFF, gmask = 0; bmask = 0, amask = 0; depth = 8, pitch = image.width; - break; + } break; case PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA: + { rmask = 0xFF, gmask = 0xFF00; bmask = 0, amask = 0; depth = 16, pitch = image.width*2; - break; + } break; case PIXELFORMAT_UNCOMPRESSED_R5G6B5: + { rmask = 0xF800, gmask = 0x07E0; bmask = 0x001F, amask = 0; depth = 16, pitch = image.width*2; - break; - case PIXELFORMAT_UNCOMPRESSED_R8G8B8: // Uses BGR for 24-bit - rmask = 0x0000FF, gmask = 0x00FF00; - bmask = 0xFF0000, amask = 0; + } break; + case PIXELFORMAT_UNCOMPRESSED_R8G8B8: + { + // WARNING: SDL2 could be using BGR but SDL3 RGB + rmask = 0xFF0000, gmask = 0x00FF00; + bmask = 0x0000FF, amask = 0; depth = 24, pitch = image.width*3; - break; + } break; case PIXELFORMAT_UNCOMPRESSED_R5G5B5A1: + { rmask = 0xF800, gmask = 0x07C0; bmask = 0x003E, amask = 0x0001; depth = 16, pitch = image.width*2; - break; + } break; case PIXELFORMAT_UNCOMPRESSED_R4G4B4A4: + { rmask = 0xF000, gmask = 0x0F00; bmask = 0x00F0, amask = 0x000F; depth = 16, pitch = image.width*2; - break; + } break; case PIXELFORMAT_UNCOMPRESSED_R8G8B8A8: + { rmask = 0xFF000000, gmask = 0x00FF0000; bmask = 0x0000FF00, amask = 0x000000FF; depth = 32, pitch = image.width*4; - break; + } break; case PIXELFORMAT_UNCOMPRESSED_R32: + { rmask = 0xFFFFFFFF, gmask = 0; bmask = 0, amask = 0; depth = 32, pitch = image.width*4; - break; + } break; case PIXELFORMAT_UNCOMPRESSED_R32G32B32: + { rmask = 0xFFFFFFFF, gmask = 0xFFFFFFFF; bmask = 0xFFFFFFFF, amask = 0; depth = 96, pitch = image.width*12; - break; + } break; case PIXELFORMAT_UNCOMPRESSED_R32G32B32A32: + { rmask = 0xFFFFFFFF, gmask = 0xFFFFFFFF; bmask = 0xFFFFFFFF, amask = 0xFFFFFFFF; depth = 128, pitch = image.width*16; - break; + } break; case PIXELFORMAT_UNCOMPRESSED_R16: + { rmask = 0xFFFF, gmask = 0; bmask = 0, amask = 0; depth = 16, pitch = image.width*2; - break; + } break; case PIXELFORMAT_UNCOMPRESSED_R16G16B16: + { rmask = 0xFFFF, gmask = 0xFFFF; bmask = 0xFFFF, amask = 0; depth = 48, pitch = image.width*6; - break; + } break; case PIXELFORMAT_UNCOMPRESSED_R16G16B16A16: + { rmask = 0xFFFF, gmask = 0xFFFF; bmask = 0xFFFF, amask = 0xFFFF; depth = 64, pitch = image.width*8; - break; + } break; default: return; // Compressed formats are not supported } From 33b2829a89a9ff6d971fe8fcf323e1b4b90e4628 Mon Sep 17 00:00:00 2001 From: Lumen Keyes Date: Tue, 1 Apr 2025 10:43:22 -0600 Subject: [PATCH 4/7] fix android-libc.txt generation Previously, the libc paths file `android-libc.txt` was written to the folder from which the user ran `zig build`. This caused problems when using raylib as a dependency in other zig projects, since raylib is not built in the project root, but the `android-libc.txt` file was still generated in the project root. The file should now be generated in .zig-cache, which should fix the isssue (and leave the project root folder cleaner). --- build.zig | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/build.zig b/build.zig index a5f88d2b5..dd0d6df6e 100644 --- a/build.zig +++ b/build.zig @@ -238,17 +238,15 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std. raylib.addSystemIncludePath( .{ .cwd_relative = androidAsmPath}); raylib.addSystemIncludePath(.{ .cwd_relative = androidGluePath}); - const libcFile = try std.fs.cwd().createFile("android-libc.txt", .{}); - const writer = libcFile.writer(); - const libc = std.zig.LibCInstallation{ + var libcData = std.ArrayList(u8).init(b.allocator).writer(); + const writer = libcData.writer(); + try (std.zig.LibCInstallation{ .include_dir = androidIncludePath, .sys_include_dir = androidIncludePath, .crt_dir = androidApiSpecificPath, - }; - try libc.render(writer); - libcFile.close(); - - raylib.setLibCFile(b.path("android-libc.txt")); + }).render(writer); + const libcFile = b.addWriteFiles().add("android-libc.txt", try libcData.toOwnedSlice()); + raylib.setLibCFile(libcFile); if (options.opengl_version == .auto) { raylib.root_module.linkSystemLibrary("GLESv2", .{}); From d0cf8961d308cc7037df67d70ec1ea75cdf203b7 Mon Sep 17 00:00:00 2001 From: Lumen Keyes Date: Tue, 1 Apr 2025 10:54:51 -0600 Subject: [PATCH 5/7] fix typo --- build.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig b/build.zig index dd0d6df6e..d7d118003 100644 --- a/build.zig +++ b/build.zig @@ -238,7 +238,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std. raylib.addSystemIncludePath( .{ .cwd_relative = androidAsmPath}); raylib.addSystemIncludePath(.{ .cwd_relative = androidGluePath}); - var libcData = std.ArrayList(u8).init(b.allocator).writer(); + var libcData = std.ArrayList(u8).init(b.allocator); const writer = libcData.writer(); try (std.zig.LibCInstallation{ .include_dir = androidIncludePath, From 1c4aa1378f61e24b2699b24ce05d5a16db64f380 Mon Sep 17 00:00:00 2001 From: Eike Decker Date: Tue, 1 Apr 2025 23:07:59 +0200 Subject: [PATCH 6/7] [rcore][SDL2] First touch position is overwritten with mouse pos I believe it makes sense to only do this when there are no known touch points. I am not even sure if this should be done at all. See https://github.com/raysan5/raylib/issues/4872 for more information. --- src/platforms/rcore_desktop_sdl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/platforms/rcore_desktop_sdl.c b/src/platforms/rcore_desktop_sdl.c index 0164d15d9..517e43914 100644 --- a/src/platforms/rcore_desktop_sdl.c +++ b/src/platforms/rcore_desktop_sdl.c @@ -1363,7 +1363,10 @@ void PollInputEvents(void) for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.currentTouchState[i]; // Map touch position to mouse position for convenience - CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition; + if (CORE.Input.Touch.pointCount == 0) + { + CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition; + } int touchAction = -1; // 0-TOUCH_ACTION_UP, 1-TOUCH_ACTION_DOWN, 2-TOUCH_ACTION_MOVE bool realTouch = false; // Flag to differentiate real touch gestures from mouse ones From ceb1a5ea2b7550aa01c103b4b3dac0dbc4d8f8fe Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 3 Apr 2025 18:31:05 +0200 Subject: [PATCH 7/7] REVIEWED: Temporaly fix for issue #4874 --- examples/textures/textures_polygon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/textures/textures_polygon.c b/examples/textures/textures_polygon.c index 729e25184..1cde29a4b 100644 --- a/examples/textures/textures_polygon.c +++ b/examples/textures/textures_polygon.c @@ -115,9 +115,9 @@ int main(void) // without crossing perimeter, points must be in anticlockwise order void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2 *points, Vector2 *texcoords, int pointCount, Color tint) { - rlSetTexture(texture.id); - rlBegin(RL_TRIANGLES); + + rlSetTexture(texture.id); rlColor4ub(tint.r, tint.g, tint.b, tint.a);