From 025b86b226e5257ee12aec362a38083aa6fd9dbe Mon Sep 17 00:00:00 2001 From: vsaint1 Date: Sat, 23 May 2026 04:36:07 -0300 Subject: [PATCH 01/18] feat: iOS option cmake --- CMakeOptions.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeOptions.txt b/CMakeOptions.txt index 9e253dc55f87..e50c0f3b266d 100644 --- a/CMakeOptions.txt +++ b/CMakeOptions.txt @@ -6,7 +6,7 @@ if(EMSCRIPTEN) # When configuring web builds with "emcmake cmake -B build -S .", set PLATFORM to Web by default SET(PLATFORM Web CACHE STRING "Platform to build for.") endif() -enum_option(PLATFORM "Desktop;Win32;Web;WebRGFW;Android;Raspberry Pi;DRM;SDL;RGFW;Memory" "Platform to build for.") +enum_option(PLATFORM "Desktop;Win32;Web;WebRGFW;Android;iOS;Raspberry Pi;DRM;SDL;RGFW;Memory" "Platform to build for.") enum_option(OPENGL_VERSION "OFF;4.3;3.3;2.1;1.1;ES 2.0;ES 3.0;Software" "Force a specific OpenGL Version?") From c80e0c4733296dbe4349e6e37c26059ee878165e Mon Sep 17 00:00:00 2001 From: vsaint1 Date: Sat, 23 May 2026 04:36:50 -0300 Subject: [PATCH 02/18] feat: iOS configuration build --- CMakeLists.txt | 4 ++++ cmake/LibraryConfigurations.cmake | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f1d319e8d7f6..ed8ba8b26577 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,10 @@ include(CompilerFlags) # Registers build options that are exposed to cmake include(CMakeOptions.txt) +if ("${PLATFORM}" STREQUAL "iOS") + enable_language(OBJC) +endif() + if (UNIX AND NOT APPLE AND NOT "${PLATFORM}" MATCHES "DRM" AND NOT "${PLATFORM}" MATCHES "Web" AND NOT "${PLATFORM}" MATCHES "SDL") if (NOT GLFW_BUILD_WAYLAND AND NOT GLFW_BUILD_X11) message(FATAL_ERROR "Cannot disable both Wayland and X11") diff --git a/cmake/LibraryConfigurations.cmake b/cmake/LibraryConfigurations.cmake index 262150be0d8a..3a5bf430d8fa 100644 --- a/cmake/LibraryConfigurations.cmake +++ b/cmake/LibraryConfigurations.cmake @@ -133,6 +133,24 @@ elseif (${PLATFORM} STREQUAL "Android") set(LIBS_PRIVATE log android EGL GLESv2 OpenSLES atomic c) set(LIBS_PUBLIC m) +elseif (${PLATFORM} STREQUAL "iOS") + set(PLATFORM_CPP "PLATFORM_IOS") + set(GRAPHICS "GRAPHICS_API_OPENGL_ES3") + + find_library(UIKIT_LIBRARY UIKit) + find_library(QUARTZCORE_LIBRARY QuartzCore) + find_library(OPENGL_ES_LIBRARY OpenGLES) + find_library(COREMOTION_LIBRARY CoreMotion) + find_library(FOUNDATION_LIBRARY Foundation) + + set(LIBS_PRIVATE + ${UIKIT_LIBRARY} + ${QUARTZCORE_LIBRARY} + ${OPENGL_ES_LIBRARY} + ${COREMOTION_LIBRARY} + ${FOUNDATION_LIBRARY} + ) + elseif ("${PLATFORM}" STREQUAL "DRM") set(PLATFORM_CPP "PLATFORM_DRM") From 070ab4c693596982a4d46cf7bf08d6b0d7d79986 Mon Sep 17 00:00:00 2001 From: vsaint1 Date: Sat, 23 May 2026 04:48:58 -0300 Subject: [PATCH 03/18] feat: raylib platform processor (ios) --- src/raylib.h | 5 +++++ src/rcore.c | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/raylib.h b/src/raylib.h index e8164073feff..c9ddb8a31af5 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -113,6 +113,11 @@ #define RLAPI // Functions defined as 'extern' by default (implicit specifiers) #endif +// iOS owns the real main() via UIApplicationMain. +#if defined(PLATFORM_IOS) + #define main raylib_main +#endif + //---------------------------------------------------------------------------------- // Defines and Macros //---------------------------------------------------------------------------------- diff --git a/src/rcore.c b/src/rcore.c index 74774e77b044..32994a616b24 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -526,6 +526,8 @@ const char *TextFormat(const char *text, ...); // Formatting of text with variab #include "platforms/rcore_drm.c" #elif defined(PLATFORM_ANDROID) #include "platforms/rcore_android.c" +#elif defined(PLATFORM_IOS) + #include "platforms/rcore_ios.c" #elif defined(PLATFORM_MEMORY) #include "platforms/rcore_memory.c" #else @@ -604,6 +606,8 @@ void InitWindow(int width, int height, const char *title) TRACELOG(LOG_INFO, "Platform backend: ANDROID"); #elif defined(PLATFORM_MEMORY) TRACELOG(LOG_INFO, "Platform backend: MEMORY (No OS)"); +#elif defined(PLATFORM_IOS) + TRACELOG(LOG_INFO, "Platform backend: iOS"); #else // TODO: Include your custom platform backend! // i.e software rendering backend or console backend! From c550fbf22913e94309256d84543ca982bacbc9e1 Mon Sep 17 00:00:00 2001 From: vsaint1 Date: Sat, 23 May 2026 04:51:23 -0300 Subject: [PATCH 04/18] iOS opengles extensions imports --- src/CMakeLists.txt | 11 +++++++++++ src/rlgl.h | 13 ++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5e5dd91eedeb..adfe7d83ae5a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -38,6 +38,12 @@ set(raylib_sources rtextures.c ) +if (${PLATFORM} STREQUAL "iOS") + list(APPEND raylib_sources + rcore_ios_main.m + ) +endif() + # /cmake/GlfwImport.cmake handles the details around the inclusion of glfw if (NOT ${PLATFORM} MATCHES "Web") include(GlfwImport) @@ -104,6 +110,11 @@ target_link_libraries(raylib PUBLIC ${LIBS_PUBLIC}) # and you will be able to select more build options include(CompileDefinitions) +if (${PLATFORM} STREQUAL "iOS") + target_compile_definitions(raylib PRIVATE GLES_SILENCE_DEPRECATION=1) + target_compile_options(raylib PRIVATE -Wno-deprecated-declarations) +endif() + # Registering include directories target_include_directories(raylib PUBLIC diff --git a/src/rlgl.h b/src/rlgl.h index ea5673397e90..e927abde48a5 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -876,9 +876,16 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad #endif #if defined(GRAPHICS_API_OPENGL_ES3) - #include // OpenGL ES 3.0 library - #define GL_GLEXT_PROTOTYPES - #include // OpenGL ES 2.0 extensions library + #if defined(PLATFORM_IOS) + #include // OpenGL ES 3.0 library + #define GL_GLEXT_PROTOTYPES + #include // OpenGL ES extensions used by raylib + #include // OpenGL ES 3.0 extensions library + #else + #include // OpenGL ES 3.0 library + #define GL_GLEXT_PROTOTYPES + #include // OpenGL ES 2.0 extensions library + #endif #elif defined(GRAPHICS_API_OPENGL_ES2) // NOTE: OpenGL ES 2.0 can be enabled on Desktop platforms, // in that case, functions are loaded from a custom glad for OpenGL ES 2.0 From 97af130bd3acc1cedcb58296507fa44ff58fbe1d Mon Sep 17 00:00:00 2001 From: vsaint1 Date: Sat, 23 May 2026 05:28:30 -0300 Subject: [PATCH 05/18] feat(apple): default property list --- examples/iOS/Info.plist | 79 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 examples/iOS/Info.plist diff --git a/examples/iOS/Info.plist b/examples/iOS/Info.plist new file mode 100644 index 000000000000..71900b80faa3 --- /dev/null +++ b/examples/iOS/Info.plist @@ -0,0 +1,79 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + raylib iOS Example + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + com.raylib.raylib-ios-example + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + raylib-ios-example + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + CFBundleIcons + + CFBundlePrimaryIcon + + CFBundleIconFiles + + raylib_180x180 + raylib_512x512 + raylib_1024x1024 + + + + CFBundleIcons~ipad + + CFBundlePrimaryIcon + + CFBundleIconFiles + + raylib_180x180 + raylib_512x512 + raylib_1024x1024 + + + + UIRequiredDeviceCapabilities + + opengles-3 + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + RaylibSceneDelegate + UISceneClassName + UIWindowScene + + + + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + + + + + From 02d6041dc203ef27d5ddb01cce99fd90e6c9198e Mon Sep 17 00:00:00 2001 From: vsaint1 Date: Sat, 23 May 2026 06:16:17 -0300 Subject: [PATCH 06/18] feat: ios guide device/simulator --- examples/iOS/README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 examples/iOS/README.md diff --git a/examples/iOS/README.md b/examples/iOS/README.md new file mode 100644 index 000000000000..3eca0a1055cf --- /dev/null +++ b/examples/iOS/README.md @@ -0,0 +1,42 @@ +# raylib Breakout demo + +This example is generated with CMake and opened in Xcode. Use the simulator or a real device by changing the Apple SDK you target. + +## Requirements + +- macOS with Xcode installed +- CMake 3.18 or newer +- iOS Simulator support from Xcode, or a connected iPhone/iPad for device testing +- An Apple developer signing team if you want to run on a real device +- Min. iOS API 13 + +## Generate the Xcode project + +From this folder, run: + +```sh +cmake -S . -B build -G Xcode -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator +``` + +This generates `build/raylib_ios_example.xcodeproj`. + +## Run in the iOS Simulator + +1. Open `build/raylib_ios_example.xcodeproj` in Xcode. +2. Select an iPhone Simulator destination. +3. Build and run the `raylib-ios-example` scheme. + +## Run on a real iPhone or iPad + +1. Regenerate the project for the device SDK: + +```sh +cmake -S . -B build -G Xcode -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos +``` + +2. Open the generated Xcode project. +3. Select your connected device. +4. Set a valid signing team in Xcode if needed. +5. Build and run the same `raylib-ios-example` scheme. + + From 6fbd0248d5c9cdc98d98279cfd03753165ae5023 Mon Sep 17 00:00:00 2001 From: vsaint1 Date: Sat, 23 May 2026 06:17:00 -0300 Subject: [PATCH 07/18] feat: cmake iOS base example --- examples/iOS/CMakeLists.txt | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 examples/iOS/CMakeLists.txt diff --git a/examples/iOS/CMakeLists.txt b/examples/iOS/CMakeLists.txt new file mode 100644 index 000000000000..584ba170e7e7 --- /dev/null +++ b/examples/iOS/CMakeLists.txt @@ -0,0 +1,62 @@ +cmake_minimum_required(VERSION 3.25) + +project(raylib_ios_example LANGUAGES C OBJC) + +set(raylib_ios_example_sources + ${CMAKE_CURRENT_LIST_DIR}/main.c + ${CMAKE_CURRENT_LIST_DIR}/../../src/rcore.c + ${CMAKE_CURRENT_LIST_DIR}/../../src/rmodels.c + ${CMAKE_CURRENT_LIST_DIR}/../../src/rshapes.c + ${CMAKE_CURRENT_LIST_DIR}/../../src/rtext.c + ${CMAKE_CURRENT_LIST_DIR}/../../src/rtextures.c + ${CMAKE_CURRENT_LIST_DIR}/../../src/rcore_ios_main.m + ${CMAKE_CURRENT_LIST_DIR}/../../logo/raylib_1024x1024.png + ${CMAKE_CURRENT_LIST_DIR}/../../logo/raylib_512x512.png + ${CMAKE_CURRENT_LIST_DIR}/../../logo/raylib_180x180.png +) + +find_library(UIKIT_LIBRARY UIKit) +find_library(QUARTZCORE_LIBRARY QuartzCore) +find_library(OPENGLES_LIBRARY OpenGLES) +find_library(COREMOTION_LIBRARY CoreMotion) +find_library(FOUNDATION_LIBRARY Foundation) + +add_executable(raylib-ios-example MACOSX_BUNDLE ${raylib_ios_example_sources}) + +target_include_directories(raylib-ios-example PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/../../src +) + +target_compile_definitions(raylib-ios-example PRIVATE + PLATFORM_IOS + GRAPHICS_API_OPENGL_ES3 + SUPPORT_MODULE_RAUDIO=0 # FIXME: Currently the mini_audio backend is not working on iOS, so we disable audio support for this example + GLES_SILENCE_DEPRECATION=1 +) + +target_compile_options(raylib-ios-example PRIVATE -Wno-deprecated-declarations) + +set_source_files_properties( + ${CMAKE_CURRENT_LIST_DIR}/../../logo/raylib_1024x1024.png + ${CMAKE_CURRENT_LIST_DIR}/../../logo/raylib_512x512.png + ${CMAKE_CURRENT_LIST_DIR}/../../logo/raylib_180x180.png + PROPERTIES MACOSX_PACKAGE_LOCATION Resources +) + +target_link_libraries(raylib-ios-example PRIVATE + ${UIKIT_LIBRARY} + ${QUARTZCORE_LIBRARY} + ${OPENGLES_LIBRARY} + ${COREMOTION_LIBRARY} + ${FOUNDATION_LIBRARY} +) + +set_target_properties(raylib-ios-example PROPERTIES + MACOSX_BUNDLE TRUE + MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_LIST_DIR}/Info.plist" + XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "YES" + XCODE_ATTRIBUTE_GENERATE_INFOPLIST_FILE "NO" + XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "13.0" + XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.raylib.raylib-ios-example" + XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2" +) \ No newline at end of file From 4ff554e950df58818c4907455cd69452dd709ba7 Mon Sep 17 00:00:00 2001 From: vsaint1 Date: Sat, 23 May 2026 06:19:13 -0300 Subject: [PATCH 08/18] feat: breakout test game --- examples/iOS/main.c | 433 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 433 insertions(+) create mode 100644 examples/iOS/main.c diff --git a/examples/iOS/main.c b/examples/iOS/main.c new file mode 100644 index 000000000000..d367dbe4109f --- /dev/null +++ b/examples/iOS/main.c @@ -0,0 +1,433 @@ +#include "raylib.h" +#include "raymath.h" + +#define BRICK_ROWS 5 +#define BRICK_COLS 7 +#define BRICK_PADDING 6.0f +#define BALL_SPEED_INIT 500.0f +#define BALL_SPEED_MAX 900.0f + +typedef enum { + STATE_TITLE, + STATE_PLAYING, + STATE_PAUSED, + STATE_WIN, + STATE_LOSE, +} GameState; + +typedef struct { + Rectangle rect; + Color color; + bool alive; + int points; +} Brick; + +typedef struct { + Color background; + Color panel; + Color panelBorder; + Color accent; + Color accentBorder; + Color text; + Color muted; + Color shadow; + + float margin; + float topBarHeight; + float buttonWidth; + float buttonHeight; + float actionWidth; + float actionHeight; + float roundness; +} UITheme; + +static UITheme DefaultUITheme(void) { + return (UITheme){ + .background = {14, 16, 22, 255}, + .panel = {245, 245, 245, 255}, + .panelBorder = {245, 245, 245, 255}, + .accent = {60, 180, 255, 255}, + .accentBorder = {245, 245, 245, 255}, + .text = {20, 20, 24, 255}, + .muted = {160, 170, 190, 255}, + .shadow = {0, 0, 0, 160}, + + .margin = 12.0f, + .topBarHeight = 34.0f, + .buttonWidth = 104.0f, + .buttonHeight = 34.0f, + .actionWidth = 168.0f, + .actionHeight = 36.0f, + .roundness = 0.0f, + }; +} + +static Color BrickColor(int row) { + Color palette[] = { + {255, 80, 80, 255}, {255, 160, 40, 255}, {255, 220, 40, 255}, + {80, 210, 90, 255}, {60, 180, 255, 255}, + }; + return palette[row % 5]; +} + +static bool CollideBallRect(Vector2 *pos, Vector2 *vel, float radius, + Rectangle rect, float dt) { + Rectangle expanded = { + rect.x - radius, + rect.y - radius, + rect.width + radius * 2.0f, + rect.height + radius * 2.0f, + }; + + if (!CheckCollisionPointRec(*pos, expanded)) + return false; + + float nearX = Clamp(pos->x, rect.x, rect.x + rect.width); + float nearY = Clamp(pos->y, rect.y, rect.y + rect.height); + float dx = pos->x - nearX; + float dy = pos->y - nearY; + + if (fabsf(dx) > fabsf(dy)) + vel->x = -vel->x; + else + vel->y = -vel->y; + + pos->x += vel->x * dt; + pos->y += vel->y * dt; + + return true; +} + +static void BuildBricks(Brick bricks[BRICK_ROWS][BRICK_COLS], float sw, + float brickAreaTop, float brickAreaH) { + float brickW = (sw - BRICK_PADDING * (BRICK_COLS + 1)) / BRICK_COLS; + float brickH = (brickAreaH - BRICK_PADDING * (BRICK_ROWS + 1)) / BRICK_ROWS; + + for (int r = 0; r < BRICK_ROWS; r++) { + for (int c = 0; c < BRICK_COLS; c++) { + float bx = BRICK_PADDING + c * (brickW + BRICK_PADDING); + float by = brickAreaTop + BRICK_PADDING + r * (brickH + BRICK_PADDING); + bricks[r][c] = (Brick){ + .rect = {bx, by, brickW, brickH}, + .color = BrickColor(r), + .alive = true, + .points = (BRICK_ROWS - r) * 10, + }; + } + } +} + +int main(void) { + InitWindow(0, 0, "Breakout - raylib iOS"); + SetTargetFPS(60); + + UITheme ui = DefaultUITheme(); + + const char *logoPath = + TextFormat("%sraylib_180x180.png", GetApplicationDirectory()); + Texture2D logo = LoadTexture(logoPath); + + int sw = GetScreenWidth(); + int sh = GetScreenHeight(); + + float paddleW = sw * 0.22f; + float paddleH = sh * 0.022f; + float paddleY = sh - sh * 0.10f; + float ballRadius = sw * 0.022f; + float brickAreaTop = sh * 0.22f; + float brickAreaH = sh * 0.32f; + + GameState state = STATE_TITLE; + int score = 0; + int lives = 3; + int totalBricks = BRICK_ROWS * BRICK_COLS; + int aliveBricks = totalBricks; + + Rectangle paddle = {sw * 0.5f - paddleW * 0.5f, paddleY, paddleW, paddleH}; + Vector2 ball = {sw * 0.5f, paddleY - ballRadius - 2.0f}; + Vector2 ballV = {BALL_SPEED_INIT * 0.6f, -BALL_SPEED_INIT}; + bool ballLaunched = false; + + Brick bricks[BRICK_ROWS][BRICK_COLS]; + BuildBricks(bricks, (float)sw, brickAreaTop, brickAreaH); + +#define RESET_BALL() \ + do { \ + ball = (Vector2){paddle.x + paddle.width * 0.5f, \ + paddleY - ballRadius - 2.0f}; \ + ballV = (Vector2){BALL_SPEED_INIT * 0.6f, -BALL_SPEED_INIT}; \ + ballLaunched = false; \ + } while (0) + + while (!WindowShouldClose()) { + float dt = GetFrameTime(); + if (dt > 0.05f) + dt = 0.05f; + + if (GetScreenWidth() != sw || GetScreenHeight() != sh) { + sw = GetScreenWidth(); + sh = GetScreenHeight(); + + paddleW = sw * 0.22f; + paddleH = sh * 0.022f; + paddleY = sh - sh * 0.10f; + ballRadius = sw * 0.022f; + brickAreaTop = sh * 0.22f; + brickAreaH = sh * 0.32f; + + paddle.width = paddleW; + paddle.height = paddleH; + paddle.y = paddleY; + + BuildBricks(bricks, (float)sw, brickAreaTop, brickAreaH); + } + + Vector2 pointer = + GetTouchPointCount() > 0 ? GetTouchPosition(0) : GetMousePosition(); + + bool tapped = IsMouseButtonPressed(MOUSE_BUTTON_LEFT); + + Rectangle pauseRect = {sw - ui.margin - ui.buttonWidth, ui.margin, + ui.buttonWidth, ui.buttonHeight}; + Rectangle buttonRect = {sw * 0.5f - ui.actionWidth * 0.5f, + sh - ui.margin - ui.actionHeight, ui.actionWidth, + ui.actionHeight}; + Rectangle menuRect = {sw * 0.5f - ui.actionWidth * 0.5f, + sh - ui.margin - ui.actionHeight * 2.0f - 8.0f, + ui.actionWidth, ui.actionHeight}; + Rectangle launchRect = {ui.margin, sh * 0.44f, sw - ui.margin * 2.0f, + sh - sh * 0.44f - ui.margin}; + + bool pausePressed = tapped && CheckCollisionPointRec(pointer, pauseRect) && + (state == STATE_PLAYING || state == STATE_PAUSED); + bool buttonPressed = tapped && CheckCollisionPointRec(pointer, buttonRect); + bool menuPressed = tapped && CheckCollisionPointRec(pointer, menuRect); + bool launchPressed = tapped && CheckCollisionPointRec(pointer, launchRect); + + if (state == STATE_TITLE) { + + if (buttonPressed) + state = STATE_PLAYING; + + } else if (state == STATE_PAUSED) { + + if (pausePressed) + state = STATE_PLAYING; + + } else if (state == STATE_WIN || state == STATE_LOSE) { + + if (buttonPressed) { + score = 0; + lives = 3; + aliveBricks = totalBricks; + paddle.x = sw * 0.5f - paddleW * 0.5f; + BuildBricks(bricks, (float)sw, brickAreaTop, brickAreaH); + RESET_BALL(); + state = STATE_PLAYING; + + } else if (menuPressed) { + score = 0; + lives = 3; + aliveBricks = totalBricks; + paddle.x = sw * 0.5f - paddleW * 0.5f; + BuildBricks(bricks, (float)sw, brickAreaTop, brickAreaH); + RESET_BALL(); + state = STATE_TITLE; + } + + } else { + + paddle.x = Clamp(pointer.x - paddle.width * 0.5f, 0.0f, + (float)sw - paddle.width); + + if (pausePressed) { + state = STATE_PAUSED; + + } else if (launchPressed && !ballLaunched) { + ballLaunched = true; + } + + if (ballLaunched) { + ball.x += ballV.x * dt; + ball.y += ballV.y * dt; + + if (ball.x - ballRadius <= 0.0f) { + ball.x = ballRadius; + ballV.x = fabsf(ballV.x); + } + if (ball.x + ballRadius >= sw) { + ball.x = sw - ballRadius; + ballV.x = -fabsf(ballV.x); + } + if (ball.y - ballRadius <= 0.0f) { + ball.y = ballRadius; + ballV.y = fabsf(ballV.y); + } + + if (ball.y - ballRadius > sh) { + lives--; + if (lives <= 0) + state = STATE_LOSE; + else + RESET_BALL(); + } + + if (CollideBallRect(&ball, &ballV, ballRadius, paddle, dt)) { + float hitPos = (ball.x - paddle.x) / paddle.width; + float angle = (hitPos - 0.5f) * 120.0f * DEG2RAD; + float speed = Vector2Length(ballV); + speed = Clamp(speed + 10.0f, 0.0f, BALL_SPEED_MAX); + ballV.x = sinf(angle) * speed; + ballV.y = -fabsf(cosf(angle) * speed); + } + + for (int r = 0; r < BRICK_ROWS; r++) { + for (int c = 0; c < BRICK_COLS; c++) { + Brick *b = &bricks[r][c]; + if (!b->alive) + continue; + + if (CollideBallRect(&ball, &ballV, ballRadius, b->rect, dt)) { + b->alive = false; + aliveBricks--; + score += b->points; + if (aliveBricks <= 0) + state = STATE_WIN; + goto done_bricks; + } + } + } + done_bricks:; + + } else { + ball.x = paddle.x + paddle.width * 0.5f; + ball.y = paddleY - ballRadius - 2.0f; + } + } + + BeginDrawing(); + ClearBackground(ui.background); + + if (state == STATE_TITLE) { + if (logo.id != 0) { + float targetSize = sh * 0.12f; + float scale = targetSize / (float)logo.width; + DrawTextureEx(logo, (Vector2){sw * 0.5f - targetSize * 0.5f, 8.0f}, + 0.0f, scale, WHITE); + } + + int ts = sw / 10; + int ss = sw / 22; + DrawText("BREAKOUT", sw / 2 - MeasureText("BREAKOUT", ts) / 2, + (int)(sh * 0.18f), ts, (Color){60, 180, 255, 255}); + DrawText("tap the button to start", + sw / 2 - MeasureText("tap the button to start", ss) / 2, + (int)(sh * 0.18f) + ts + 8, ss, (Color){160, 170, 190, 255}); + } + + if (state != STATE_TITLE) { + for (int r = 0; r < BRICK_ROWS; r++) { + for (int c = 0; c < BRICK_COLS; c++) { + Brick *b = &bricks[r][c]; + if (!b->alive) + continue; + + DrawRectangleRounded(b->rect, 0.25f, 6, b->color); + DrawLineEx((Vector2){b->rect.x + 4, b->rect.y + 2}, + (Vector2){b->rect.x + b->rect.width - 4, b->rect.y + 2}, + 1.5f, (Color){255, 255, 255, 60}); + } + } + + DrawRectangleRounded(paddle, 0.5f, 8, (Color){60, 180, 255, 255}); + DrawCircleV(ball, ballRadius, WHITE); + DrawCircleLines((int)ball.x, (int)ball.y, ballRadius + 2, + (Color){255, 255, 255, 60}); + + int hs = sw / 24; + DrawText(TextFormat("Score: %d", score), 14, 14, hs, + (Color){200, 210, 225, 255}); + DrawText(TextFormat("Lives: %d", lives), 14, 14 + hs + 8, hs, + (Color){255, 80, 80, 255}); + + if (!ballLaunched && state == STATE_PLAYING) { + const char *hint = "tap anywhere to launch"; + int hintSize = sw / 26; + DrawText(hint, sw / 2 - MeasureText(hint, hintSize) / 2, + (int)(sh * 0.72f), hintSize, ui.muted); + } + + if (state == STATE_PAUSED) { + DrawRectangle(0, 0, sw, sh, (Color){0, 0, 0, 150}); + + int ts = sw / 10; + int ss = sw / 22; + DrawText("PAUSED", sw / 2 - MeasureText("PAUSED", ts) / 2, sh / 2 - ts, + ts, RAYWHITE); + DrawText("tap resume to continue", + sw / 2 - MeasureText("tap resume to continue", ss) / 2, + sh / 2 + ts, ss, (Color){160, 170, 190, 180}); + } + + if (state == STATE_WIN || state == STATE_LOSE) { + DrawRectangle(0, 0, sw, sh, (Color){0, 0, 0, 160}); + + const char *title = state == STATE_WIN ? "YOU WIN!" : "GAME OVER"; + Color tcol = state == STATE_WIN ? (Color){80, 220, 100, 255} + : (Color){255, 80, 80, 255}; + int ts = sw / 9; + int ss = sw / 22; + + DrawText(title, sw / 2 - MeasureText(title, ts) / 2, sh / 2 - ts, ts, + tcol); + DrawText(TextFormat("Score: %d", score), + sw / 2 - MeasureText(TextFormat("Score: %d", score), ss) / 2, + sh / 2 + ts / 4, ss, (Color){200, 210, 225, 255}); + + const char *msg = state == STATE_WIN ? "tap retry to play again" + : "tap retry to try again"; + DrawText(msg, sw / 2 - MeasureText(msg, ss) / 2, sh / 2 + ts, ss, + (Color){160, 170, 190, 200}); + } + } + + if (state == STATE_PLAYING || state == STATE_PAUSED) { + const char *pauseText = state == STATE_PAUSED ? "RESUME" : "PAUSE"; + DrawRectangleRounded(pauseRect, ui.roundness, 8, ui.panel); + DrawText(pauseText, + (int)(pauseRect.x + pauseRect.width * 0.5f - + (float)MeasureText(pauseText, 16) * 0.5f), + (int)(pauseRect.y + 8), 16, ui.text); + } + + bool drawActionButton = + (state == STATE_TITLE) || (state == STATE_WIN || state == STATE_LOSE); + if (drawActionButton) { + const char *buttonText = + (state == STATE_WIN || state == STATE_LOSE) ? "RETRY" : "START"; + Rectangle actionButton = {sw * 0.5f - ui.actionWidth * 0.5f, + sh - ui.margin - ui.actionHeight, + ui.actionWidth, ui.actionHeight}; + DrawRectangleRounded(actionButton, ui.roundness, 8, ui.panel); + DrawText(buttonText, + (int)(actionButton.x + actionButton.width * 0.5f - + (float)MeasureText(buttonText, 18) * 0.5f), + (int)(actionButton.y + 8), 18, ui.text); + } + + if (state == STATE_WIN || state == STATE_LOSE) { + const char *menuText = "MAIN MENU"; + DrawRectangleRounded(menuRect, ui.roundness, 8, ui.panel); + DrawText(menuText, + (int)(menuRect.x + menuRect.width * 0.5f - + (float)MeasureText(menuText, 18) * 0.5f), + (int)(menuRect.y + 8), 18, ui.text); + } + + EndDrawing(); + } + + UnloadTexture(logo); + CloseWindow(); + return 0; +} \ No newline at end of file From 6af06cabe193f96b22cb3c5bf9e28efbfd20715f Mon Sep 17 00:00:00 2001 From: vsaint1 Date: Sat, 23 May 2026 06:22:48 -0300 Subject: [PATCH 09/18] feat: platform iOS bridge layer --- src/rcore_ios_main.m | 472 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 472 insertions(+) create mode 100644 src/rcore_ios_main.m diff --git a/src/rcore_ios_main.m b/src/rcore_ios_main.m new file mode 100644 index 000000000000..51624badfd9a --- /dev/null +++ b/src/rcore_ios_main.m @@ -0,0 +1,472 @@ +#import +#import +#import +#import +#import + +#include +#include +#include +#include + +extern int raylib_main(int argc, char *argv[]); + +extern void ios_handle_touch_began(intptr_t touchId, float x, float y); +extern void ios_handle_touch_moved(intptr_t touchId, float x, float y); +extern void ios_handle_touch_ended(intptr_t touchId, float x, float y); +extern void ios_handle_touch_cancelled(intptr_t touchId, float x, float y); +extern void ios_request_close(void); +extern void ios_set_window_focused(bool focused); + +typedef struct IOSBridgeState { + int argc; + char **argv; + UIWindow *window; + UIViewController *viewController; + UIView *glView; + EAGLContext *context; + GLuint framebuffer; + GLuint colorBuffer; + GLuint depthBuffer; + int screenWidth; + int screenHeight; + int renderWidth; + int renderHeight; + float scaleX; + float scaleY; + bool raylibStarted; + bool shuttingDown; + bool initialized; +} IOSBridgeState; + +static IOSBridgeState ios = {0}; + +@interface RaylibGLView : UIView +@end + +@implementation RaylibGLView + ++ (Class)layerClass { + return [CAEAGLLayer class]; +} + +@end + +@interface RaylibViewController : UIViewController +@end + +@implementation RaylibViewController + +- (BOOL)prefersStatusBarHidden { + return YES; +} + +- (void)loadView { + self.view = [[RaylibGLView alloc] initWithFrame:[UIScreen mainScreen].bounds]; + self.view.multipleTouchEnabled = YES; +} + +- (void)viewDidAppear:(BOOL)animated { + [super viewDidAppear:animated]; + ios_set_window_focused(true); +} + +- (void)viewWillDisappear:(BOOL)animated { + [super viewWillDisappear:animated]; + ios_set_window_focused(false); +} +- (void)forwardTouches:(NSSet *)touches action:(int)action { + for (UITouch *touch in touches) { + CGPoint point = [touch locationInView:self.view]; + intptr_t touchId = (intptr_t)(__bridge void *)touch; + + switch (action) { + case 0: + ios_handle_touch_began(touchId, point.x, point.y); + break; + case 1: + ios_handle_touch_moved(touchId, point.x, point.y); + break; + case 2: + ios_handle_touch_ended(touchId, point.x, point.y); + break; + case 3: + ios_handle_touch_cancelled(touchId, point.x, point.y); + break; + default: + break; + } + } +} + +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { + (void)event; + [self forwardTouches:touches action:0]; +} + +- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { + (void)event; + [self forwardTouches:touches action:1]; +} + +- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { + (void)event; + [self forwardTouches:touches action:2]; +} + +- (void)touchesCancelled:(NSSet *)touches + withEvent:(UIEvent *)event { + (void)event; + [self forwardTouches:touches action:3]; +} + +@end + +void ios_shutdown_window(void) { + if (!ios.initialized || ios.shuttingDown) + return; + ios.shuttingDown = true; + + void (^shutdownBlock)(void) = ^{ + if (ios.context != nil) { + [EAGLContext setCurrentContext:ios.context]; + + if (ios.framebuffer != 0) + glDeleteFramebuffers(1, &ios.framebuffer); + if (ios.colorBuffer != 0) + glDeleteRenderbuffers(1, &ios.colorBuffer); + if (ios.depthBuffer != 0) + glDeleteRenderbuffers(1, &ios.depthBuffer); + + ios.framebuffer = 0; + ios.colorBuffer = 0; + ios.depthBuffer = 0; + ios.context = nil; + } + + ios.glView = nil; + ios.viewController = nil; + ios.window = nil; + ios.initialized = false; + }; + + if ([NSThread isMainThread]) + shutdownBlock(); + else + dispatch_sync(dispatch_get_main_queue(), shutdownBlock); + + ios.shuttingDown = false; +} + +@interface RaylibAppDelegate : UIResponder +@end + +@interface RaylibSceneDelegate : UIResponder + +@property(strong, nonatomic) UIWindow *window; + +@end + +static void ios_start_raylib_main(void) { + if (ios.raylibStarted) + return; + ios.raylibStarted = true; + + dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{ + raylib_main(ios.argc, ios.argv); + }); +} + +@implementation RaylibAppDelegate + +- (BOOL)application:(UIApplication *)application + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + (void)application; + (void)launchOptions; + + return YES; +} + +- (UISceneConfiguration *)application:(UIApplication *)application + configurationForConnectingSceneSession: + (UISceneSession *)connectingSceneSession + options:(UISceneConnectionOptions *)options { + (void)application; + (void)connectingSceneSession; + (void)options; + + UISceneConfiguration *configuration = [UISceneConfiguration + configurationWithName:@"Default Configuration" + sessionRole:UIWindowSceneSessionRoleApplication]; + configuration.delegateClass = [RaylibSceneDelegate class]; + return configuration; +} + +- (void)applicationWillResignActive:(UIApplication *)application { + (void)application; + ios_set_window_focused(false); +} + +- (void)applicationDidBecomeActive:(UIApplication *)application { + (void)application; + ios_set_window_focused(true); +} + +- (void)applicationWillTerminate:(UIApplication *)application { + (void)application; + ios_request_close(); +} + +@end + +@implementation RaylibSceneDelegate + +- (void)scene:(UIScene *)scene + willConnectToSession:(UISceneSession *)session + options:(UISceneConnectionOptions *)connectionOptions { + (void)session; + (void)connectionOptions; + + if (![scene isKindOfClass:[UIWindowScene class]]) + return; + + UIWindowScene *windowScene = (UIWindowScene *)scene; + self.window = [[UIWindow alloc] initWithWindowScene:windowScene]; + ios.window = self.window; + + if (ios.viewController == nil) { + ios.viewController = [[RaylibViewController alloc] init]; + } + self.window.rootViewController = ios.viewController; + [self.window makeKeyAndVisible]; + + ios_start_raylib_main(); +} + +- (void)sceneDidBecomeActive:(UIScene *)scene { + (void)scene; + ios_set_window_focused(true); +} + +- (void)sceneWillResignActive:(UIScene *)scene { + (void)scene; + ios_set_window_focused(false); +} + +- (void)sceneDidDisconnect:(UIScene *)scene { + (void)scene; + ios_request_close(); + ios_shutdown_window(); +} + +@end + +static BOOL ios_setup_gl(void) { + if (!ios.window || !ios.viewController) + return NO; + + ios.glView = ios.viewController.view; + CAEAGLLayer *eaglLayer = (CAEAGLLayer *)ios.glView.layer; + eaglLayer.opaque = YES; + eaglLayer.drawableProperties = @{ + kEAGLDrawablePropertyRetainedBacking : @NO, + kEAGLDrawablePropertyColorFormat : kEAGLColorFormatRGBA8 + }; + + // Ensure layer uses native scale for proper retina resolution + CGFloat nativeScale = [UIScreen mainScreen].nativeScale; + eaglLayer.contentsScale = nativeScale; + ios.glView.contentScaleFactor = nativeScale; + + ios.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; + if (!ios.context) { + ios.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; + } + + if (!ios.context) + return NO; + + [EAGLContext setCurrentContext:ios.context]; + + glGenFramebuffers(1, &ios.framebuffer); + glGenRenderbuffers(1, &ios.colorBuffer); + glGenRenderbuffers(1, &ios.depthBuffer); + + glBindFramebuffer(GL_FRAMEBUFFER, ios.framebuffer); + + glBindRenderbuffer(GL_RENDERBUFFER, ios.colorBuffer); + if (![ios.context renderbufferStorage:GL_RENDERBUFFER + fromDrawable:eaglLayer]) { + return NO; + } + + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + GL_RENDERBUFFER, ios.colorBuffer); + + glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, + &ios.renderWidth); + glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, + &ios.renderHeight); + + glBindRenderbuffer(GL_RENDERBUFFER, ios.depthBuffer); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, ios.renderWidth, + ios.renderHeight); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, + GL_RENDERBUFFER, ios.depthBuffer); + + BOOL fbComplete = + (glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE); + + GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (fbStatus != GL_FRAMEBUFFER_COMPLETE) { + NSLog(@"[raylib][IOS] Framebuffer incomplete: 0x%04X", fbStatus); + } else { + NSLog(@"[raylib][IOS] Framebuffer complete (%d x %d)", ios.renderWidth, + ios.renderHeight); + } + + [EAGLContext setCurrentContext:nil]; + + return fbComplete; +} + +bool ios_initialize_window(int requestedWidth, int requestedHeight, + int *screenWidth, int *screenHeight, + int *renderWidth, int *renderHeight, float *scaleX, + float *scaleY) { + (void)requestedWidth; + (void)requestedHeight; + + __block bool ok = false; + dispatch_sync(dispatch_get_main_queue(), ^{ + if (ios.window == nil) { + ios.window = + [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; + } + + if (ios.viewController == nil) { + ios.viewController = [[RaylibViewController alloc] init]; + } + + ios.window.rootViewController = ios.viewController; + [ios.window makeKeyAndVisible]; + + ok = ios_setup_gl(); + + UIScreen *screen = [UIScreen mainScreen]; + CGSize boundsSize = screen.bounds.size; + ios.screenWidth = (int)boundsSize.width; + ios.screenHeight = (int)boundsSize.height; + ios.scaleX = (float)screen.nativeScale; + ios.scaleY = (float)screen.nativeScale; + + if (screenWidth) + *screenWidth = ios.screenWidth; + + if (screenHeight) + *screenHeight = ios.screenHeight; + + if (renderWidth) + *renderWidth = ios.renderWidth; + + if (renderHeight) + *renderHeight = ios.renderHeight; + + if (scaleX) + *scaleX = ios.scaleX; + + if (scaleY) + *scaleY = ios.scaleY; + }); + + ios.initialized = ok; + return ok; +} + +void ios_make_current_context(void) { + if (ios.context != nil) + [EAGLContext setCurrentContext:ios.context]; + + if (ios.framebuffer != 0) + glBindFramebuffer(GL_FRAMEBUFFER, ios.framebuffer); + if (ios.colorBuffer != 0) + glBindRenderbuffer(GL_RENDERBUFFER, ios.colorBuffer); + + glViewport(0, 0, ios.renderWidth, ios.renderHeight); + // NSLog(@"[raylib][IOS] IOSMakeCurrentContext: thread=%@, fb=%u, rb=%u, " + // @"viewport=%dx%d", + // [NSThread currentThread], ios.framebuffer, ios.colorBuffer, + // ios.renderWidth, ios.renderHeight); +} + +void ios_present_frame(void) { + if (ios.context == nil || ios.shuttingDown) + return; + + if ([EAGLContext currentContext] != ios.context) { + [EAGLContext setCurrentContext:ios.context]; + } + + // NSLog(@"[raylib][IOS] IOSPresentFrame: thread=%@, currentContext=%@", + // [NSThread currentThread], [EAGLContext currentContext]); + + GLenum err = glGetError(); + if (err != GL_NO_ERROR) + NSLog(@"[raylib][IOS] glGetError before present: 0x%04X", err); + + [ios.context presentRenderbuffer:GL_RENDERBUFFER]; + + err = glGetError(); + if (err != GL_NO_ERROR) + NSLog(@"[raylib][IOS] glGetError after present: 0x%04X", err); +} + +void *ios_get_window_handle(void) { return (__bridge void *)ios.window; } + +void ios_get_window_metrics(int *screenWidth, int *screenHeight, + int *renderWidth, int *renderHeight, float *scaleX, + float *scaleY) { + if (screenWidth) + *screenWidth = ios.screenWidth; + + if (screenHeight) + *screenHeight = ios.screenHeight; + + if (renderWidth) + *renderWidth = ios.renderWidth; + + if (renderHeight) + *renderHeight = ios.renderHeight; + + if (scaleX) + *scaleX = ios.scaleX; + + if (scaleY) + *scaleY = ios.scaleY; +} + +void *ios_get_proc_address(const char *name) { + return dlsym(RTLD_DEFAULT, name); +} + +void ios_open_url(const char *url) { + NSString *nsurlString = [NSString stringWithUTF8String:url]; + NSURL *nsurl = [NSURL URLWithString:nsurlString]; + if (nsurl != nil) { + dispatch_async(dispatch_get_main_queue(), ^{ + [[UIApplication sharedApplication] openURL:nsurl + options:@{} + completionHandler:nil]; + }); + } +} + +int main(int argc, char *argv[]) { + ios.argc = argc; + ios.argv = argv; + + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, + NSStringFromClass([RaylibAppDelegate class])); + } +} \ No newline at end of file From 128eddee58d4feb52032ed64a9564101784094dc Mon Sep 17 00:00:00 2001 From: vsaint1 Date: Sat, 23 May 2026 06:23:40 -0300 Subject: [PATCH 10/18] feat: platform iOS implementation --- src/platforms/rcore_ios.c | 553 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 553 insertions(+) create mode 100644 src/platforms/rcore_ios.c diff --git a/src/platforms/rcore_ios.c b/src/platforms/rcore_ios.c new file mode 100644 index 000000000000..ffb03cf865c0 --- /dev/null +++ b/src/platforms/rcore_ios.c @@ -0,0 +1,553 @@ +/********************************************************************************************** +* +* rcore_ios - Functions to manage window, graphics device and inputs +* +* PLATFORM: IOS +* - iOS (arm64) +* - iOS Simulator +* +* LIMITATIONS: +* - No keyboard input support +* - No gamepad input support +* +* DEPENDENCIES: +* - UIKit/QuartzCore/OpenGLES (provided by iOS SDK) +* - raylib_ios_main.m provides the native window and GL bridge +* +* LICENSE: zlib/libpng +* +* Copyright (c) 2013-2026 Ramon Santamaria (@raysan5) and contributors +* +**********************************************************************************************/ + +#include +#include +#include +#include +#include + +#if defined(__APPLE__) + #include +#endif + +// UIKit/OpenGL bridge functions implemented in rcore_ios_main.m +RLAPI bool ios_initialize_window(int requestedWidth, int requestedHeight, int *screenWidth, int *screenHeight, int *renderWidth, int *renderHeight, float *scaleX, float *scaleY); +RLAPI void ios_make_current_context(void); +RLAPI void ios_shutdown_window(void); +RLAPI void ios_present_frame(void); +RLAPI void *ios_get_window_handle(void); +RLAPI void ios_get_window_metrics(int *screenWidth, int *screenHeight, int *renderWidth, int *renderHeight, float *scaleX, float *scaleY); +RLAPI void *ios_get_proc_address(const char *name); +RLAPI void ios_open_url(const char *url); + +//---------------------------------------------------------------------------------- +// Types and Structures Definition +//---------------------------------------------------------------------------------- +typedef struct { + bool initialized; +} PlatformData; + +typedef struct { + int32_t pointCount; // Number of active touch points + int32_t pointId[MAX_TOUCH_POINTS]; // Touch point ids + Vector2 position[MAX_TOUCH_POINTS]; // Touch point positions + int32_t hoverPoints[MAX_TOUCH_POINTS]; // Hover point slots +} TouchRaw; + +//---------------------------------------------------------------------------------- +// Global Variables Definition +//---------------------------------------------------------------------------------- +extern CoreData CORE; // Global CORE state context + +static PlatformData platform = { 0 }; // Platform specific data +static TouchRaw touchRaw = { 0 }; // Raw touch state + +//---------------------------------------------------------------------------------- +// Module Internal Functions Declaration +//---------------------------------------------------------------------------------- +int InitPlatform(void); // Initialize platform (graphics, inputs and more) +bool InitGraphicsDevice(void); // Initialize graphics device + +static int FindTouchSlot(intptr_t touchId, bool allowAllocate); +static void UpdateMouseFromTouches(void); + +//---------------------------------------------------------------------------------- +// Module Functions Definition: Window and Graphics Device +//---------------------------------------------------------------------------------- + +// Check if application should close +bool WindowShouldClose(void) +{ + if (CORE.Window.ready) return CORE.Window.shouldClose; + else return true; +} + +// Toggle fullscreen mode +void ToggleFullscreen(void) +{ + TRACELOG(LOG_WARNING, "ToggleFullscreen() not available on target platform"); +} + +// Toggle borderless windowed mode +void ToggleBorderlessWindowed(void) +{ + TRACELOG(LOG_WARNING, "ToggleBorderlessWindowed() not available on target platform"); +} + +// Set window state: maximized, if resizable +void MaximizeWindow(void) +{ + TRACELOG(LOG_WARNING, "MaximizeWindow() not available on target platform"); +} + +// Set window state: minimized +void MinimizeWindow(void) +{ + TRACELOG(LOG_WARNING, "MinimizeWindow() not available on target platform"); +} + +// Restore window from being minimized/maximized +void RestoreWindow(void) +{ + TRACELOG(LOG_WARNING, "RestoreWindow() not available on target platform"); +} + +// Set window configuration state using flags +void SetWindowState(unsigned int flags) +{ + TRACELOG(LOG_WARNING, "SetWindowState() not available on target platform"); +} + +// Clear window configuration state flags +void ClearWindowState(unsigned int flags) +{ + TRACELOG(LOG_WARNING, "ClearWindowState() not available on target platform"); +} + +// Set icon for window +void SetWindowIcon(Image image) +{ + TRACELOG(LOG_WARNING, "SetWindowIcon() not available on target platform"); +} + +// Set icons for window +void SetWindowIcons(Image *images, int count) +{ + TRACELOG(LOG_WARNING, "SetWindowIcons() not available on target platform"); +} + +// Set title for window +void SetWindowTitle(const char *title) +{ + CORE.Window.title = title; +} + +// Set window position on screen (windowed mode) +void SetWindowPosition(int x, int y) +{ + TRACELOG(LOG_WARNING, "SetWindowPosition() not available on target platform"); +} + +// Set monitor for the current window +void SetWindowMonitor(int monitor) +{ + TRACELOG(LOG_WARNING, "SetWindowMonitor() not available on target platform"); +} + +// Set window minimum dimensions (FLAG_WINDOW_RESIZABLE) +void SetWindowMinSize(int width, int height) +{ + CORE.Window.screenMin.width = width; + CORE.Window.screenMin.height = height; +} + +// Set window maximum dimensions (FLAG_WINDOW_RESIZABLE) +void SetWindowMaxSize(int width, int height) +{ + CORE.Window.screenMax.width = width; + CORE.Window.screenMax.height = height; +} + +// Set window dimensions +void SetWindowSize(int width, int height) +{ + TRACELOG(LOG_WARNING, "SetWindowSize() not available on target platform"); +} + +// Set window opacity [0.0f..1.0f] +void SetWindowOpacity(float opacity) +{ + TRACELOG(LOG_WARNING, "SetWindowOpacity() not available on target platform"); +} + +// Set window focused +void SetWindowFocused(void) +{ + TRACELOG(LOG_WARNING, "SetWindowFocused() not available on target platform"); +} + +// Get native window handle +void *GetWindowHandle(void) +{ + return ios_get_window_handle(); +} + +// Get number of monitors +int GetMonitorCount(void) { return 1; } + +// Get current monitor where window is placed +int GetCurrentMonitor(void) { return 0; } + +// Get selected monitor position +Vector2 GetMonitorPosition(int monitor) { return (Vector2){ 0, 0 }; } + +// Get selected monitor width (currently used by monitor) +int GetMonitorWidth(int monitor) { return CORE.Window.screen.width; } + +// Get selected monitor height (currently used by monitor) +int GetMonitorHeight(int monitor) { return CORE.Window.screen.height; } + +// Get selected monitor physical width in millimetres +int GetMonitorPhysicalWidth(int monitor) { return 0; } + +// Get selected monitor physical height in millimetres +int GetMonitorPhysicalHeight(int monitor) { return 0; } + +// Get selected monitor refresh rate +int GetMonitorRefreshRate(int monitor) { return 0; } + +// Get the human-readable, UTF-8 encoded name of the selected monitor +const char *GetMonitorName(int monitor) { return ""; } + +// Get window position XY on monitor +Vector2 GetWindowPosition(void) { return (Vector2){ 0, 0 }; } + +// Get window scale DPI factor for current monitor +Vector2 GetWindowScaleDPI(void) +{ + int screenWidth = 0, screenHeight = 0; + int renderWidth = 0, renderHeight = 0; + float scaleX = 1.0f, scaleY = 1.0f; + + ios_get_window_metrics(&screenWidth, &screenHeight, &renderWidth, &renderHeight, &scaleX, &scaleY); + (void)screenWidth; (void)screenHeight; + (void)renderWidth; (void)renderHeight; + + return (Vector2){ scaleX, scaleY }; +} + +// Set clipboard text content +void SetClipboardText(const char *text) +{ + TRACELOG(LOG_WARNING, "SetClipboardText() not implemented on target platform"); +} + +// Get clipboard text content +const char *GetClipboardText(void) +{ + TRACELOG(LOG_WARNING, "GetClipboardText() not implemented on target platform"); + return NULL; +} + +// Get clipboard image +Image GetClipboardImage(void) +{ + Image image = { 0 }; + TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform"); + return image; +} + +// Show mouse cursor +void ShowCursor(void) { CORE.Input.Mouse.cursorHidden = false; } + +// Hide mouse cursor +void HideCursor(void) { CORE.Input.Mouse.cursorHidden = true; } + +// Enable cursor (unlock cursor) +void EnableCursor(void) +{ + SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); + CORE.Input.Mouse.cursorHidden = false; +} + +// Disable cursor (lock cursor) +void DisableCursor(void) +{ + SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); + CORE.Input.Mouse.cursorHidden = true; +} + +// Swap back buffer with front buffer (screen drawing) +void SwapScreenBuffer(void) +{ + ios_present_frame(); +} + +//---------------------------------------------------------------------------------- +// Module Functions Definition: Misc +//---------------------------------------------------------------------------------- + +// Get elapsed time measure in seconds since InitTimer() +double GetTime(void) +{ + struct timespec ts = { 0 }; + clock_gettime(CLOCK_MONOTONIC, &ts); + unsigned long long int nanoSeconds = (unsigned long long int)ts.tv_sec*1000000000LLU + (unsigned long long int)ts.tv_nsec; + + return (double)(nanoSeconds - CORE.Time.base)*1e-9; // Elapsed time since InitTimer() +} + +// Open URL with default system browser (if available) +// NOTE: This function is only safe to use if you control the URL given. +// A user could craft a malicious string performing another action. +// Only call this function yourself not with user input or make sure to check +// the string yourself. Ref: https://github.com/raysan5/raylib/issues/686 +void OpenURL(const char *url) +{ + // Security check to (partially) avoid malicious code + if (strchr(url, '\'') != NULL) TRACELOG(LOG_WARNING, "SYSTEM: Provided URL could be potentially malicious, avoid [\'] character"); + else ios_open_url(url); +} + +//---------------------------------------------------------------------------------- +// Module Functions Definition: Inputs +//---------------------------------------------------------------------------------- + +// Set internal gamepad mappings +int SetGamepadMappings(const char *mappings) +{ + TRACELOG(LOG_WARNING, "SetGamepadMappings() not implemented on target platform"); + return 0; +} + +// Set gamepad vibration +void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor, float duration) +{ + TRACELOG(LOG_WARNING, "SetGamepadVibration() not implemented on target platform"); +} + +// Set mouse position XY +void SetMousePosition(int x, int y) +{ + CORE.Input.Mouse.currentPosition = (Vector2){ (float)x, (float)y }; + CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition; +} + +// Set mouse cursor +void SetMouseCursor(int cursor) +{ + TRACELOG(LOG_WARNING, "SetMouseCursor() not implemented on target platform"); +} + +// Get physical key name +const char *GetKeyName(int key) +{ + TRACELOG(LOG_WARNING, "GetKeyName() not implemented on target platform"); + return ""; +} + +// Register all input events +void PollInputEvents(void) +{ +#if defined(SUPPORT_GESTURES_SYSTEM) + // NOTE: Gestures update must be called every frame to reset gestures correctly + // because ProcessGestureEvent() is called on an event, not every frame + UpdateGestures(); +#endif + + // Reset keys/chars pressed registered + CORE.Input.Keyboard.keyPressedQueueCount = 0; + CORE.Input.Keyboard.charPressedQueueCount = 0; + + // Reset key repeats + for (int i = 0; i < MAX_KEYBOARD_KEYS; i++) CORE.Input.Keyboard.keyRepeatInFrame[i] = 0; + + // Reset last gamepad button/axis registered state + CORE.Input.Gamepad.lastButtonPressed = 0; // GAMEPAD_BUTTON_UNKNOWN + + // Register previous touch states + for (int i = 0; i < MAX_TOUCH_POINTS; i++) + CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.currentTouchState[i]; + + // Register previous keys states + for (int i = 0; i < MAX_KEYBOARD_KEYS; i++) + { + CORE.Input.Keyboard.previousKeyState[i] = CORE.Input.Keyboard.currentKeyState[i]; + CORE.Input.Keyboard.keyRepeatInFrame[i] = 0; + } + + UpdateMouseFromTouches(); +} + +//---------------------------------------------------------------------------------- +// Module Internal Functions Definition +//---------------------------------------------------------------------------------- + +// Initialize platform: graphics, inputs and more +int InitPlatform(void) +{ + FLAG_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE); + + if (FLAG_IS_SET(CORE.Window.flags, FLAG_MSAA_4X_HINT)) TRACELOG(LOG_INFO, "DISPLAY: Trying to enable MSAA x4"); + + int screenWidth = 0, screenHeight = 0; + int renderWidth = 0, renderHeight = 0; + float scaleX = 1.0f, scaleY = 1.0f; + + if (!ios_initialize_window(CORE.Window.screen.width, CORE.Window.screen.height, + &screenWidth, &screenHeight, &renderWidth, &renderHeight, &scaleX, &scaleY)) + { + TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize iOS window and graphics context"); + return -1; + } + + ios_make_current_context(); + + CORE.Window.screen.width = screenWidth; + CORE.Window.screen.height = screenHeight; + CORE.Window.display.width = (int)((float)screenWidth*scaleX); + CORE.Window.display.height = (int)((float)screenHeight*scaleY); + CORE.Window.render.width = renderWidth; + CORE.Window.render.height = renderHeight; + CORE.Window.currentFbo.width = CORE.Window.render.width; + CORE.Window.currentFbo.height = CORE.Window.render.height; + CORE.Window.screenScale = MatrixScale(scaleX, scaleY, 1.0f); + + rlLoadExtensions(ios_get_proc_address); + + for (int i = 0; i < MAX_TOUCH_POINTS; i++) touchRaw.hoverPoints[i] = -1; + + platform.initialized = true; + CORE.Window.ready = true; + + InitTimer(); + CORE.Storage.basePath = GetWorkingDirectory(); + + TRACELOG(LOG_INFO, "PLATFORM: IOS: Initialized successfully"); + TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height); + TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height); + + return 0; +} + +// Close platform +void ClosePlatform(void) +{ + platform = (PlatformData){ 0 }; + touchRaw = (TouchRaw){ 0 }; + ios_shutdown_window(); +} + +// Find or allocate a touch slot for the given touchId +static int FindTouchSlot(intptr_t touchId, bool allowAllocate) +{ + for (int i = 0; i < touchRaw.pointCount; i++) + { + if (touchRaw.pointId[i] == (int32_t)touchId) return i; + } + + if (!allowAllocate) return -1; + if (touchRaw.pointCount < MAX_TOUCH_POINTS) return touchRaw.pointCount; + + return -1; +} + +// Sync mouse position/state from primary touch point +static void UpdateMouseFromTouches(void) +{ + if (touchRaw.pointCount > 0) + { + CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition; + CORE.Input.Mouse.currentPosition = touchRaw.position[0]; + CORE.Input.Mouse.currentWheelMove = (Vector2){ 0.0f, 0.0f }; + } +} + +//---------------------------------------------------------------------------------- +// iOS Bridge Callbacks (called from rcore_ios_main.m) +//---------------------------------------------------------------------------------- + +void ios_handle_touch_began(intptr_t touchId, float x, float y) +{ + int index = FindTouchSlot(touchId, true); + if (index < 0) return; + + touchRaw.pointId[index] = (int32_t)touchId; + touchRaw.position[index] = (Vector2){ x, y }; + + CORE.Input.Touch.pointId[index] = (int)touchId; + CORE.Input.Touch.position[index] = (Vector2){ x, y }; + CORE.Input.Touch.currentTouchState[index] = 1; + CORE.Input.Touch.previousTouchState[index] = 0; + + CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_LEFT] = 1; + CORE.Input.Mouse.previousButtonState[MOUSE_BUTTON_LEFT] = 0; + + if (touchRaw.pointCount < MAX_TOUCH_POINTS) touchRaw.pointCount++; + CORE.Input.Touch.pointCount = touchRaw.pointCount; + + UpdateMouseFromTouches(); +} + +void ios_handle_touch_moved(intptr_t touchId, float x, float y) +{ + int index = FindTouchSlot(touchId, false); + if (index < 0) return; + + touchRaw.position[index] = (Vector2){ x, y }; + CORE.Input.Touch.pointId[index] = (int)touchId; + CORE.Input.Touch.position[index] = (Vector2){ x, y }; + CORE.Input.Touch.currentTouchState[index] = 1; + CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_LEFT] = 1; + CORE.Input.Touch.pointCount = touchRaw.pointCount; + + UpdateMouseFromTouches(); +} + +void ios_handle_touch_ended(intptr_t touchId, float x, float y) +{ + int index = FindTouchSlot(touchId, false); + if (index < 0) return; + + touchRaw.position[index] = (Vector2){ x, y }; + CORE.Input.Touch.position[index] = (Vector2){ x, y }; + CORE.Input.Touch.currentTouchState[index] = 0; + CORE.Input.Touch.previousTouchState[index] = 1; + CORE.Input.Touch.pointId[index] = 0; + + // Compact the touch arrays — shift remaining points down + for (int i = index; i < touchRaw.pointCount - 1; i++) + { + touchRaw.pointId[i] = touchRaw.pointId[i + 1]; + touchRaw.position[i] = touchRaw.position[i + 1]; + + CORE.Input.Touch.pointId[i] = CORE.Input.Touch.pointId[i + 1]; + CORE.Input.Touch.position[i] = CORE.Input.Touch.position[i + 1]; + CORE.Input.Touch.currentTouchState[i] = CORE.Input.Touch.currentTouchState[i + 1]; + CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.previousTouchState[i + 1]; + } + + if (touchRaw.pointCount > 0) touchRaw.pointCount--; + CORE.Input.Touch.pointCount = touchRaw.pointCount; + + CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_LEFT] = (touchRaw.pointCount > 0)? 1 : 0; + CORE.Input.Mouse.previousButtonState[MOUSE_BUTTON_LEFT] = 1; + + UpdateMouseFromTouches(); +} + +void ios_handle_touch_cancelled(intptr_t touchId, float x, float y) +{ + ios_handle_touch_ended(touchId, x, y); +} + +void ios_request_close(void) +{ + CORE.Window.shouldClose = true; +} + +void ios_set_window_focused(bool focused) +{ + if (focused) FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED); + else FLAG_SET(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED); +} \ No newline at end of file From eba14aadbcacdb00b6be86aeaf18a624eb4b63b8 Mon Sep 17 00:00:00 2001 From: vsaint1 Date: Wed, 27 May 2026 02:34:49 -0300 Subject: [PATCH 11/18] renamed: ios shutdown -> close --- src/platforms/rcore_ios.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/platforms/rcore_ios.c b/src/platforms/rcore_ios.c index ffb03cf865c0..6623a1ab91b4 100644 --- a/src/platforms/rcore_ios.c +++ b/src/platforms/rcore_ios.c @@ -33,7 +33,7 @@ // UIKit/OpenGL bridge functions implemented in rcore_ios_main.m RLAPI bool ios_initialize_window(int requestedWidth, int requestedHeight, int *screenWidth, int *screenHeight, int *renderWidth, int *renderHeight, float *scaleX, float *scaleY); RLAPI void ios_make_current_context(void); -RLAPI void ios_shutdown_window(void); +RLAPI void ios_close_platform(void); RLAPI void ios_present_frame(void); RLAPI void *ios_get_window_handle(void); RLAPI void ios_get_window_metrics(int *screenWidth, int *screenHeight, int *renderWidth, int *renderHeight, float *scaleX, float *scaleY); @@ -433,9 +433,11 @@ int InitPlatform(void) // Close platform void ClosePlatform(void) { + ios_close_platform(); + + CORE = (CoreData){ 0 }; platform = (PlatformData){ 0 }; touchRaw = (TouchRaw){ 0 }; - ios_shutdown_window(); } // Find or allocate a touch slot for the given touchId From 202a35833eb83de60ecb9c297555560f139d48a9 Mon Sep 17 00:00:00 2001 From: vsaint1 Date: Wed, 27 May 2026 02:48:14 -0300 Subject: [PATCH 12/18] feat: add iOS threading and vsync handling --- src/rcore_ios_main.m | 148 ++++++++++++++++++++++++++++++++----------- 1 file changed, 111 insertions(+), 37 deletions(-) diff --git a/src/rcore_ios_main.m b/src/rcore_ios_main.m index 51624badfd9a..ffb188cb42bc 100644 --- a/src/rcore_ios_main.m +++ b/src/rcore_ios_main.m @@ -1,6 +1,8 @@ #import #import #import +#import +#include #import #import @@ -41,6 +43,11 @@ static IOSBridgeState ios = {0}; +static dispatch_queue_t raylibQueue = nil; +static CADisplayLink *displayLink = nil; +static dispatch_semaphore_t frameSem = nil; +static int64_t vsyncCount = 0; + @interface RaylibGLView : UIView @end @@ -75,6 +82,7 @@ - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; ios_set_window_focused(false); } + - (void)forwardTouches:(NSSet *)touches action:(int)action { for (UITouch *touch in touches) { CGPoint point = [touch locationInView:self.view]; @@ -122,57 +130,113 @@ - (void)touchesCancelled:(NSSet *)touches @end -void ios_shutdown_window(void) { - if (!ios.initialized || ios.shuttingDown) +@interface RaylibDisplayLinkTarget : NSObject ++ (void)startDisplayLink; ++ (void)onDisplayFrame:(CADisplayLink *)link; ++ (void)stopDisplayLink; +@end + +@implementation RaylibDisplayLinkTarget + ++ (void)startDisplayLink { + if (displayLink != nil) return; - ios.shuttingDown = true; - void (^shutdownBlock)(void) = ^{ - if (ios.context != nil) { - [EAGLContext setCurrentContext:ios.context]; - - if (ios.framebuffer != 0) - glDeleteFramebuffers(1, &ios.framebuffer); - if (ios.colorBuffer != 0) - glDeleteRenderbuffers(1, &ios.colorBuffer); - if (ios.depthBuffer != 0) - glDeleteRenderbuffers(1, &ios.depthBuffer); - - ios.framebuffer = 0; - ios.colorBuffer = 0; - ios.depthBuffer = 0; - ios.context = nil; - } + frameSem = dispatch_semaphore_create(0); + vsyncCount = 0; - ios.glView = nil; - ios.viewController = nil; - ios.window = nil; - ios.initialized = false; - }; + displayLink = + [CADisplayLink displayLinkWithTarget:[self class] + selector:@selector(onDisplayFrame:)]; + + NSInteger maxFPS = [UIScreen mainScreen].maximumFramesPerSecond; + + // Use the display native refresh rate + displayLink.preferredFrameRateRange = + CAFrameRateRangeMake(60.0f, maxFPS, maxFPS); + + [displayLink addToRunLoop:[NSRunLoop mainRunLoop] + forMode:NSRunLoopCommonModes]; +} + ++ (void)onDisplayFrame:(CADisplayLink *)link { + (void)link; + __atomic_fetch_add(&vsyncCount, 1, __ATOMIC_RELEASE); + dispatch_semaphore_signal(frameSem); +} + ++ (void)stopDisplayLink { + if (displayLink == nil) + return; + + [displayLink invalidate]; + displayLink = nil; + + dispatch_semaphore_signal(frameSem); +} + +@end + +static void shutdown_internal(void) { + [RaylibDisplayLinkTarget stopDisplayLink]; + + if (ios.context != nil) { + [EAGLContext setCurrentContext:ios.context]; + + if (ios.framebuffer != 0) + glDeleteFramebuffers(1, &ios.framebuffer); + if (ios.colorBuffer != 0) + glDeleteRenderbuffers(1, &ios.colorBuffer); + if (ios.depthBuffer != 0) + glDeleteRenderbuffers(1, &ios.depthBuffer); + + ios.framebuffer = 0; + ios.colorBuffer = 0; + ios.depthBuffer = 0; + ios.context = nil; + } + + ios.glView = nil; + ios.viewController = nil; + ios.window = nil; + ios.initialized = false; +} + +void ios_close_platform(void) { + if (!ios.initialized || ios.shuttingDown) + return; + + ios.shuttingDown = true; if ([NSThread isMainThread]) - shutdownBlock(); + shutdown_internal(); else - dispatch_sync(dispatch_get_main_queue(), shutdownBlock); - - ios.shuttingDown = false; + dispatch_async(dispatch_get_main_queue(), ^{ + shutdown_internal(); + }); } @interface RaylibAppDelegate : UIResponder @end @interface RaylibSceneDelegate : UIResponder - @property(strong, nonatomic) UIWindow *window; - @end static void ios_start_raylib_main(void) { if (ios.raylibStarted) return; + ios.raylibStarted = true; - dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{ + raylibQueue = + dispatch_queue_create("com.raylib.engine", DISPATCH_QUEUE_SERIAL); + + dispatch_async(raylibQueue, ^{ + [[NSThread currentThread] setName:@"com.raylib.engine"]; + + // NSLog(@"[raylib][IOS] raylib thread: %@", [NSThread currentThread].name); + raylib_main(ios.argc, ios.argv); }); } @@ -240,6 +304,8 @@ - (void)scene:(UIScene *)scene self.window.rootViewController = ios.viewController; [self.window makeKeyAndVisible]; + [RaylibDisplayLinkTarget startDisplayLink]; + ios_start_raylib_main(); } @@ -256,7 +322,7 @@ - (void)sceneWillResignActive:(UIScene *)scene { - (void)sceneDidDisconnect:(UIScene *)scene { (void)scene; ios_request_close(); - ios_shutdown_window(); + ios_close_platform(); } @end @@ -314,9 +380,6 @@ static BOOL ios_setup_gl(void) { glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, ios.depthBuffer); - BOOL fbComplete = - (glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE); - GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (fbStatus != GL_FRAMEBUFFER_COMPLETE) { NSLog(@"[raylib][IOS] Framebuffer incomplete: 0x%04X", fbStatus); @@ -327,7 +390,7 @@ static BOOL ios_setup_gl(void) { [EAGLContext setCurrentContext:nil]; - return fbComplete; + return fbStatus == GL_FRAMEBUFFER_COMPLETE; } bool ios_initialize_window(int requestedWidth, int requestedHeight, @@ -419,6 +482,17 @@ void ios_present_frame(void) { err = glGetError(); if (err != GL_NO_ERROR) NSLog(@"[raylib][IOS] glGetError after present: 0x%04X", err); + if (frameSem != nil && !ios.shuttingDown) { + static int64_t lastVsync = 0; + int64_t current = __atomic_load_n(&vsyncCount, __ATOMIC_ACQUIRE); + + while ((current - lastVsync) < 1 && !ios.shuttingDown) { + dispatch_semaphore_wait(frameSem, DISPATCH_TIME_FOREVER); + current = __atomic_load_n(&vsyncCount, __ATOMIC_ACQUIRE); + } + + lastVsync = current; + } } void *ios_get_window_handle(void) { return (__bridge void *)ios.window; } @@ -442,7 +516,7 @@ void ios_get_window_metrics(int *screenWidth, int *screenHeight, *scaleX = ios.scaleX; if (scaleY) - *scaleY = ios.scaleY; + *scaleY = ios.scaleY; } void *ios_get_proc_address(const char *name) { From bb8ab464d07eeb27084f4c9f8be7d9ca5bb6a6e7 Mon Sep 17 00:00:00 2001 From: vsaint1 Date: Wed, 27 May 2026 02:51:50 -0300 Subject: [PATCH 13/18] removed iOS example project --- examples/iOS/CMakeLists.txt | 62 ------ examples/iOS/Info.plist | 79 ------- examples/iOS/README.md | 42 ---- examples/iOS/main.c | 433 ------------------------------------ 4 files changed, 616 deletions(-) delete mode 100644 examples/iOS/CMakeLists.txt delete mode 100644 examples/iOS/Info.plist delete mode 100644 examples/iOS/README.md delete mode 100644 examples/iOS/main.c diff --git a/examples/iOS/CMakeLists.txt b/examples/iOS/CMakeLists.txt deleted file mode 100644 index 584ba170e7e7..000000000000 --- a/examples/iOS/CMakeLists.txt +++ /dev/null @@ -1,62 +0,0 @@ -cmake_minimum_required(VERSION 3.25) - -project(raylib_ios_example LANGUAGES C OBJC) - -set(raylib_ios_example_sources - ${CMAKE_CURRENT_LIST_DIR}/main.c - ${CMAKE_CURRENT_LIST_DIR}/../../src/rcore.c - ${CMAKE_CURRENT_LIST_DIR}/../../src/rmodels.c - ${CMAKE_CURRENT_LIST_DIR}/../../src/rshapes.c - ${CMAKE_CURRENT_LIST_DIR}/../../src/rtext.c - ${CMAKE_CURRENT_LIST_DIR}/../../src/rtextures.c - ${CMAKE_CURRENT_LIST_DIR}/../../src/rcore_ios_main.m - ${CMAKE_CURRENT_LIST_DIR}/../../logo/raylib_1024x1024.png - ${CMAKE_CURRENT_LIST_DIR}/../../logo/raylib_512x512.png - ${CMAKE_CURRENT_LIST_DIR}/../../logo/raylib_180x180.png -) - -find_library(UIKIT_LIBRARY UIKit) -find_library(QUARTZCORE_LIBRARY QuartzCore) -find_library(OPENGLES_LIBRARY OpenGLES) -find_library(COREMOTION_LIBRARY CoreMotion) -find_library(FOUNDATION_LIBRARY Foundation) - -add_executable(raylib-ios-example MACOSX_BUNDLE ${raylib_ios_example_sources}) - -target_include_directories(raylib-ios-example PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/../../src -) - -target_compile_definitions(raylib-ios-example PRIVATE - PLATFORM_IOS - GRAPHICS_API_OPENGL_ES3 - SUPPORT_MODULE_RAUDIO=0 # FIXME: Currently the mini_audio backend is not working on iOS, so we disable audio support for this example - GLES_SILENCE_DEPRECATION=1 -) - -target_compile_options(raylib-ios-example PRIVATE -Wno-deprecated-declarations) - -set_source_files_properties( - ${CMAKE_CURRENT_LIST_DIR}/../../logo/raylib_1024x1024.png - ${CMAKE_CURRENT_LIST_DIR}/../../logo/raylib_512x512.png - ${CMAKE_CURRENT_LIST_DIR}/../../logo/raylib_180x180.png - PROPERTIES MACOSX_PACKAGE_LOCATION Resources -) - -target_link_libraries(raylib-ios-example PRIVATE - ${UIKIT_LIBRARY} - ${QUARTZCORE_LIBRARY} - ${OPENGLES_LIBRARY} - ${COREMOTION_LIBRARY} - ${FOUNDATION_LIBRARY} -) - -set_target_properties(raylib-ios-example PROPERTIES - MACOSX_BUNDLE TRUE - MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_LIST_DIR}/Info.plist" - XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "YES" - XCODE_ATTRIBUTE_GENERATE_INFOPLIST_FILE "NO" - XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "13.0" - XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.raylib.raylib-ios-example" - XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2" -) \ No newline at end of file diff --git a/examples/iOS/Info.plist b/examples/iOS/Info.plist deleted file mode 100644 index 71900b80faa3..000000000000 --- a/examples/iOS/Info.plist +++ /dev/null @@ -1,79 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleDisplayName - raylib iOS Example - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - com.raylib.raylib-ios-example - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - raylib-ios-example - CFBundlePackageType - APPL - CFBundleShortVersionString - 1.0 - CFBundleVersion - 1 - LSRequiresIPhoneOS - - CFBundleIcons - - CFBundlePrimaryIcon - - CFBundleIconFiles - - raylib_180x180 - raylib_512x512 - raylib_1024x1024 - - - - CFBundleIcons~ipad - - CFBundlePrimaryIcon - - CFBundleIconFiles - - raylib_180x180 - raylib_512x512 - raylib_1024x1024 - - - - UIRequiredDeviceCapabilities - - opengles-3 - - UIApplicationSceneManifest - - UIApplicationSupportsMultipleScenes - - UISceneConfigurations - - UIWindowSceneSessionRoleApplication - - - UISceneConfigurationName - Default Configuration - UISceneDelegateClassName - RaylibSceneDelegate - UISceneClassName - UIWindowScene - - - - - UISupportedInterfaceOrientations - - UIInterfaceOrientationPortrait - - - - - diff --git a/examples/iOS/README.md b/examples/iOS/README.md deleted file mode 100644 index 3eca0a1055cf..000000000000 --- a/examples/iOS/README.md +++ /dev/null @@ -1,42 +0,0 @@ -# raylib Breakout demo - -This example is generated with CMake and opened in Xcode. Use the simulator or a real device by changing the Apple SDK you target. - -## Requirements - -- macOS with Xcode installed -- CMake 3.18 or newer -- iOS Simulator support from Xcode, or a connected iPhone/iPad for device testing -- An Apple developer signing team if you want to run on a real device -- Min. iOS API 13 - -## Generate the Xcode project - -From this folder, run: - -```sh -cmake -S . -B build -G Xcode -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator -``` - -This generates `build/raylib_ios_example.xcodeproj`. - -## Run in the iOS Simulator - -1. Open `build/raylib_ios_example.xcodeproj` in Xcode. -2. Select an iPhone Simulator destination. -3. Build and run the `raylib-ios-example` scheme. - -## Run on a real iPhone or iPad - -1. Regenerate the project for the device SDK: - -```sh -cmake -S . -B build -G Xcode -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos -``` - -2. Open the generated Xcode project. -3. Select your connected device. -4. Set a valid signing team in Xcode if needed. -5. Build and run the same `raylib-ios-example` scheme. - - diff --git a/examples/iOS/main.c b/examples/iOS/main.c deleted file mode 100644 index d367dbe4109f..000000000000 --- a/examples/iOS/main.c +++ /dev/null @@ -1,433 +0,0 @@ -#include "raylib.h" -#include "raymath.h" - -#define BRICK_ROWS 5 -#define BRICK_COLS 7 -#define BRICK_PADDING 6.0f -#define BALL_SPEED_INIT 500.0f -#define BALL_SPEED_MAX 900.0f - -typedef enum { - STATE_TITLE, - STATE_PLAYING, - STATE_PAUSED, - STATE_WIN, - STATE_LOSE, -} GameState; - -typedef struct { - Rectangle rect; - Color color; - bool alive; - int points; -} Brick; - -typedef struct { - Color background; - Color panel; - Color panelBorder; - Color accent; - Color accentBorder; - Color text; - Color muted; - Color shadow; - - float margin; - float topBarHeight; - float buttonWidth; - float buttonHeight; - float actionWidth; - float actionHeight; - float roundness; -} UITheme; - -static UITheme DefaultUITheme(void) { - return (UITheme){ - .background = {14, 16, 22, 255}, - .panel = {245, 245, 245, 255}, - .panelBorder = {245, 245, 245, 255}, - .accent = {60, 180, 255, 255}, - .accentBorder = {245, 245, 245, 255}, - .text = {20, 20, 24, 255}, - .muted = {160, 170, 190, 255}, - .shadow = {0, 0, 0, 160}, - - .margin = 12.0f, - .topBarHeight = 34.0f, - .buttonWidth = 104.0f, - .buttonHeight = 34.0f, - .actionWidth = 168.0f, - .actionHeight = 36.0f, - .roundness = 0.0f, - }; -} - -static Color BrickColor(int row) { - Color palette[] = { - {255, 80, 80, 255}, {255, 160, 40, 255}, {255, 220, 40, 255}, - {80, 210, 90, 255}, {60, 180, 255, 255}, - }; - return palette[row % 5]; -} - -static bool CollideBallRect(Vector2 *pos, Vector2 *vel, float radius, - Rectangle rect, float dt) { - Rectangle expanded = { - rect.x - radius, - rect.y - radius, - rect.width + radius * 2.0f, - rect.height + radius * 2.0f, - }; - - if (!CheckCollisionPointRec(*pos, expanded)) - return false; - - float nearX = Clamp(pos->x, rect.x, rect.x + rect.width); - float nearY = Clamp(pos->y, rect.y, rect.y + rect.height); - float dx = pos->x - nearX; - float dy = pos->y - nearY; - - if (fabsf(dx) > fabsf(dy)) - vel->x = -vel->x; - else - vel->y = -vel->y; - - pos->x += vel->x * dt; - pos->y += vel->y * dt; - - return true; -} - -static void BuildBricks(Brick bricks[BRICK_ROWS][BRICK_COLS], float sw, - float brickAreaTop, float brickAreaH) { - float brickW = (sw - BRICK_PADDING * (BRICK_COLS + 1)) / BRICK_COLS; - float brickH = (brickAreaH - BRICK_PADDING * (BRICK_ROWS + 1)) / BRICK_ROWS; - - for (int r = 0; r < BRICK_ROWS; r++) { - for (int c = 0; c < BRICK_COLS; c++) { - float bx = BRICK_PADDING + c * (brickW + BRICK_PADDING); - float by = brickAreaTop + BRICK_PADDING + r * (brickH + BRICK_PADDING); - bricks[r][c] = (Brick){ - .rect = {bx, by, brickW, brickH}, - .color = BrickColor(r), - .alive = true, - .points = (BRICK_ROWS - r) * 10, - }; - } - } -} - -int main(void) { - InitWindow(0, 0, "Breakout - raylib iOS"); - SetTargetFPS(60); - - UITheme ui = DefaultUITheme(); - - const char *logoPath = - TextFormat("%sraylib_180x180.png", GetApplicationDirectory()); - Texture2D logo = LoadTexture(logoPath); - - int sw = GetScreenWidth(); - int sh = GetScreenHeight(); - - float paddleW = sw * 0.22f; - float paddleH = sh * 0.022f; - float paddleY = sh - sh * 0.10f; - float ballRadius = sw * 0.022f; - float brickAreaTop = sh * 0.22f; - float brickAreaH = sh * 0.32f; - - GameState state = STATE_TITLE; - int score = 0; - int lives = 3; - int totalBricks = BRICK_ROWS * BRICK_COLS; - int aliveBricks = totalBricks; - - Rectangle paddle = {sw * 0.5f - paddleW * 0.5f, paddleY, paddleW, paddleH}; - Vector2 ball = {sw * 0.5f, paddleY - ballRadius - 2.0f}; - Vector2 ballV = {BALL_SPEED_INIT * 0.6f, -BALL_SPEED_INIT}; - bool ballLaunched = false; - - Brick bricks[BRICK_ROWS][BRICK_COLS]; - BuildBricks(bricks, (float)sw, brickAreaTop, brickAreaH); - -#define RESET_BALL() \ - do { \ - ball = (Vector2){paddle.x + paddle.width * 0.5f, \ - paddleY - ballRadius - 2.0f}; \ - ballV = (Vector2){BALL_SPEED_INIT * 0.6f, -BALL_SPEED_INIT}; \ - ballLaunched = false; \ - } while (0) - - while (!WindowShouldClose()) { - float dt = GetFrameTime(); - if (dt > 0.05f) - dt = 0.05f; - - if (GetScreenWidth() != sw || GetScreenHeight() != sh) { - sw = GetScreenWidth(); - sh = GetScreenHeight(); - - paddleW = sw * 0.22f; - paddleH = sh * 0.022f; - paddleY = sh - sh * 0.10f; - ballRadius = sw * 0.022f; - brickAreaTop = sh * 0.22f; - brickAreaH = sh * 0.32f; - - paddle.width = paddleW; - paddle.height = paddleH; - paddle.y = paddleY; - - BuildBricks(bricks, (float)sw, brickAreaTop, brickAreaH); - } - - Vector2 pointer = - GetTouchPointCount() > 0 ? GetTouchPosition(0) : GetMousePosition(); - - bool tapped = IsMouseButtonPressed(MOUSE_BUTTON_LEFT); - - Rectangle pauseRect = {sw - ui.margin - ui.buttonWidth, ui.margin, - ui.buttonWidth, ui.buttonHeight}; - Rectangle buttonRect = {sw * 0.5f - ui.actionWidth * 0.5f, - sh - ui.margin - ui.actionHeight, ui.actionWidth, - ui.actionHeight}; - Rectangle menuRect = {sw * 0.5f - ui.actionWidth * 0.5f, - sh - ui.margin - ui.actionHeight * 2.0f - 8.0f, - ui.actionWidth, ui.actionHeight}; - Rectangle launchRect = {ui.margin, sh * 0.44f, sw - ui.margin * 2.0f, - sh - sh * 0.44f - ui.margin}; - - bool pausePressed = tapped && CheckCollisionPointRec(pointer, pauseRect) && - (state == STATE_PLAYING || state == STATE_PAUSED); - bool buttonPressed = tapped && CheckCollisionPointRec(pointer, buttonRect); - bool menuPressed = tapped && CheckCollisionPointRec(pointer, menuRect); - bool launchPressed = tapped && CheckCollisionPointRec(pointer, launchRect); - - if (state == STATE_TITLE) { - - if (buttonPressed) - state = STATE_PLAYING; - - } else if (state == STATE_PAUSED) { - - if (pausePressed) - state = STATE_PLAYING; - - } else if (state == STATE_WIN || state == STATE_LOSE) { - - if (buttonPressed) { - score = 0; - lives = 3; - aliveBricks = totalBricks; - paddle.x = sw * 0.5f - paddleW * 0.5f; - BuildBricks(bricks, (float)sw, brickAreaTop, brickAreaH); - RESET_BALL(); - state = STATE_PLAYING; - - } else if (menuPressed) { - score = 0; - lives = 3; - aliveBricks = totalBricks; - paddle.x = sw * 0.5f - paddleW * 0.5f; - BuildBricks(bricks, (float)sw, brickAreaTop, brickAreaH); - RESET_BALL(); - state = STATE_TITLE; - } - - } else { - - paddle.x = Clamp(pointer.x - paddle.width * 0.5f, 0.0f, - (float)sw - paddle.width); - - if (pausePressed) { - state = STATE_PAUSED; - - } else if (launchPressed && !ballLaunched) { - ballLaunched = true; - } - - if (ballLaunched) { - ball.x += ballV.x * dt; - ball.y += ballV.y * dt; - - if (ball.x - ballRadius <= 0.0f) { - ball.x = ballRadius; - ballV.x = fabsf(ballV.x); - } - if (ball.x + ballRadius >= sw) { - ball.x = sw - ballRadius; - ballV.x = -fabsf(ballV.x); - } - if (ball.y - ballRadius <= 0.0f) { - ball.y = ballRadius; - ballV.y = fabsf(ballV.y); - } - - if (ball.y - ballRadius > sh) { - lives--; - if (lives <= 0) - state = STATE_LOSE; - else - RESET_BALL(); - } - - if (CollideBallRect(&ball, &ballV, ballRadius, paddle, dt)) { - float hitPos = (ball.x - paddle.x) / paddle.width; - float angle = (hitPos - 0.5f) * 120.0f * DEG2RAD; - float speed = Vector2Length(ballV); - speed = Clamp(speed + 10.0f, 0.0f, BALL_SPEED_MAX); - ballV.x = sinf(angle) * speed; - ballV.y = -fabsf(cosf(angle) * speed); - } - - for (int r = 0; r < BRICK_ROWS; r++) { - for (int c = 0; c < BRICK_COLS; c++) { - Brick *b = &bricks[r][c]; - if (!b->alive) - continue; - - if (CollideBallRect(&ball, &ballV, ballRadius, b->rect, dt)) { - b->alive = false; - aliveBricks--; - score += b->points; - if (aliveBricks <= 0) - state = STATE_WIN; - goto done_bricks; - } - } - } - done_bricks:; - - } else { - ball.x = paddle.x + paddle.width * 0.5f; - ball.y = paddleY - ballRadius - 2.0f; - } - } - - BeginDrawing(); - ClearBackground(ui.background); - - if (state == STATE_TITLE) { - if (logo.id != 0) { - float targetSize = sh * 0.12f; - float scale = targetSize / (float)logo.width; - DrawTextureEx(logo, (Vector2){sw * 0.5f - targetSize * 0.5f, 8.0f}, - 0.0f, scale, WHITE); - } - - int ts = sw / 10; - int ss = sw / 22; - DrawText("BREAKOUT", sw / 2 - MeasureText("BREAKOUT", ts) / 2, - (int)(sh * 0.18f), ts, (Color){60, 180, 255, 255}); - DrawText("tap the button to start", - sw / 2 - MeasureText("tap the button to start", ss) / 2, - (int)(sh * 0.18f) + ts + 8, ss, (Color){160, 170, 190, 255}); - } - - if (state != STATE_TITLE) { - for (int r = 0; r < BRICK_ROWS; r++) { - for (int c = 0; c < BRICK_COLS; c++) { - Brick *b = &bricks[r][c]; - if (!b->alive) - continue; - - DrawRectangleRounded(b->rect, 0.25f, 6, b->color); - DrawLineEx((Vector2){b->rect.x + 4, b->rect.y + 2}, - (Vector2){b->rect.x + b->rect.width - 4, b->rect.y + 2}, - 1.5f, (Color){255, 255, 255, 60}); - } - } - - DrawRectangleRounded(paddle, 0.5f, 8, (Color){60, 180, 255, 255}); - DrawCircleV(ball, ballRadius, WHITE); - DrawCircleLines((int)ball.x, (int)ball.y, ballRadius + 2, - (Color){255, 255, 255, 60}); - - int hs = sw / 24; - DrawText(TextFormat("Score: %d", score), 14, 14, hs, - (Color){200, 210, 225, 255}); - DrawText(TextFormat("Lives: %d", lives), 14, 14 + hs + 8, hs, - (Color){255, 80, 80, 255}); - - if (!ballLaunched && state == STATE_PLAYING) { - const char *hint = "tap anywhere to launch"; - int hintSize = sw / 26; - DrawText(hint, sw / 2 - MeasureText(hint, hintSize) / 2, - (int)(sh * 0.72f), hintSize, ui.muted); - } - - if (state == STATE_PAUSED) { - DrawRectangle(0, 0, sw, sh, (Color){0, 0, 0, 150}); - - int ts = sw / 10; - int ss = sw / 22; - DrawText("PAUSED", sw / 2 - MeasureText("PAUSED", ts) / 2, sh / 2 - ts, - ts, RAYWHITE); - DrawText("tap resume to continue", - sw / 2 - MeasureText("tap resume to continue", ss) / 2, - sh / 2 + ts, ss, (Color){160, 170, 190, 180}); - } - - if (state == STATE_WIN || state == STATE_LOSE) { - DrawRectangle(0, 0, sw, sh, (Color){0, 0, 0, 160}); - - const char *title = state == STATE_WIN ? "YOU WIN!" : "GAME OVER"; - Color tcol = state == STATE_WIN ? (Color){80, 220, 100, 255} - : (Color){255, 80, 80, 255}; - int ts = sw / 9; - int ss = sw / 22; - - DrawText(title, sw / 2 - MeasureText(title, ts) / 2, sh / 2 - ts, ts, - tcol); - DrawText(TextFormat("Score: %d", score), - sw / 2 - MeasureText(TextFormat("Score: %d", score), ss) / 2, - sh / 2 + ts / 4, ss, (Color){200, 210, 225, 255}); - - const char *msg = state == STATE_WIN ? "tap retry to play again" - : "tap retry to try again"; - DrawText(msg, sw / 2 - MeasureText(msg, ss) / 2, sh / 2 + ts, ss, - (Color){160, 170, 190, 200}); - } - } - - if (state == STATE_PLAYING || state == STATE_PAUSED) { - const char *pauseText = state == STATE_PAUSED ? "RESUME" : "PAUSE"; - DrawRectangleRounded(pauseRect, ui.roundness, 8, ui.panel); - DrawText(pauseText, - (int)(pauseRect.x + pauseRect.width * 0.5f - - (float)MeasureText(pauseText, 16) * 0.5f), - (int)(pauseRect.y + 8), 16, ui.text); - } - - bool drawActionButton = - (state == STATE_TITLE) || (state == STATE_WIN || state == STATE_LOSE); - if (drawActionButton) { - const char *buttonText = - (state == STATE_WIN || state == STATE_LOSE) ? "RETRY" : "START"; - Rectangle actionButton = {sw * 0.5f - ui.actionWidth * 0.5f, - sh - ui.margin - ui.actionHeight, - ui.actionWidth, ui.actionHeight}; - DrawRectangleRounded(actionButton, ui.roundness, 8, ui.panel); - DrawText(buttonText, - (int)(actionButton.x + actionButton.width * 0.5f - - (float)MeasureText(buttonText, 18) * 0.5f), - (int)(actionButton.y + 8), 18, ui.text); - } - - if (state == STATE_WIN || state == STATE_LOSE) { - const char *menuText = "MAIN MENU"; - DrawRectangleRounded(menuRect, ui.roundness, 8, ui.panel); - DrawText(menuText, - (int)(menuRect.x + menuRect.width * 0.5f - - (float)MeasureText(menuText, 18) * 0.5f), - (int)(menuRect.y + 8), 18, ui.text); - } - - EndDrawing(); - } - - UnloadTexture(logo); - CloseWindow(); - return 0; -} \ No newline at end of file From f3aaba8db8cc72df54c13ff1859b22fe1b50c010 Mon Sep 17 00:00:00 2001 From: vsaint1 Date: Mon, 1 Jun 2026 21:59:24 -0300 Subject: [PATCH 14/18] removed platform preprocessor --- src/raylib.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/raylib.h b/src/raylib.h index c9ddb8a31af5..f3221e44260a 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -113,10 +113,6 @@ #define RLAPI // Functions defined as 'extern' by default (implicit specifiers) #endif -// iOS owns the real main() via UIApplicationMain. -#if defined(PLATFORM_IOS) - #define main raylib_main -#endif //---------------------------------------------------------------------------------- // Defines and Macros From e72038e13657ad17a260164959662170a4feed89 Mon Sep 17 00:00:00 2001 From: vsaint1 Date: Fri, 5 Jun 2026 10:48:54 -0300 Subject: [PATCH 15/18] fix: url components and import --- src/rcore_ios_main.m | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/rcore_ios_main.m b/src/rcore_ios_main.m index ffb188cb42bc..9245e6a5d5dd 100644 --- a/src/rcore_ios_main.m +++ b/src/rcore_ios_main.m @@ -2,7 +2,7 @@ #import #import #import -#include +#import #import #import @@ -150,7 +150,7 @@ + (void)startDisplayLink { selector:@selector(onDisplayFrame:)]; NSInteger maxFPS = [UIScreen mainScreen].maximumFramesPerSecond; - + // Use the display native refresh rate displayLink.preferredFrameRateRange = CAFrameRateRangeMake(60.0f, maxFPS, maxFPS); @@ -514,9 +514,9 @@ void ios_get_window_metrics(int *screenWidth, int *screenHeight, if (scaleX) *scaleX = ios.scaleX; - + if (scaleY) - *scaleY = ios.scaleY; + *scaleY = ios.scaleY; } void *ios_get_proc_address(const char *name) { @@ -524,11 +524,25 @@ void ios_get_window_metrics(int *screenWidth, int *screenHeight, } void ios_open_url(const char *url) { - NSString *nsurlString = [NSString stringWithUTF8String:url]; - NSURL *nsurl = [NSURL URLWithString:nsurlString]; - if (nsurl != nil) { + if (!url) { + NSLog(@"[raylib][IOS] invalid URL: null"); + return; + } + + NSURLComponents *components = [NSURLComponents + componentsWithString:[NSString stringWithUTF8String:url]]; + + if (components == nil || components.scheme == nil) { + + NSLog(@"[raylib][IOS] invalid URL: %s, Scheme: %s", url, + components ? components.scheme.UTF8String : "nil"); + return; + } + + if (components.URL != nil) { + dispatch_async(dispatch_get_main_queue(), ^{ - [[UIApplication sharedApplication] openURL:nsurl + [[UIApplication sharedApplication] openURL:components.URL options:@{} completionHandler:nil]; }); From d9c8a09f196ea01e3bfb4b1bb56119754dabf536 Mon Sep 17 00:00:00 2001 From: vsaint1 Date: Mon, 15 Jun 2026 05:46:34 -0300 Subject: [PATCH 16/18] refactor: global thread/vsync into nsobject (raylibcontroller) --- src/rcore_ios_main.m | 216 +++++++++++++++++++++++++++---------------- 1 file changed, 134 insertions(+), 82 deletions(-) diff --git a/src/rcore_ios_main.m b/src/rcore_ios_main.m index 9245e6a5d5dd..1f4abfe9f69d 100644 --- a/src/rcore_ios_main.m +++ b/src/rcore_ios_main.m @@ -36,17 +36,141 @@ int renderHeight; float scaleX; float scaleY; - bool raylibStarted; bool shuttingDown; bool initialized; } IOSBridgeState; static IOSBridgeState ios = {0}; -static dispatch_queue_t raylibQueue = nil; -static CADisplayLink *displayLink = nil; -static dispatch_semaphore_t frameSem = nil; -static int64_t vsyncCount = 0; +@interface RaylibController : NSObject + ++ (instancetype)sharedController; + +- (void)startInternal; + +- (void)startDisplayLink:(float)minFPS; + +- (void)stopDisplayLink; + +- (void)waitForVSync; + +@end + +@implementation RaylibController { + CADisplayLink *_displayLink; + dispatch_semaphore_t _frameSemaphore; + dispatch_queue_t _raylibQueue; + int64_t _vsyncCount; + int64_t _lastConsumedVsync; + float _minimumFPS; + BOOL _raylibStarted; +} + ++ (instancetype)sharedController { + static RaylibController *instance = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + instance = [[self alloc] init]; + }); + + return instance; +} + +- (instancetype)init { + self = [super init]; + if (self) { + _frameSemaphore = dispatch_semaphore_create(0); + _raylibQueue = + dispatch_queue_create("com.raylib.engine", DISPATCH_QUEUE_SERIAL); + _vsyncCount = 0; + _lastConsumedVsync = 0; + _raylibStarted = NO; + _minimumFPS = 60.0f; + } + + return self; +} + +- (void)startInternal { + if (_raylibStarted) + return; + + _raylibStarted = YES; + + dispatch_async(_raylibQueue, ^{ + [[NSThread currentThread] setName:@"com.raylib.engine"]; + + // NSLog(@"[raylib][IOS] raylib thread: %@", [NSThread currentThread].name); + + raylib_main(ios.argc, ios.argv); + }); +} + +- (void)startDisplayLink:(float)minFPS { + if (![NSThread isMainThread]) { + dispatch_async(dispatch_get_main_queue(), ^{ + [self startDisplayLink:_minimumFPS]; + }); + + return; + } + + _minimumFPS = minFPS; + + if (_displayLink != nil) + return; + + _displayLink = + [CADisplayLink displayLinkWithTarget:self + selector:@selector(onDisplayFrame:)]; + + NSInteger maxFPS = [UIScreen mainScreen].maximumFramesPerSecond; + + // Use the display native refresh rate + _displayLink.preferredFrameRateRange = + CAFrameRateRangeMake(_minimumFPS, maxFPS, maxFPS); + + [_displayLink addToRunLoop:[NSRunLoop mainRunLoop] + forMode:NSRunLoopCommonModes]; +} + +- (void)onDisplayFrame:(CADisplayLink *)link { + (void)link; + + __atomic_fetch_add(&_vsyncCount, 1, __ATOMIC_RELEASE); + dispatch_semaphore_signal(_frameSemaphore); +} + +- (void)stopDisplayLink { + if (![NSThread isMainThread]) { + dispatch_async(dispatch_get_main_queue(), ^{ + [self stopDisplayLink]; + }); + + return; + } + + if (_displayLink == nil) + return; + + [_displayLink invalidate]; + _displayLink = nil; + + dispatch_semaphore_signal(_frameSemaphore); +} + +- (void)waitForVSync { + int64_t current = __atomic_load_n(&_vsyncCount, __ATOMIC_ACQUIRE); + + while ((current - _lastConsumedVsync) < 1 && !ios.shuttingDown) { + dispatch_semaphore_wait(_frameSemaphore, DISPATCH_TIME_FOREVER); + current = __atomic_load_n(&_vsyncCount, __ATOMIC_ACQUIRE); + } + + _lastConsumedVsync = current; +} + +@end @interface RaylibGLView : UIView @end @@ -130,55 +254,8 @@ - (void)touchesCancelled:(NSSet *)touches @end -@interface RaylibDisplayLinkTarget : NSObject -+ (void)startDisplayLink; -+ (void)onDisplayFrame:(CADisplayLink *)link; -+ (void)stopDisplayLink; -@end - -@implementation RaylibDisplayLinkTarget - -+ (void)startDisplayLink { - if (displayLink != nil) - return; - - frameSem = dispatch_semaphore_create(0); - vsyncCount = 0; - - displayLink = - [CADisplayLink displayLinkWithTarget:[self class] - selector:@selector(onDisplayFrame:)]; - - NSInteger maxFPS = [UIScreen mainScreen].maximumFramesPerSecond; - - // Use the display native refresh rate - displayLink.preferredFrameRateRange = - CAFrameRateRangeMake(60.0f, maxFPS, maxFPS); - - [displayLink addToRunLoop:[NSRunLoop mainRunLoop] - forMode:NSRunLoopCommonModes]; -} - -+ (void)onDisplayFrame:(CADisplayLink *)link { - (void)link; - __atomic_fetch_add(&vsyncCount, 1, __ATOMIC_RELEASE); - dispatch_semaphore_signal(frameSem); -} - -+ (void)stopDisplayLink { - if (displayLink == nil) - return; - - [displayLink invalidate]; - displayLink = nil; - - dispatch_semaphore_signal(frameSem); -} - -@end - static void shutdown_internal(void) { - [RaylibDisplayLinkTarget stopDisplayLink]; + [[RaylibController sharedController] stopDisplayLink]; if (ios.context != nil) { [EAGLContext setCurrentContext:ios.context]; @@ -223,24 +300,6 @@ @interface RaylibSceneDelegate : UIResponder @property(strong, nonatomic) UIWindow *window; @end -static void ios_start_raylib_main(void) { - if (ios.raylibStarted) - return; - - ios.raylibStarted = true; - - raylibQueue = - dispatch_queue_create("com.raylib.engine", DISPATCH_QUEUE_SERIAL); - - dispatch_async(raylibQueue, ^{ - [[NSThread currentThread] setName:@"com.raylib.engine"]; - - // NSLog(@"[raylib][IOS] raylib thread: %@", [NSThread currentThread].name); - - raylib_main(ios.argc, ios.argv); - }); -} - @implementation RaylibAppDelegate - (BOOL)application:(UIApplication *)application @@ -304,9 +363,9 @@ - (void)scene:(UIScene *)scene self.window.rootViewController = ios.viewController; [self.window makeKeyAndVisible]; - [RaylibDisplayLinkTarget startDisplayLink]; + [[RaylibController sharedController] startDisplayLink:60.0f]; - ios_start_raylib_main(); + [[RaylibController sharedController] startInternal]; } - (void)sceneDidBecomeActive:(UIScene *)scene { @@ -482,16 +541,9 @@ void ios_present_frame(void) { err = glGetError(); if (err != GL_NO_ERROR) NSLog(@"[raylib][IOS] glGetError after present: 0x%04X", err); - if (frameSem != nil && !ios.shuttingDown) { - static int64_t lastVsync = 0; - int64_t current = __atomic_load_n(&vsyncCount, __ATOMIC_ACQUIRE); - - while ((current - lastVsync) < 1 && !ios.shuttingDown) { - dispatch_semaphore_wait(frameSem, DISPATCH_TIME_FOREVER); - current = __atomic_load_n(&vsyncCount, __ATOMIC_ACQUIRE); - } - lastVsync = current; + if (!ios.shuttingDown) { + [[RaylibController sharedController] waitForVSync]; } } From 5d8a8e8885792e192cc4829bf7481251e6fc9f49 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 28 Jun 2026 23:53:17 +0200 Subject: [PATCH 17/18] REVIEWED: iOS implementation -WIP- REVIEWED: iOS formatting REVIEWED: Some OpenGL details REVIEWED: Move platform code to platform directory WARNING: Changes not tested! --- src/CMakeLists.txt | 2 +- src/platforms/rcore_ios.c | 101 ++++++++++++++------------- src/{ => platforms}/rcore_ios_main.m | 51 +++++++++++--- src/raylib.h | 1 - 4 files changed, 96 insertions(+), 59 deletions(-) rename src/{ => platforms}/rcore_ios_main.m (92%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 87cab453af8d..320f237b1396 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -37,7 +37,7 @@ set(raylib_sources ) if (${PLATFORM} STREQUAL "iOS") - list(APPEND raylib_sources rcore_ios_main.m) + list(APPEND raylib_sources platforms/rcore_ios_main.m) endif() # Only build raudio if it's enabled diff --git a/src/platforms/rcore_ios.c b/src/platforms/rcore_ios.c index 6623a1ab91b4..cdd4e8d8ccc9 100644 --- a/src/platforms/rcore_ios.c +++ b/src/platforms/rcore_ios.c @@ -30,37 +30,37 @@ #include #endif -// UIKit/OpenGL bridge functions implemented in rcore_ios_main.m +// UIKit/OpenGL bridge functions implemented in [rcore_ios_main.m] RLAPI bool ios_initialize_window(int requestedWidth, int requestedHeight, int *screenWidth, int *screenHeight, int *renderWidth, int *renderHeight, float *scaleX, float *scaleY); -RLAPI void ios_make_current_context(void); RLAPI void ios_close_platform(void); +RLAPI void ios_make_current_context(void); RLAPI void ios_present_frame(void); RLAPI void *ios_get_window_handle(void); RLAPI void ios_get_window_metrics(int *screenWidth, int *screenHeight, int *renderWidth, int *renderHeight, float *scaleX, float *scaleY); RLAPI void *ios_get_proc_address(const char *name); RLAPI void ios_open_url(const char *url); +RLAPI void ios_set_target_fps(float fps); //---------------------------------------------------------------------------------- // Types and Structures Definition //---------------------------------------------------------------------------------- typedef struct { bool initialized; + struct { + // TODO: Use CORE.Input.Touch data... why is it required to duplicate this data? + int32_t pointCount; // Number of active touch points + int32_t pointId[MAX_TOUCH_POINTS]; // Touch point ids + Vector2 position[MAX_TOUCH_POINTS]; // Touch point positions + int32_t hoverPoints[MAX_TOUCH_POINTS]; // Hover point slots + } TouchRaw; } PlatformData; -typedef struct { - int32_t pointCount; // Number of active touch points - int32_t pointId[MAX_TOUCH_POINTS]; // Touch point ids - Vector2 position[MAX_TOUCH_POINTS]; // Touch point positions - int32_t hoverPoints[MAX_TOUCH_POINTS]; // Hover point slots -} TouchRaw; - //---------------------------------------------------------------------------------- // Global Variables Definition //---------------------------------------------------------------------------------- extern CoreData CORE; // Global CORE state context -static PlatformData platform = { 0 }; // Platform specific data -static TouchRaw touchRaw = { 0 }; // Raw touch state +static PlatformData platform = { 0 }; // Platform specific data //---------------------------------------------------------------------------------- // Module Internal Functions Declaration @@ -230,6 +230,7 @@ Vector2 GetWindowScaleDPI(void) float scaleX = 1.0f, scaleY = 1.0f; ios_get_window_metrics(&screenWidth, &screenHeight, &renderWidth, &renderHeight, &scaleX, &scaleY); + (void)screenWidth; (void)screenHeight; (void)renderWidth; (void)renderHeight; @@ -280,6 +281,8 @@ void DisableCursor(void) // Swap back buffer with front buffer (screen drawing) void SwapScreenBuffer(void) { + if (CORE.Time.target > 0) ios_set_target_fps((float)(1.0/CORE.Time.target)); + ios_present_frame(); } @@ -305,6 +308,7 @@ double GetTime(void) void OpenURL(const char *url) { // Security check to (partially) avoid malicious code + // TODO: Security concerns, this cod should b reviewed (not only for iOS) if (strchr(url, '\'') != NULL) TRACELOG(LOG_WARNING, "SYSTEM: Provided URL could be potentially malicious, avoid [\'] character"); else ios_open_url(url); } @@ -395,7 +399,7 @@ int InitPlatform(void) float scaleX = 1.0f, scaleY = 1.0f; if (!ios_initialize_window(CORE.Window.screen.width, CORE.Window.screen.height, - &screenWidth, &screenHeight, &renderWidth, &renderHeight, &scaleX, &scaleY)) + &screenWidth, &screenHeight, &renderWidth, &renderHeight, &scaleX, &scaleY)) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize iOS window and graphics context"); return -1; @@ -403,19 +407,19 @@ int InitPlatform(void) ios_make_current_context(); - CORE.Window.screen.width = screenWidth; - CORE.Window.screen.height = screenHeight; - CORE.Window.display.width = (int)((float)screenWidth*scaleX); + CORE.Window.screen.width = screenWidth; + CORE.Window.screen.height = screenHeight; + CORE.Window.display.width = (int)((float)screenWidth*scaleX); CORE.Window.display.height = (int)((float)screenHeight*scaleY); - CORE.Window.render.width = renderWidth; - CORE.Window.render.height = renderHeight; - CORE.Window.currentFbo.width = CORE.Window.render.width; + CORE.Window.render.width = renderWidth; + CORE.Window.render.height = renderHeight; + CORE.Window.currentFbo.width = CORE.Window.render.width; CORE.Window.currentFbo.height = CORE.Window.render.height; CORE.Window.screenScale = MatrixScale(scaleX, scaleY, 1.0f); rlLoadExtensions(ios_get_proc_address); - for (int i = 0; i < MAX_TOUCH_POINTS; i++) touchRaw.hoverPoints[i] = -1; + for (int i = 0; i < MAX_TOUCH_POINTS; i++) platform.TouchRaw.hoverPoints[i] = -1; platform.initialized = true; CORE.Window.ready = true; @@ -437,19 +441,19 @@ void ClosePlatform(void) CORE = (CoreData){ 0 }; platform = (PlatformData){ 0 }; - touchRaw = (TouchRaw){ 0 }; + platform.TouchRaw = (TouchRaw){ 0 }; } // Find or allocate a touch slot for the given touchId static int FindTouchSlot(intptr_t touchId, bool allowAllocate) { - for (int i = 0; i < touchRaw.pointCount; i++) + for (int i = 0; i < platform.TouchRaw.pointCount; i++) { - if (touchRaw.pointId[i] == (int32_t)touchId) return i; + if (platform.TouchRaw.pointId[i] == (int32_t)touchId) return i; } if (!allowAllocate) return -1; - if (touchRaw.pointCount < MAX_TOUCH_POINTS) return touchRaw.pointCount; + if (platform.TouchRaw.pointCount < MAX_TOUCH_POINTS) return platform.TouchRaw.pointCount; return -1; } @@ -457,10 +461,10 @@ static int FindTouchSlot(intptr_t touchId, bool allowAllocate) // Sync mouse position/state from primary touch point static void UpdateMouseFromTouches(void) { - if (touchRaw.pointCount > 0) + if (platform.TouchRaw.pointCount > 0) { CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition; - CORE.Input.Mouse.currentPosition = touchRaw.position[0]; + CORE.Input.Mouse.currentPosition = platform.TouchRaw.position[0]; CORE.Input.Mouse.currentWheelMove = (Vector2){ 0.0f, 0.0f }; } } @@ -474,19 +478,20 @@ void ios_handle_touch_began(intptr_t touchId, float x, float y) int index = FindTouchSlot(touchId, true); if (index < 0) return; - touchRaw.pointId[index] = (int32_t)touchId; - touchRaw.position[index] = (Vector2){ x, y }; + platform.TouchRaw.pointId[index] = (int32_t)touchId; + platform.TouchRaw.position[index] = (Vector2){ x, y }; - CORE.Input.Touch.pointId[index] = (int)touchId; - CORE.Input.Touch.position[index] = (Vector2){ x, y }; + CORE.Input.Touch.pointId[index] = (int)touchId; + CORE.Input.Touch.position[index] = (Vector2){ x, y }; CORE.Input.Touch.currentTouchState[index] = 1; CORE.Input.Touch.previousTouchState[index] = 0; - CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_LEFT] = 1; + CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_LEFT] = 1; CORE.Input.Mouse.previousButtonState[MOUSE_BUTTON_LEFT] = 0; - if (touchRaw.pointCount < MAX_TOUCH_POINTS) touchRaw.pointCount++; - CORE.Input.Touch.pointCount = touchRaw.pointCount; + if (platform.TouchRaw.pointCount < MAX_TOUCH_POINTS) platform.TouchRaw.pointCount++; + + CORE.Input.Touch.pointCount = platform.TouchRaw.pointCount; UpdateMouseFromTouches(); } @@ -496,12 +501,12 @@ void ios_handle_touch_moved(intptr_t touchId, float x, float y) int index = FindTouchSlot(touchId, false); if (index < 0) return; - touchRaw.position[index] = (Vector2){ x, y }; + platform.TouchRaw.position[index] = (Vector2){ x, y }; CORE.Input.Touch.pointId[index] = (int)touchId; CORE.Input.Touch.position[index] = (Vector2){ x, y }; CORE.Input.Touch.currentTouchState[index] = 1; CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_LEFT] = 1; - CORE.Input.Touch.pointCount = touchRaw.pointCount; + CORE.Input.Touch.pointCount = platform.TouchRaw.pointCount; UpdateMouseFromTouches(); } @@ -511,28 +516,28 @@ void ios_handle_touch_ended(intptr_t touchId, float x, float y) int index = FindTouchSlot(touchId, false); if (index < 0) return; - touchRaw.position[index] = (Vector2){ x, y }; - CORE.Input.Touch.position[index] = (Vector2){ x, y }; - CORE.Input.Touch.currentTouchState[index] = 0; - CORE.Input.Touch.previousTouchState[index] = 1; - CORE.Input.Touch.pointId[index] = 0; + platform.TouchRaw.position[index] = (Vector2){ x, y }; + CORE.Input.Touch.position[index] = (Vector2){ x, y }; + CORE.Input.Touch.currentTouchState[index] = 0; + CORE.Input.Touch.previousTouchState[index] = 1; + CORE.Input.Touch.pointId[index] = 0; // Compact the touch arrays — shift remaining points down - for (int i = index; i < touchRaw.pointCount - 1; i++) + for (int i = index; i < platform.TouchRaw.pointCount - 1; i++) { - touchRaw.pointId[i] = touchRaw.pointId[i + 1]; - touchRaw.position[i] = touchRaw.position[i + 1]; + platform.TouchRaw.pointId[i] = platform.TouchRaw.pointId[i + 1]; + platform.TouchRaw.position[i] = platform.TouchRaw.position[i + 1]; - CORE.Input.Touch.pointId[i] = CORE.Input.Touch.pointId[i + 1]; - CORE.Input.Touch.position[i] = CORE.Input.Touch.position[i + 1]; - CORE.Input.Touch.currentTouchState[i] = CORE.Input.Touch.currentTouchState[i + 1]; + CORE.Input.Touch.pointId[i] = CORE.Input.Touch.pointId[i + 1]; + CORE.Input.Touch.position[i] = CORE.Input.Touch.position[i + 1]; + CORE.Input.Touch.currentTouchState[i] = CORE.Input.Touch.currentTouchState[i + 1]; CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.previousTouchState[i + 1]; } - if (touchRaw.pointCount > 0) touchRaw.pointCount--; - CORE.Input.Touch.pointCount = touchRaw.pointCount; + if (platform.TouchRaw.pointCount > 0) platform.TouchRaw.pointCount--; + CORE.Input.Touch.pointCount = platform.TouchRaw.pointCount; - CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_LEFT] = (touchRaw.pointCount > 0)? 1 : 0; + CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_LEFT] = (platform.TouchRaw.pointCount > 0)? 1 : 0; CORE.Input.Mouse.previousButtonState[MOUSE_BUTTON_LEFT] = 1; UpdateMouseFromTouches(); diff --git a/src/rcore_ios_main.m b/src/platforms/rcore_ios_main.m similarity index 92% rename from src/rcore_ios_main.m rename to src/platforms/rcore_ios_main.m index 1f4abfe9f69d..c6e29985f649 100644 --- a/src/rcore_ios_main.m +++ b/src/platforms/rcore_ios_main.m @@ -1,3 +1,24 @@ +/********************************************************************************************** +* +* rcore_ios_main.m - Functions required by iOS platform implementation +* +* PLATFORM: IOS +* - iOS (arm64) +* - iOS Simulator +* +* LIMITATIONS: +* - No keyboard input support +* - No gamepad input support +* +* DEPENDENCIES: +* - UIKit/QuartzCore/OpenGLES (provided by iOS SDK) +* +* LICENSE: zlib/libpng +* +* Copyright (c) 2013-2026 Ramon Santamaria (@raysan5) and contributors +* +**********************************************************************************************/ + #import #import #import @@ -54,6 +75,8 @@ - (void)stopDisplayLink; - (void)waitForVSync; +- (void)setTargetFPS:(float)fps; + @end @implementation RaylibController { @@ -127,8 +150,9 @@ - (void)startDisplayLink:(float)minFPS { NSInteger maxFPS = [UIScreen mainScreen].maximumFramesPerSecond; // Use the display native refresh rate - _displayLink.preferredFrameRateRange = - CAFrameRateRangeMake(_minimumFPS, maxFPS, maxFPS); + // NOTE: Driven dynamically via setTargetFPS, no hardcoded maxFPS + //_displayLink.preferredFrameRateRange = + // CAFrameRateRangeMake(_minimumFPS, maxFPS, maxFPS); [_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; @@ -170,6 +194,13 @@ - (void)waitForVSync { _lastConsumedVsync = current; } +- (void)setTargetFPS:(float)fps { + _minimumFPS = fps; + if (_displayLink != nil) + _displayLink.preferredFrameRateRange = + CAFrameRateRangeMake(fps, fps, fps); +} + @end @interface RaylibGLView : UIView @@ -532,15 +563,13 @@ void ios_present_frame(void) { // NSLog(@"[raylib][IOS] IOSPresentFrame: thread=%@, currentContext=%@", // [NSThread currentThread], [EAGLContext currentContext]); - GLenum err = glGetError(); - if (err != GL_NO_ERROR) - NSLog(@"[raylib][IOS] glGetError before present: 0x%04X", err); - [ios.context presentRenderbuffer:GL_RENDERBUFFER]; - err = glGetError(); - if (err != GL_NO_ERROR) - NSLog(@"[raylib][IOS] glGetError after present: 0x%04X", err); +#if RLGL_SHOW_GL_DETAILS_INFO + GLenum err = glGetError(); + if (err != GL_NO_ERROR) + NSLog(@"[raylib][IOS] glGetError after present: 0x%04X", err); +#endif if (!ios.shuttingDown) { [[RaylibController sharedController] waitForVSync]; @@ -601,6 +630,10 @@ void ios_open_url(const char *url) { } } +void ios_set_target_fps(float fps) { + [[RaylibController sharedController] setTargetFPS:fps]; +} + int main(int argc, char *argv[]) { ios.argc = argc; ios.argv = argv; diff --git a/src/raylib.h b/src/raylib.h index f88867d555dd..e49d6b2f7de2 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -113,7 +113,6 @@ #define RLAPI // Functions defined as 'extern' by default (implicit specifiers) #endif - //---------------------------------------------------------------------------------- // Defines and Macros //---------------------------------------------------------------------------------- From 07fd6d6428c8d6df584867ea044c5299e90ebc72 Mon Sep 17 00:00:00 2001 From: vsaint1 Date: Thu, 2 Jul 2026 03:23:03 -0300 Subject: [PATCH 18/18] fix cleanup --- src/platforms/rcore_ios.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/platforms/rcore_ios.c b/src/platforms/rcore_ios.c index cdd4e8d8ccc9..1f33d75578bd 100644 --- a/src/platforms/rcore_ios.c +++ b/src/platforms/rcore_ios.c @@ -441,7 +441,6 @@ void ClosePlatform(void) CORE = (CoreData){ 0 }; platform = (PlatformData){ 0 }; - platform.TouchRaw = (TouchRaw){ 0 }; } // Find or allocate a touch slot for the given touchId @@ -557,4 +556,4 @@ void ios_set_window_focused(bool focused) { if (focused) FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED); else FLAG_SET(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED); -} \ No newline at end of file +}