Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rcore] Porting raylib to iOS and implement rcore_ios.c #3880

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
d0a13c6
init
blueloveTH Mar 22, 2024
0caa413
create XCode15 project targeting iOS
blueloveTH Mar 23, 2024
b3b2d50
Update rcore_ios.c
blueloveTH Mar 23, 2024
dfc6dc2
some update
blueloveTH Mar 23, 2024
d1ffab4
the first working version
blueloveTH Mar 23, 2024
cae863a
some fix
blueloveTH Mar 23, 2024
2900607
prepare to add touch callbacks
blueloveTH Mar 23, 2024
74da3b7
Update rcore_ios.c
blueloveTH Mar 23, 2024
9f7dec6
support more touches
blueloveTH Mar 24, 2024
c66c9e9
some fix
blueloveTH Mar 24, 2024
a552997
change `pointId[]` to `long long`
blueloveTH Mar 24, 2024
5db5720
Update raylib_api.* by CI
github-actions[bot] Mar 24, 2024
c0ac347
Update rcore_ios.c
blueloveTH Mar 24, 2024
3a9649d
Update rcore_ios.c
blueloveTH Mar 24, 2024
67fb284
upgrade to `GRAPHICS_API_OPENGL_ES3`
blueloveTH Mar 24, 2024
0a9ea31
Update rlgl.h
blueloveTH Mar 25, 2024
cd1b81d
Update project.pbxproj
blueloveTH Mar 25, 2024
33ccfd9
Create ios.yml
blueloveTH Mar 25, 2024
ed861d0
Update ios.yml
blueloveTH Mar 25, 2024
da46011
Update ios.yml
blueloveTH Mar 25, 2024
2e29d3f
Update ios.yml
blueloveTH Mar 25, 2024
ee2a307
Update rcore_ios.c
blueloveTH Mar 27, 2024
e6afac8
Update rcore_ios.c
blueloveTH Mar 27, 2024
e5ecddf
Update rcore_ios.c
blueloveTH Mar 27, 2024
86b3ba2
Update rcore_ios.c
blueloveTH Mar 27, 2024
c124623
Update rcore_ios.c
blueloveTH Mar 27, 2024
f3c4d49
Update rcore_ios.c
blueloveTH Mar 27, 2024
d1a8b86
Revert "change `pointId[]` to `long long`"
blueloveTH Mar 27, 2024
faaa623
revert long long change
blueloveTH Mar 27, 2024
4a7b666
Update raylib_api.* by CI
github-actions[bot] Mar 27, 2024
bc34ea6
Update rcore_ios.c
blueloveTH Mar 27, 2024
3c12964
Update rcore_ios.c
blueloveTH Mar 27, 2024
b69cee5
Update rcore_ios.c
blueloveTH Mar 28, 2024
5241819
Update rcore_ios.c
blueloveTH Mar 28, 2024
d10d888
Update rcore_ios.c
blueloveTH Mar 28, 2024
8fbec6f
Revert "Update raylib_api.* by CI"
blueloveTH Apr 3, 2024
7f9400c
Revert "Update raylib_api.* by CI"
blueloveTH Apr 3, 2024
cd8f5f9
Update rcore_ios.c
blueloveTH Apr 4, 2024
c5c41f9
Update rcore_ios.c
blueloveTH Apr 4, 2024
c4a42a3
Update rcore_android.c
blueloveTH Apr 6, 2024
918c394
Update rcore_android.c
blueloveTH Apr 6, 2024
d68b8eb
Update main.c
blueloveTH Apr 11, 2024
a3873bf
Update project.pbxproj
blueloveTH Apr 11, 2024
1de43bf
Update rcore_ios.c
blueloveTH Apr 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: iOS

on:
workflow_dispatch:
push:
paths:
- 'src/**'
- 'examples/**'
- '.github/workflows/android.yml'
pull_request:
paths:
- 'src/**'
- 'examples/**'
- '.github/workflows/android.yml'
release:
types: [published]

jobs:
build:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@master
- name: Build Xcode15 project
run: |
cd projects/Xcode15
curl -L https://github.com/raysan5/raylib/files/14743869/libEGL.xcframework.zip --output libEGL.xcframework.zip
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are those files located? It looks a bit dodgy... isn't there a better approach?

curl -L https://github.com/raysan5/raylib/files/14743873/libGLESv2.xcframework.zip --output libGLESv2.xcframework.zip
mkdir -p raylib/Frameworks
unzip -q libEGL.xcframework.zip -d raylib/Frameworks/libEGL.xcframework
unzip -q libGLESv2.xcframework.zip -d raylib/Frameworks/libGLESv2.xcframework
rm libEGL.xcframework.zip
rm libGLESv2.xcframework.zip
xcodebuild -project raylib.xcodeproj -scheme raylib -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14' build

14 changes: 10 additions & 4 deletions parser/output/raylib_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@
"type": "UNKNOWN",
"value": "SHADER_LOC_MAP_METALNESS",
"description": ""
},
{
"name": "GetMouseRay",
"type": "UNKNOWN",
"value": "GetScreenToWorldRay",
"description": "Compatibility hack for previous raylib versions"
}
],
"structs": [
Expand Down Expand Up @@ -3873,12 +3879,12 @@
},
{
"name": "GetScreenToWorldRay",
"description": "Get a ray trace from mouse position",
"description": "Get a ray trace from screen position (i.e mouse)",
"returnType": "Ray",
"params": [
{
"type": "Vector2",
"name": "mousePosition"
"name": "position"
},
{
"type": "Camera",
Expand All @@ -3888,12 +3894,12 @@
},
{
"name": "GetScreenToWorldRayEx",
"description": "Get a ray trace from mouse position in a viewport",
"description": "Get a ray trace from screen position (i.e mouse) in a viewport",
"returnType": "Ray",
"params": [
{
"type": "Vector2",
"name": "mousePosition"
"name": "position"
},
{
"type": "Camera",
Expand Down
14 changes: 10 additions & 4 deletions parser/output/raylib_api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ return {
type = "UNKNOWN",
value = "SHADER_LOC_MAP_METALNESS",
description = ""
},
{
name = "GetMouseRay",
blueloveTH marked this conversation as resolved.
Show resolved Hide resolved
type = "UNKNOWN",
value = "GetScreenToWorldRay",
description = "Compatibility hack for previous raylib versions"
}
},
structs = {
Expand Down Expand Up @@ -3636,19 +3642,19 @@ return {
},
{
name = "GetScreenToWorldRay",
description = "Get a ray trace from mouse position",
description = "Get a ray trace from screen position (i.e mouse)",
returnType = "Ray",
params = {
{type = "Vector2", name = "mousePosition"},
{type = "Vector2", name = "position"},
{type = "Camera", name = "camera"}
}
},
{
name = "GetScreenToWorldRayEx",
description = "Get a ray trace from mouse position in a viewport",
description = "Get a ray trace from screen position (i.e mouse) in a viewport",
returnType = "Ray",
params = {
{type = "Vector2", name = "mousePosition"},
{type = "Vector2", name = "position"},
{type = "Camera", name = "camera"},
{type = "float", name = "width"},
{type = "float", name = "height"}
Expand Down
15 changes: 10 additions & 5 deletions parser/output/raylib_api.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Defines found: 56
Defines found: 57

Define 001: RAYLIB_H
Name: RAYLIB_H
Expand Down Expand Up @@ -281,6 +281,11 @@ Define 056: SHADER_LOC_MAP_SPECULAR
Type: UNKNOWN
Value: SHADER_LOC_MAP_METALNESS
Description:
Define 057: GetMouseRay
Name: GetMouseRay
Type: UNKNOWN
Value: GetScreenToWorldRay
Description: Compatibility hack for previous raylib versions

Structures found: 34

Expand Down Expand Up @@ -1424,14 +1429,14 @@ Function 083: UnloadShader() (1 input parameters)
Function 084: GetScreenToWorldRay() (2 input parameters)
Name: GetScreenToWorldRay
Return type: Ray
Description: Get a ray trace from mouse position
Param[1]: mousePosition (type: Vector2)
Description: Get a ray trace from screen position (i.e mouse)
Param[1]: position (type: Vector2)
Param[2]: camera (type: Camera)
Function 085: GetScreenToWorldRayEx() (4 input parameters)
Name: GetScreenToWorldRayEx
Return type: Ray
Description: Get a ray trace from mouse position in a viewport
Param[1]: mousePosition (type: Vector2)
Description: Get a ray trace from screen position (i.e mouse) in a viewport
Param[1]: position (type: Vector2)
Param[2]: camera (type: Camera)
Param[3]: width (type: float)
Param[4]: height (type: float)
Expand Down
11 changes: 6 additions & 5 deletions parser/output/raylib_api.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="Windows-1252" ?>
<raylibAPI>
<Defines count="56">
<Defines count="57">
<Define name="RAYLIB_H" type="GUARD" value="" desc="" />
<Define name="RAYLIB_VERSION_MAJOR" type="INT" value="5" desc="" />
<Define name="RAYLIB_VERSION_MINOR" type="INT" value="1" desc="" />
Expand Down Expand Up @@ -57,6 +57,7 @@
<Define name="MATERIAL_MAP_SPECULAR" type="UNKNOWN" value="MATERIAL_MAP_METALNESS" desc="" />
<Define name="SHADER_LOC_MAP_DIFFUSE" type="UNKNOWN" value="SHADER_LOC_MAP_ALBEDO" desc="" />
<Define name="SHADER_LOC_MAP_SPECULAR" type="UNKNOWN" value="SHADER_LOC_MAP_METALNESS" desc="" />
<Define name="GetMouseRay" type="UNKNOWN" value="GetScreenToWorldRay" desc="Compatibility hack for previous raylib versions" />
</Defines>
<Structs count="34">
<Struct name="Vector2" fieldCount="2" desc="Vector2, 2 components">
Expand Down Expand Up @@ -902,12 +903,12 @@
<Function name="UnloadShader" retType="void" paramCount="1" desc="Unload shader from GPU memory (VRAM)">
<Param type="Shader" name="shader" desc="" />
</Function>
<Function name="GetScreenToWorldRay" retType="Ray" paramCount="2" desc="Get a ray trace from mouse position">
<Param type="Vector2" name="mousePosition" desc="" />
<Function name="GetScreenToWorldRay" retType="Ray" paramCount="2" desc="Get a ray trace from screen position (i.e mouse)">
<Param type="Vector2" name="position" desc="" />
<Param type="Camera" name="camera" desc="" />
</Function>
<Function name="GetScreenToWorldRayEx" retType="Ray" paramCount="4" desc="Get a ray trace from mouse position in a viewport">
<Param type="Vector2" name="mousePosition" desc="" />
<Function name="GetScreenToWorldRayEx" retType="Ray" paramCount="4" desc="Get a ray trace from screen position (i.e mouse) in a viewport">
<Param type="Vector2" name="position" desc="" />
<Param type="Camera" name="camera" desc="" />
<Param type="float" name="width" desc="" />
<Param type="float" name="height" desc="" />
Expand Down
120 changes: 120 additions & 0 deletions projects/Xcode15/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*******************************************************************************************
*
* raylib [core] example - Input Gestures Detection
*
* Example originally created with raylib 1.4, last time updated with raylib 4.2
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2016-2024 Ramon Santamaria (@raysan5)
*
********************************************************************************************/

#include "raylib.h"

int MAX_GESTURE_STRINGS = 20;
int screenWidth = 0;
int screenHeight = 0;
Vector2 touchPosition;
Rectangle touchArea;
int gesturesCount = 0;
char gestureStrings[100][32];
int currentGesture = GESTURE_NONE;
int lastGesture = GESTURE_NONE;

void ios_ready(){
InitWindow(0, 0, "raylib [core] example - input gestures");

screenWidth = GetScreenWidth();
screenHeight = GetScreenHeight();

touchPosition = (Vector2){ 0, 0 };
touchArea = (Rectangle){ 220, 10, screenWidth - 230.0f, screenHeight - 20.0f };

//SetGesturesEnabled(0b0000000000001001); // Enable only some gestures to be detected
SetTargetFPS(60);
MAX_GESTURE_STRINGS = (screenHeight - 50) / 20;
}

static void add_gesture(const char* title){
if (gesturesCount >= MAX_GESTURE_STRINGS)
{
for (int i = 0; i < MAX_GESTURE_STRINGS; i++) TextCopy(gestureStrings[i], "\0");
gesturesCount = 0;
}
TextCopy(gestureStrings[gesturesCount], title);
gesturesCount++;
}

void ios_update()
{
lastGesture = currentGesture;
currentGesture = GetGestureDetected();
touchPosition = GetTouchPosition(0);

if(IsMouseButtonPressed(0)) add_gesture("MouseButtonPressed");
if(IsMouseButtonReleased(0)) add_gesture("MouseButtonReleased");

if (CheckCollisionPointRec(touchPosition, touchArea) && (currentGesture != GESTURE_NONE))
{
if (currentGesture != lastGesture)
{
// Store gesture string
switch (currentGesture)
{
case GESTURE_TAP: add_gesture( "GESTURE TAP"); break;
case GESTURE_DOUBLETAP: add_gesture( "GESTURE DOUBLETAP"); break;
case GESTURE_HOLD: add_gesture( "GESTURE HOLD"); break;
case GESTURE_DRAG: add_gesture( "GESTURE DRAG"); break;
case GESTURE_SWIPE_RIGHT: add_gesture( "GESTURE SWIPE RIGHT"); break;
case GESTURE_SWIPE_LEFT: add_gesture( "GESTURE SWIPE LEFT"); break;
case GESTURE_SWIPE_UP: add_gesture( "GESTURE SWIPE UP"); break;
case GESTURE_SWIPE_DOWN: add_gesture( "GESTURE SWIPE DOWN"); break;
case GESTURE_PINCH_IN: add_gesture( "GESTURE PINCH IN"); break;
case GESTURE_PINCH_OUT: add_gesture( "GESTURE PINCH OUT"); break;
default: break;
}
}
}

// Draw
//----------------------------------------------------------------------------------
BeginDrawing();

ClearBackground(RAYWHITE);

DrawRectangleRec(touchArea, GRAY);
DrawRectangle(225, 15, screenWidth - 240, screenHeight - 30, RAYWHITE);

DrawText("GESTURES TEST AREA", screenWidth - 270, screenHeight - 40, 20, Fade(GRAY, 0.5f));

for (int i = 0; i < gesturesCount; i++)
{
if (i % 2 == 0){
DrawRectangle(10, 30 + 20*i, 200, 20, Fade(LIGHTGRAY, 0.5f));
}else{
DrawRectangle(10, 30 + 20*i, 200, 20, Fade(LIGHTGRAY, 0.3f));
}
if (i < gesturesCount - 1){
DrawText(gestureStrings[i], 35, 36 + 20*i, 10, DARKGRAY);
}else{
DrawText(gestureStrings[i], 35, 36 + 20*i, 10, MAROON);
}
}

DrawRectangleLines(10, 29, 200, screenHeight - 50, GRAY);
DrawText(
TextFormat("TOUCH COUNT: %d", GetTouchPointCount()),
50, 15, 10, GRAY
);

for(int i=0; i < GetTouchPointCount(); i++){
DrawCircleV(GetTouchPosition(i), 30, MAROON);
}
EndDrawing();
}

void ios_destroy(){
CloseWindow(); // Close window and OpenGL context
}
Loading
Loading