summaryrefslogtreecommitdiff
path: root/src/contrib/SDL-3.2.20/docs/README-ios.md
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-08-30 16:53:58 -0700
committer3gg <3gg@shellblade.net>2025-08-30 16:53:58 -0700
commit6aaedb813fa11ba0679c3051bc2eb28646b9506c (patch)
tree34acbfc9840e02cb4753e6306ea7ce978bf8b58e /src/contrib/SDL-3.2.20/docs/README-ios.md
parent8f228ade99dd3d4c8da9b78ade1815c9adf85c8f (diff)
Update to SDL3
Diffstat (limited to 'src/contrib/SDL-3.2.20/docs/README-ios.md')
-rw-r--r--src/contrib/SDL-3.2.20/docs/README-ios.md260
1 files changed, 260 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/docs/README-ios.md b/src/contrib/SDL-3.2.20/docs/README-ios.md
new file mode 100644
index 0000000..166d182
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/docs/README-ios.md
@@ -0,0 +1,260 @@
1iOS
2======
3
4Building the Simple DirectMedia Layer for iOS 11.0+
5==============================================================================
6
7Please note that building SDL requires at least Xcode 12.2 and the iOS 14.2 SDK.
8
9Instructions:
10
111. Open SDL.xcodeproj (located in Xcode/SDL) in Xcode.
122. Select your desired target, and hit build.
13
14
15Using the Simple DirectMedia Layer for iOS
16==============================================================================
17
181. Run Xcode and create a new project using the iOS Game template, selecting the Objective C language and Metal game technology.
192. In the main view, delete all files except for Assets and LaunchScreen
203. Right click the project in the main view, select "Add Files...", and add the SDL project, Xcode/SDL/SDL.xcodeproj
214. Select the project in the main view, go to the "Info" tab and under "Custom iOS Target Properties" remove the line "Main storyboard file base name"
225. Select the project in the main view, go to the "Build Settings" tab, select "All", and edit "Header Search Path" and drag over the SDL "Public Headers" folder from the left
236. Select the project in the main view, go to the "Build Phases" tab, select "Link Binary With Libraries", and add SDL3.framework from "Framework-iOS"
247. Select the project in the main view, go to the "General" tab, scroll down to "Frameworks, Libraries, and Embedded Content", and select "Embed & Sign" for the SDL library.
258. Add the source files that you would normally have for an SDL program, making sure to have #include <SDL3/SDL_main.h> at the top of the file containing your main() function.
269. Add any assets that your application needs.
2710. Enjoy!
28
29
30TODO: Add information regarding App Store requirements such as icons, etc.
31
32
33Notes -- Retina / High-DPI and window sizes
34==============================================================================
35
36Window and display mode sizes in SDL are in points rather than in pixels.
37On iOS this means that a window created on an iPhone 6 will have a size in
38points of 375 x 667, rather than a size in pixels of 750 x 1334. All iOS apps
39are expected to size their content based on points rather than pixels,
40as this allows different iOS devices to have different pixel densities
41(Retina versus non-Retina screens, etc.) without apps caring too much.
42
43SDL_GetWindowSize() and mouse coordinates are in points rather than pixels,
44but the window will have a much greater pixel density when the device supports
45it, and the SDL_GetWindowSizeInPixels() can be called to determine the size
46in pixels of the drawable screen framebuffer.
47
48The SDL 2D rendering API will automatically handle this for you, by default
49providing a rendering area in points, and you can call SDL_SetRenderLogicalPresentation()
50to gain access to the higher density resolution.
51
52Some OpenGL ES functions such as glViewport expect sizes in pixels rather than
53sizes in points. When doing 2D rendering with OpenGL ES, an orthographic projection
54matrix using the size in points (SDL_GetWindowSize()) can be used in order to
55display content at the same scale no matter whether a Retina device is used or not.
56
57
58Notes -- Application events
59==============================================================================
60
61On iOS the application goes through a fixed life cycle and you will get
62notifications of state changes via application events. When these events
63are delivered you must handle them in an event callback because the OS may
64not give you any processing time after the events are delivered.
65
66e.g.
67
68 bool HandleAppEvents(void *userdata, SDL_Event *event)
69 {
70 switch (event->type)
71 {
72 case SDL_EVENT_TERMINATING:
73 /* Terminate the app.
74 Shut everything down before returning from this function.
75 */
76 return false;
77 case SDL_EVENT_LOW_MEMORY:
78 /* You will get this when your app is paused and iOS wants more memory.
79 Release as much memory as possible.
80 */
81 return false;
82 case SDL_EVENT_WILL_ENTER_BACKGROUND:
83 /* Prepare your app to go into the background. Stop loops, etc.
84 This gets called when the user hits the home button, or gets a call.
85 */
86 return false;
87 case SDL_EVENT_DID_ENTER_BACKGROUND:
88 /* This will get called if the user accepted whatever sent your app to the background.
89 If the user got a phone call and canceled it, you'll instead get an SDL_EVENT_DID_ENTER_FOREGROUND event and restart your loops.
90 When you get this, you have 5 seconds to save all your state or the app will be terminated.
91 Your app is NOT active at this point.
92 */
93 return false;
94 case SDL_EVENT_WILL_ENTER_FOREGROUND:
95 /* This call happens when your app is coming back to the foreground.
96 Restore all your state here.
97 */
98 return false;
99 case SDL_EVENT_DID_ENTER_FOREGROUND:
100 /* Restart your loops here.
101 Your app is interactive and getting CPU again.
102 */
103 return false;
104 default:
105 /* No special processing, add it to the event queue */
106 return true;
107 }
108 }
109
110 int main(int argc, char *argv[])
111 {
112 SDL_SetEventFilter(HandleAppEvents, NULL);
113
114 ... run your main loop
115
116 return 0;
117 }
118
119
120Note that if you are using main callbacks instead of a standard C main() function, your SDL_AppEvent() callback will run as these events arrive and you do not need to use SDL_SetEventFilter.
121
122
123Notes -- Keyboard
124==============================================================================
125
126The SDL keyboard API has been extended to support on-screen keyboards:
127
128void SDL_StartTextInput()
129 -- enables text events and reveals the onscreen keyboard.
130
131void SDL_StopTextInput()
132 -- disables text events and hides the onscreen keyboard.
133
134bool SDL_TextInputActive()
135 -- returns whether or not text events are enabled (and the onscreen keyboard is visible)
136
137
138Notes -- Mouse
139==============================================================================
140
141iOS now supports Bluetooth mice on iPad, but by default will provide the mouse input as touch. In order for SDL to see the real mouse events, you should set the key UIApplicationSupportsIndirectInputEvents to true in your Info.plist
142
143From iOS 17 onward, the key now defaults to true.
144
145
146Notes -- Reading and Writing files
147==============================================================================
148
149Each application installed on iPhone resides in a sandbox which includes its own application home directory. Your application may not access files outside this directory.
150
151When your SDL based iPhone application starts up, it sets the working directory to the main bundle, where your application resources are stored. You cannot write to this directory. Instead, you should write document files to the directory returned by SDL_GetUserFolder(SDL_FOLDER_DOCUMENTS) and preferences to the directory returned by SDL_GetPrefPath().
152
153More information on this subject is available here:
154http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Introduction/Introduction.html
155
156
157Notes -- xcFramework
158==============================================================================
159
160The SDL.xcodeproj file now includes a target to build SDL3.xcframework. An xcframework is a new (Xcode 11) uber-framework which can handle any combination of processor type and target OS platform.
161
162In the past, iOS devices were always an ARM variant processor, and the simulator was always i386 or x86_64, and thus libraries could be combined into a single framework for both simulator and device. With the introduction of the Apple Silicon ARM-based machines, regular frameworks would collide as CPU type was no longer sufficient to differentiate the platform. So Apple created the new xcframework library package.
163
164The xcframework target builds into a Products directory alongside the SDL.xcodeproj file, as SDL3.xcframework. This can be brought in to any iOS project and will function properly for both simulator and device, no matter their CPUs. Note that Intel Macs cannot cross-compile for Apple Silicon Macs. If you need AS compatibility, perform this build on an Apple Silicon Mac.
165
166This target requires Xcode 11 or later. The target will simply fail to build if attempted on older Xcodes.
167
168In addition, on Apple platforms, main() cannot be in a dynamically loaded library.
169However, unlike in SDL2, in SDL3 SDL_main is implemented inline in SDL_main.h, so you don't need to link against a static libSDL3main.lib, and you don't need to copy a .c file from the SDL3 source either.
170This means that iOS apps which used the statically-linked libSDL3.lib and now link with the xcframwork can just `#include <SDL3/SDL_main.h>` in the source file that contains their standard `int main(int argc, char *argv[])` function to get a header-only SDL_main implementation that calls the `SDL_RunApp()` with your standard main function.
171
172Using an xcFramework is similar to using a regular framework. However, issues have been seen with the build system not seeing the headers in the xcFramework. To remedy this, add the path to the xcFramework in your app's target ==> Build Settings ==> Framework Search Paths and mark it recursive (this is critical). Also critical is to remove "*.framework" from Build Settings ==> Sub-Directories to Exclude in Recursive Searches. Clean the build folder, and on your next build the build system should be able to see any of these in your code, as expected:
173
174#include "SDL_main.h"
175#include <SDL.h>
176#include <SDL_main.h>
177
178
179Notes -- iPhone SDL limitations
180==============================================================================
181
182Windows:
183 Full-size, single window applications only. You cannot create multi-window SDL applications for iPhone OS. The application window will fill the display, though you have the option of turning on or off the menu-bar (pass SDL_CreateWindow() the flag SDL_WINDOW_BORDERLESS).
184
185Textures:
186 The optimal texture formats on iOS are SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_XBGR8888, and SDL_PIXELFORMAT_RGB24 pixel formats.
187
188
189Notes -- CoreBluetooth.framework
190==============================================================================
191
192SDL_JOYSTICK_HIDAPI is disabled by default. It can give you access to a lot
193more game controller devices, but it requires permission from the user before
194your app will be able to talk to the Bluetooth hardware. "Made For iOS"
195branded controllers do not need this as we don't have to speak to them
196directly with raw bluetooth, so many apps can live without this.
197
198You'll need to link with CoreBluetooth.framework and add something like this
199to your Info.plist:
200
201<key>NSBluetoothPeripheralUsageDescription</key>
202<string>MyApp would like to remain connected to nearby bluetooth Game Controllers and Game Pads even when you're not using the app.</string>
203
204
205Game Center
206==============================================================================
207
208Game Center integration might require that you break up your main loop in order to yield control back to the system. In other words, instead of running an endless main loop, you run each frame in a callback function, using:
209
210 bool SDL_SetiOSAnimationCallback(SDL_Window * window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam);
211
212This will set up the given function to be called back on the animation callback, and then you have to return from main() to let the Cocoa event loop run.
213
214e.g.
215
216 extern "C"
217 void ShowFrame(void*)
218 {
219 ... do event handling, frame logic and rendering ...
220 }
221
222 int main(int argc, char *argv[])
223 {
224 ... initialize game ...
225
226 #ifdef SDL_PLATFORM_IOS
227 // Initialize the Game Center for scoring and matchmaking
228 InitGameCenter();
229
230 // Set up the game to run in the window animation callback on iOS
231 // so that Game Center and so forth works correctly.
232 SDL_SetiOSAnimationCallback(window, 1, ShowFrame, NULL);
233 #else
234 while ( running ) {
235 ShowFrame(0);
236 DelayFrame();
237 }
238 #endif
239 return 0;
240 }
241
242
243Note that if you are using main callbacks instead of a standard C main() function, your SDL_AppIterate() callback is already doing this and you don't need to use SDL_SetiOSAnimationCallback.
244
245
246Deploying to older versions of iOS
247==============================================================================
248
249SDL supports deploying to older versions of iOS than are supported by the latest version of Xcode, all the way back to iOS 11.0
250
251In order to do that you need to download an older version of Xcode:
252https://developer.apple.com/download/more/?name=Xcode
253
254Open the package contents of the older Xcode and your newer version of Xcode and copy over the folders in Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
255
256Then open the file Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/SDKSettings.plist and add the versions of iOS you want to deploy to the key Root/DefaultProperties/DEPLOYMENT_TARGET_SUGGESTED_VALUES
257
258Open your project and set your deployment target to the desired version of iOS
259
260Finally, remove GameController from the list of frameworks linked by your application and edit the build settings for "Other Linker Flags" and add -weak_framework GameController