4 ==============================================================================
5 Building the Simple DirectMedia Layer
for iOS 5.1+
6 ==============================================================================
8 Requirements: Mac OS X 10.8 or later and the iOS 7+ SDK.
12 1. Open SDL.xcodeproj (located
in Xcode-iOS/SDL)
in Xcode.
13 2. Select your desired
target, and hit build.
15 There are three build targets:
17 Build SDL as
a statically linked library
19 Build
a test
program (there are known test failures which are fine)
21 Package
a project
template together with the SDL
for iPhone
static libraries and copies of the SDL headers. The
template includes proper references to the SDL library and headers, skeleton code
for a basic SDL
program, and placeholder graphics
for the application icon and startup
screen.
24 ==============================================================================
25 Build SDL
for iOS from the command line
26 ==============================================================================
28 1. cd (PATH WHERE THE SDL CODE IS)/build-scripts
31 If everything goes fine, you should see
a build/ios directory, inside there
's
32 two directories "lib" and "include".
33 "include" contains a copy of the SDL headers that you'll need
for your project,
34 make sure to configure XCode to look
for headers there.
35 "lib" contains find
two files, libSDL2.a and libSDL2main.a, you have to add both
36 to your XCode project. These libraries contain three architectures
in them,
37 armv6
for legacy
devices, armv7, and i386 (
for the simulator).
38 By
default, iosbuild.sh will autodetect the SDK version you have installed
using
39 xcodebuild -showsdks, and build
for iOS >= 3.0, you can
override this behaviour
42 MIN_OS_VERSION=4.2 ./iosbuild.sh
44 ==============================================================================
45 Using the Simple DirectMedia Layer
for iOS
46 ==============================================================================
48 FIXME: This needs to be updated
for the latest methods
50 Here is the easiest method:
51 1. Build the SDL library (libSDL2.a) and the iPhone SDL Application template.
52 2. Install the iPhone SDL Application template
by copying it to
one of Xcode'
s template directories.
I recommend creating
a directory called "SDL"
in "/Developer/Platforms/iOS.platform/Developer/Library/Xcode/Project Templates/" and placing it there.
53 3. Start
a new project using the template. The project should be immediately ready for use with SDL.
55 Here is
a more manual method:
56 1. Create
a new iOS view based application.
57 2. Build the SDL static library (libSDL2.
a) for iOS and include them
in your project. Xcode will ignore the library that is not currently of the correct architecture, hence your app will work both on iOS and
in the iOS Simulator.
58 3. Include the SDL header files
in your project.
59 4. Remove the ApplicationDelegate.
h and ApplicationDelegate.
m files -- SDL for iOS provides its own UIApplicationDelegate. Remove MainWindow.xib -- SDL for iOS produces its user interface programmatically.
60 5. Delete the contents of
main.
m and program your app as
a regular SDL program instead. You may replace
main.
m with your own
main.
c, but you must tell Xcode not to use the project prefix file, as it includes Objective-C code.
62 ==============================================================================
64 ==============================================================================
68 created on an iPhone 6 will have
a size in screen coordinates of 375
x 667,
69 rather than
a size in pixels of 750 x 1334. All iOS apps are expected to
71 as this allows different iOS devices to have different pixel densities
72 (Retina versus non-Retina screens, etc.) without apps caring too much.
74 By default SDL will not use the full pixel density of the
screen on
79 will still be
in "
screen coordinates" rather than pixels, but the
window will
80 have
a much greater pixel density when the
device supports it, and the
82 whether raw OpenGL or the SDL_Render API is used) can be queried to determine
86 sizes in screen coordinates. When doing 2D rendering with OpenGL ES, an
89 no matter whether
a Retina
device is used or not.
91 ==============================================================================
92 Notes -- Application
events
93 ==============================================================================
95 On iOS the application goes through
a fixed life cycle and you will
get
98 not give you any processing
time after the
events are delivered.
144 int main(
int argc,
char *argv[])
154 ==============================================================================
155 Notes -- Accelerometer as Joystick
156 ==============================================================================
158 SDL
for iPhone supports polling the built
in accelerometer as
a joystick
device. For an example on how to
do this, see the accelerometer.c
in the demos directory.
162 ==============================================================================
164 ==============================================================================
166 Your SDL application for iOS uses OpenGL ES for video
by default.
168 OpenGL ES for iOS supports several display pixel
formats, such as RGBA8 and RGB565, which provide
a 32 bit and 16 bit
color buffer respectively. By default, the implementation uses RGB565, but you may use RGBA8
by setting each
color component to 8
bits in SDL_GL_SetAttribute().
174 OpenGL ES on iOS doesn'
t use the traditional system-
framebuffer setup provided
in other operating systems. Special care must be taken because of this:
177 - The drawable Framebuffer Object must be bound while rendering to the
screen and when
SDL_GL_SwapWindow() is called.
182 ==============================================================================
184 ==============================================================================
186 The SDL keyboard API has been extended to support on-screen keyboards:
189 -- enables
text events and reveals the onscreen keyboard.
192 -- disables
text events and hides the onscreen keyboard.
195 -- returns whether or not
text events are enabled (and the onscreen keyboard is visible)
198 ==============================================================================
199 Notes -- Reading and Writing files
200 ==============================================================================
202 Each application installed on iPhone resides
in a sandbox which includes its own Application Home directory. Your application may not
access files outside this directory.
204 Once your application is installed its directory tree looks like:
213 When your SDL based iPhone application starts up, it sets the working directory to the
main bundle (MySDLApp Home/MySDLApp.app), where your application resources are stored. You cannot write to this directory. Instead,
I advise you to write document files to "../Documents/" and preferences to "../Library/Preferences".
215 More information on this subject is
available here:
218 ==============================================================================
219 Notes -- iPhone SDL limitations
220 ==============================================================================
228 Loading Shared Objects:
229 This is disabled
by default since it seems to break the terms of the iOS SDK agreement for iOS versions prior to iOS 8. It can be re-enabled
in SDL_config_iphoneos.
h.
231 ==============================================================================
233 ==============================================================================
235 Game 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:
239 This 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.
244 void ShowFrame(
void*)
246 ...
do event handling, frame logic and rendering ...
249 int main(
int argc,
char *argv[])
251 ... initialize game ...
269 ==============================================================================
270 Deploying to older versions of iOS
271 ==============================================================================
273 SDL supports deploying to older versions of iOS than are supported
by the latest version of Xcode, all the way back to iOS 6.1
275 In
order to
do that you need to download an older version of Xcode:
278 Open 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
280 Then 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
282 Open your project and set your deployment target to the desired version of iOS
284 Finally, 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