README-android.md
1Android
2================================================================================
3
4Requirements:
5
6Android SDK (version 12 or later)
7http://developer.android.com/sdk/index.html
8
9Android NDK r7 or later
10http://developer.android.com/tools/sdk/ndk/index.html
11
12Minimum API level supported by SDL: 10 (Android 2.3.3)
13Joystick support is available for API level >=12 devices.
14
15================================================================================
16 How the port works
17================================================================================
18
19- Android applications are Java-based, optionally with parts written in C
20- As SDL apps are C-based, we use a small Java shim that uses JNI to talk to
21 the SDL library
22- This means that your application C code must be placed inside an Android
23 Java project, along with some C support code that communicates with Java
24- This eventually produces a standard Android .apk package
25
26The Android Java code implements an "Activity" and can be found in:
27android-project/src/org/libsdl/app/SDLActivity.java
28
29The Java code loads your game code, the SDL shared library, and
30dispatches to native functions implemented in the SDL library:
31src/core/android/SDL_android.c
32
33Your project must include some glue code that starts your main() routine:
34src/main/android/SDL_android_main.c
35
36
37================================================================================
38 Building an app
39================================================================================
40
41For simple projects you can use the script located at build-scripts/androidbuild.sh
42
43There's two ways of using it:
44
45 androidbuild.sh com.yourcompany.yourapp < sources.list
46 androidbuild.sh com.yourcompany.yourapp source1.c source2.c ...sourceN.c
47
48sources.list should be a text file with a source file name in each line
49Filenames should be specified relative to the current directory, for example if
50you are in the build-scripts directory and want to create the testgles.c test, you'll
51run:
52
53 ./androidbuild.sh org.libsdl.testgles ../test/testgles.c
54
55One limitation of this script is that all sources provided will be aggregated into
56a single directory, thus all your source files should have a unique name.
57
58Once the project is complete the script will tell you where the debug APK is located.
59If you want to create a signed release APK, you can use the project created by this
60utility to generate it.
61
62Finally, a word of caution: re running androidbuild.sh wipes any changes you may have
63done in the build directory for the app!
64
65
66For more complex projects, follow these instructions:
67
681. Copy the android-project directory wherever you want to keep your projects
69 and rename it to the name of your project.
702. Move or symlink this SDL directory into the "<project>/jni" directory
713. Edit "<project>/jni/src/Android.mk" to include your source files
724. Run 'ndk-build' (a script provided by the NDK). This compiles the C source
73
74If you want to use the Eclipse IDE, skip to the Eclipse section below.
75
765. Create "<project>/local.properties" and use that to point to the Android SDK directory, by writing a line with the following form:
77
78 sdk.dir=PATH_TO_ANDROID_SDK
79
806. Run 'ant debug' in android/project. This compiles the .java and eventually
81 creates a .apk with the native code embedded
827. 'ant debug install' will push the apk to the device or emulator (if connected)
83
84Here's an explanation of the files in the Android project, so you can customize them:
85
86 android-project/
87 AndroidManifest.xml - package manifest. Among others, it contains the class name
88 of the main Activity and the package name of the application.
89 build.properties - empty
90 build.xml - build description file, used by ant. The actual application name
91 is specified here.
92 default.properties - holds the target ABI for the application, android-10 and up
93 project.properties - holds the target ABI for the application, android-10 and up
94 local.properties - holds the SDK path, you should change this to the path to your SDK
95 jni/ - directory holding native code
96 jni/Android.mk - Android makefile that can call recursively the Android.mk files
97 in all subdirectories
98 jni/SDL/ - (symlink to) directory holding the SDL library files
99 jni/SDL/Android.mk - Android makefile for creating the SDL shared library
100 jni/src/ - directory holding your C/C++ source
101 jni/src/Android.mk - Android makefile that you should customize to include your
102 source code and any library references
103 res/ - directory holding resources for your application
104 res/drawable-* - directories holding icons for different phone hardware. Could be
105 one dir called "drawable".
106 res/layout/main.xml - Usually contains a file main.xml, which declares the screen layout.
107 We don't need it because we use the SDL video output.
108 res/values/strings.xml - strings used in your application, including the application name
109 shown on the phone.
110 src/org/libsdl/app/SDLActivity.java - the Java class handling the initialization and binding
111 to SDL. Be very careful changing this, as the SDL library relies
112 on this implementation.
113
114
115================================================================================
116 Build an app with static linking of libSDL
117================================================================================
118
119This build uses the Android NDK module system.
120
121Instructions:
1221. Copy the android-project directory wherever you want to keep your projects
123 and rename it to the name of your project.
1242. Rename "<project>/jni/src/Android_static.mk" to "<project>/jni/src/Android.mk"
125 (overwrite the existing one)
1263. Edit "<project>/jni/src/Android.mk" to include your source files
1274. create and export an environment variable named NDK_MODULE_PATH that points
128 to the parent directory of this SDL directory. e.g.:
129
130 export NDK_MODULE_PATH="$PWD"/..
131
1325. Edit "<project>/src/org/libsdl/app/SDLActivity.java" and remove the call to
133 System.loadLibrary("SDL2").
1346. Run 'ndk-build' (a script provided by the NDK). This compiles the C source
135
136
137================================================================================
138 Customizing your application name
139================================================================================
140
141To customize your application name, edit AndroidManifest.xml and replace
142"org.libsdl.app" with an identifier for your product package.
143
144Then create a Java class extending SDLActivity and place it in a directory
145under src matching your package, e.g.
146
147 src/com/gamemaker/game/MyGame.java
148
149Here's an example of a minimal class file:
150
151 --- MyGame.java --------------------------
152 package com.gamemaker.game;
153
154 import org.libsdl.app.SDLActivity;
155
156 /**
157 * A sample wrapper class that just calls SDLActivity
158 */
159
160 public class MyGame extends SDLActivity { }
161
162 ------------------------------------------
163
164Then replace "SDLActivity" in AndroidManifest.xml with the name of your
165class, .e.g. "MyGame"
166
167================================================================================
168 Customizing your application icon
169================================================================================
170
171Conceptually changing your icon is just replacing the "ic_launcher.png" files in
172the drawable directories under the res directory. There are four directories for
173different screen sizes. These can be replaced with one dir called "drawable",
174containing an icon file "ic_launcher.png" with dimensions 48x48 or 72x72.
175
176You may need to change the name of your icon in AndroidManifest.xml to match
177this icon filename.
178
179================================================================================
180 Loading assets
181================================================================================
182
183Any files you put in the "assets" directory of your android-project directory
184will get bundled into the application package and you can load them using the
185standard functions in SDL_rwops.h.
186
187There are also a few Android specific functions that allow you to get other
188useful paths for saving and loading data:
189* SDL_AndroidGetInternalStoragePath()
190* SDL_AndroidGetExternalStorageState()
191* SDL_AndroidGetExternalStoragePath()
192
193See SDL_system.h for more details on these functions.
194
195The asset packaging system will, by default, compress certain file extensions.
196SDL includes two asset file access mechanisms, the preferred one is the so
197called "File Descriptor" method, which is faster and doesn't involve the Dalvik
198GC, but given this method does not work on compressed assets, there is also the
199"Input Stream" method, which is automatically used as a fall back by SDL. You
200may want to keep this fact in mind when building your APK, specially when large
201files are involved.
202For more information on which extensions get compressed by default and how to
203disable this behaviour, see for example:
204
205http://ponystyle.com/blog/2010/03/26/dealing-with-asset-compression-in-android-apps/
206
207================================================================================
208 Pause / Resume behaviour
209================================================================================
210
211If SDL is compiled with SDL_ANDROID_BLOCK_ON_PAUSE defined (the default),
212the event loop will block itself when the app is paused (ie, when the user
213returns to the main Android dashboard). Blocking is better in terms of battery
214use, and it allows your app to spring back to life instantaneously after resume
215(versus polling for a resume message).
216
217Upon resume, SDL will attempt to restore the GL context automatically.
218In modern devices (Android 3.0 and up) this will most likely succeed and your
219app can continue to operate as it was.
220
221However, there's a chance (on older hardware, or on systems under heavy load),
222where the GL context can not be restored. In that case you have to listen for
223a specific message, (which is not yet implemented!) and restore your textures
224manually or quit the app (which is actually the kind of behaviour you'll see
225under iOS, if the OS can not restore your GL context it will just kill your app)
226
227================================================================================
228 Threads and the Java VM
229================================================================================
230
231For a quick tour on how Linux native threads interoperate with the Java VM, take
232a look here: http://developer.android.com/guide/practices/jni.html
233
234If you want to use threads in your SDL app, it's strongly recommended that you
235do so by creating them using SDL functions. This way, the required attach/detach
236handling is managed by SDL automagically. If you have threads created by other
237means and they make calls to SDL functions, make sure that you call
238Android_JNI_SetupThread() before doing anything else otherwise SDL will attach
239your thread automatically anyway (when you make an SDL call), but it'll never
240detach it.
241
242================================================================================
243 Using STL
244================================================================================
245
246You can use STL in your project by creating an Application.mk file in the jni
247folder and adding the following line:
248
249 APP_STL := stlport_static
250
251For more information check out CPLUSPLUS-SUPPORT.html in the NDK documentation.
252
253================================================================================
254 Additional documentation
255================================================================================
256
257The documentation in the NDK docs directory is very helpful in understanding the
258build process and how to work with native code on the Android platform.
259
260The best place to start is with docs/OVERVIEW.TXT
261
262
263================================================================================
264 Using Eclipse
265================================================================================
266
267First make sure that you've installed Eclipse and the Android extensions as described here:
268 http://developer.android.com/tools/sdk/eclipse-adt.html
269
270Once you've copied the SDL android project and customized it, you can create an Eclipse project from it:
271 * File -> New -> Other
272 * Select the Android -> Android Project wizard and click Next
273 * Enter the name you'd like your project to have
274 * Select "Create project from existing source" and browse for your project directory
275 * Make sure the Build Target is set to Android 3.1 (API 12)
276 * Click Finish
277
278
279================================================================================
280 Using the emulator
281================================================================================
282
283There are some good tips and tricks for getting the most out of the
284emulator here: http://developer.android.com/tools/devices/emulator.html
285
286Especially useful is the info on setting up OpenGL ES 2.0 emulation.
287
288Notice that this software emulator is incredibly slow and needs a lot of disk space.
289Using a real device works better.
290
291================================================================================
292 Troubleshooting
293================================================================================
294
295You can create and run an emulator from the Eclipse IDE:
296 * Window -> Android SDK and AVD Manager
297
298You can see if adb can see any devices with the following command:
299
300 adb devices
301
302You can see the output of log messages on the default device with:
303
304 adb logcat
305
306You can push files to the device with:
307
308 adb push local_file remote_path_and_file
309
310You can push files to the SD Card at /sdcard, for example:
311
312 adb push moose.dat /sdcard/moose.dat
313
314You can see the files on the SD card with a shell command:
315
316 adb shell ls /sdcard/
317
318You can start a command shell on the default device with:
319
320 adb shell
321
322You can remove the library files of your project (and not the SDL lib files) with:
323
324 ndk-build clean
325
326You can do a build with the following command:
327
328 ndk-build
329
330You can see the complete command line that ndk-build is using by passing V=1 on the command line:
331
332 ndk-build V=1
333
334If your application crashes in native code, you can use addr2line to convert the
335addresses in the stack trace to lines in your code.
336
337For example, if your crash looks like this:
338
339 I/DEBUG ( 31): signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 400085d0
340 I/DEBUG ( 31): r0 00000000 r1 00001000 r2 00000003 r3 400085d4
341 I/DEBUG ( 31): r4 400085d0 r5 40008000 r6 afd41504 r7 436c6a7c
342 I/DEBUG ( 31): r8 436c6b30 r9 435c6fb0 10 435c6f9c fp 4168d82c
343 I/DEBUG ( 31): ip 8346aff0 sp 436c6a60 lr afd1c8ff pc afd1c902 cpsr 60000030
344 I/DEBUG ( 31): #00 pc 0001c902 /system/lib/libc.so
345 I/DEBUG ( 31): #01 pc 0001ccf6 /system/lib/libc.so
346 I/DEBUG ( 31): #02 pc 000014bc /data/data/org.libsdl.app/lib/libmain.so
347 I/DEBUG ( 31): #03 pc 00001506 /data/data/org.libsdl.app/lib/libmain.so
348
349You can see that there's a crash in the C library being called from the main code.
350I run addr2line with the debug version of my code:
351
352 arm-eabi-addr2line -C -f -e obj/local/armeabi/libmain.so
353
354and then paste in the number after "pc" in the call stack, from the line that I care about:
355000014bc
356
357I get output from addr2line showing that it's in the quit function, in testspriteminimal.c, on line 23.
358
359You can add logging to your code to help show what's happening:
360
361 #include <android/log.h>
362
363 __android_log_print(ANDROID_LOG_INFO, "foo", "Something happened! x = %d", x);
364
365If you need to build without optimization turned on, you can create a file called
366"Application.mk" in the jni directory, with the following line in it:
367
368 APP_OPTIM := debug
369
370
371================================================================================
372 Memory debugging
373================================================================================
374
375The best (and slowest) way to debug memory issues on Android is valgrind.
376Valgrind has support for Android out of the box, just grab code using:
377
378 svn co svn://svn.valgrind.org/valgrind/trunk valgrind
379
380... and follow the instructions in the file README.android to build it.
381
382One thing I needed to do on Mac OS X was change the path to the toolchain,
383and add ranlib to the environment variables:
384export RANLIB=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-ranlib
385
386Once valgrind is built, you can create a wrapper script to launch your
387application with it, changing org.libsdl.app to your package identifier:
388
389 --- start_valgrind_app -------------------
390 #!/system/bin/sh
391 export TMPDIR=/data/data/org.libsdl.app
392 exec /data/local/Inst/bin/valgrind --log-file=/sdcard/valgrind.log --error-limit=no $*
393 ------------------------------------------
394
395Then push it to the device:
396
397 adb push start_valgrind_app /data/local
398
399and make it executable:
400
401 adb shell chmod 755 /data/local/start_valgrind_app
402
403and tell Android to use the script to launch your application:
404
405 adb shell setprop wrap.org.libsdl.app "logwrapper /data/local/start_valgrind_app"
406
407If the setprop command says "could not set property", it's likely that
408your package name is too long and you should make it shorter by changing
409AndroidManifest.xml and the path to your class file in android-project/src
410
411You can then launch your application normally and waaaaaaaiiittt for it.
412You can monitor the startup process with the logcat command above, and
413when it's done (or even while it's running) you can grab the valgrind
414output file:
415
416 adb pull /sdcard/valgrind.log
417
418When you're done instrumenting with valgrind, you can disable the wrapper:
419
420 adb shell setprop wrap.org.libsdl.app ""
421
422================================================================================
423 Graphics debugging
424================================================================================
425
426If you are developing on a compatible Tegra-based tablet, NVidia provides
427Tegra Graphics Debugger at their website. Because SDL2 dynamically loads EGL
428and GLES libraries, you must follow their instructions for installing the
429interposer library on a rooted device. The non-rooted instructions are not
430compatible with applications that use SDL2 for video.
431
432The Tegra Graphics Debugger is available from NVidia here:
433https://developer.nvidia.com/tegra-graphics-debugger
434
435================================================================================
436 Why is API level 10 the minimum required?
437================================================================================
438
439API level 10 is the minimum required level at runtime (that is, on the device)
440because SDL requires some functionality for running not
441available on older devices. Since the incorporation of joystick support into SDL,
442the minimum SDK required to *build* SDL is version 12. Devices running API levels
44310-11 are still supported, only with the joystick functionality disabled.
444
445Support for native OpenGL ES and ES2 applications was introduced in the NDK for
446API level 4 and 8. EGL was made a stable API in the NDK for API level 9, which
447has since then been obsoleted, with the recommendation to developers to bump the
448required API level to 10.
449As of this writing, according to http://developer.android.com/about/dashboards/index.html
450about 90% of the Android devices accessing Google Play support API level 10 or
451higher (March 2013).
452
453================================================================================
454 A note regarding the use of the "dirty rectangles" rendering technique
455================================================================================
456
457If your app uses a variation of the "dirty rectangles" rendering technique,
458where you only update a portion of the screen on each frame, you may notice a
459variety of visual glitches on Android, that are not present on other platforms.
460This is caused by SDL's use of EGL as the support system to handle OpenGL ES/ES2
461contexts, in particular the use of the eglSwapBuffers function. As stated in the
462documentation for the function "The contents of ancillary buffers are always
463undefined after calling eglSwapBuffers".
464Setting the EGL_SWAP_BEHAVIOR attribute of the surface to EGL_BUFFER_PRESERVED
465is not possible for SDL as it requires EGL 1.4, available only on the API level
46617+, so the only workaround available on this platform is to redraw the entire
467screen each frame.
468
469Reference: http://www.khronos.org/registry/egl/specs/EGLTechNote0001.html
470
471================================================================================
472 Known issues
473================================================================================
474
475- The number of buttons reported for each joystick is hardcoded to be 36, which
476is the current maximum number of buttons Android can report.
477
478
README-cmake.md
1CMake
2================================================================================
3(www.cmake.org)
4
5SDL's build system was traditionally based on autotools. Over time, this
6approach has suffered from several issues across the different supported
7platforms.
8To solve these problems, a new build system based on CMake is under development.
9It works in parallel to the legacy system, so users can experiment with it
10without complication.
11While still experimental, the build system should be usable on the following
12platforms:
13
14* FreeBSD
15* Linux
16* VS.NET 2010
17* MinGW and Msys
18* OS X with support for XCode
19
20
21================================================================================
22Usage
23================================================================================
24
25Assuming the source for SDL is located at ~/sdl
26
27 cd ~
28 mkdir build
29 cd build
30 cmake ../sdl
31
32This will build the static and dynamic versions of SDL in the ~/build directory.
33
README-directfb.md
1DirectFB
2========
3
4Supports:
5
6- Hardware YUV overlays
7- OpenGL - software only
8- 2D/3D accelerations (depends on directfb driver)
9- multiple displays
10- windows
11
12What you need:
13
14* DirectFB 1.0.1, 1.2.x, 1.3.0
15* Kernel-Framebuffer support: required: vesafb, radeonfb ....
16* Mesa 7.0.x - optional for OpenGL
17
18/etc/directfbrc
19
20This file should contain the following lines to make
21your joystick work and avoid crashes:
22------------------------
23disable-module=joystick
24disable-module=cle266
25disable-module=cyber5k
26no-linux-input-grab
27------------------------
28
29To disable to use x11 backend when DISPLAY variable is found use
30
31export SDL_DIRECTFB_X11_CHECK=0
32
33To disable the use of linux input devices, i.e. multimice/multikeyboard support,
34use
35
36export SDL_DIRECTFB_LINUX_INPUT=0
37
38To use hardware accelerated YUV-overlays for YUV-textures, use:
39
40export SDL_DIRECTFB_YUV_DIRECT=1
41
42This is disabled by default. It will only support one
43YUV texture, namely the first. Every other YUV texture will be
44rendered in software.
45
46In addition, you may use (directfb-1.2.x)
47
48export SDL_DIRECTFB_YUV_UNDERLAY=1
49
50to make the YUV texture an underlay. This will make the cursor to
51be shown.
52
53Simple Window Manager
54=====================
55
56The driver has support for a very, very basic window manager you may
57want to use when running with "wm=default". Use
58
59export SDL_DIRECTFB_WM=1
60
61to enable basic window borders. In order to have the window title rendered,
62you need to have the following font installed:
63
64/usr/share/fonts/truetype/freefont/FreeSans.ttf
65
66OpenGL Support
67==============
68
69The following instructions will give you *software* OpenGL. However this
70works at least on all directfb supported platforms.
71
72As of this writing 20100802 you need to pull Mesa from git and do the following:
73
74------------------------
75git clone git://anongit.freedesktop.org/git/mesa/mesa
76cd mesa
77git checkout 2c9fdaf7292423c157fc79b5ce43f0f199dd753a
78------------------------
79
80Edit configs/linux-directfb so that the Directories-section looks like
81------------------------
82# Directories
83SRC_DIRS = mesa glu
84GLU_DIRS = sgi
85DRIVER_DIRS = directfb
86PROGRAM_DIRS =
87------------------------
88
89make linux-directfb
90make
91
92echo Installing - please enter sudo pw.
93
94sudo make install INSTALL_DIR=/usr/local/dfb_GL
95cd src/mesa/drivers/directfb
96make
97sudo make install INSTALL_DIR=/usr/local/dfb_GL
98------------------------
99
100To run the SDL - testprograms:
101
102export SDL_VIDEODRIVER=directfb
103export LD_LIBRARY_PATH=/usr/local/dfb_GL/lib
104export LD_PRELOAD=/usr/local/dfb_GL/libGL.so.7
105
106./testgl
107
108
README-dynapi.md
1Dynamic API
2================================================================================
3Originally posted by Ryan at:
4 https://plus.google.com/103391075724026391227/posts/TB8UfnDYu4U
5
6Background:
7
8- The Steam Runtime has (at least in theory) a really kick-ass build of SDL2,
9 but developers are shipping their own SDL2 with individual Steam games.
10 These games might stop getting updates, but a newer SDL2 might be needed later.
11 Certainly we'll always be fixing bugs in SDL, even if a new video target isn't
12 ever needed, and these fixes won't make it to a game shipping its own SDL.
13- Even if we replace the SDL2 in those games with a compatible one, that is to
14 say, edit a developer's Steam depot (yuck!), there are developers that are
15 statically linking SDL2 that we can't do this for. We can't even force the
16 dynamic loader to ignore their SDL2 in this case, of course.
17- If you don't ship an SDL2 with the game in some form, people that disabled the
18 Steam Runtime, or just tried to run the game from the command line instead of
19 Steam might find themselves unable to run the game, due to a missing dependency.
20- If you want to ship on non-Steam platforms like GOG or Humble Bundle, or target
21 generic Linux boxes that may or may not have SDL2 installed, you have to ship
22 the library or risk a total failure to launch. So now, you might have to have
23 a non-Steam build plus a Steam build (that is, one with and one without SDL2
24 included), which is inconvenient if you could have had one universal build
25 that works everywhere.
26- We like the zlib license, but the biggest complaint from the open source
27 community about the license change is the static linking. The LGPL forced this
28 as a legal, not technical issue, but zlib doesn't care. Even those that aren't
29 concerned about the GNU freedoms found themselves solving the same problems:
30 swapping in a newer SDL to an older game often times can save the day.
31 Static linking stops this dead.
32
33So here's what we did:
34
35SDL now has, internally, a table of function pointers. So, this is what SDL_Init
36now looks like:
37
38 UInt32 SDL_Init(Uint32 flags)
39 {
40 return jump_table.SDL_Init(flags);
41 }
42
43Except that is all done with a bunch of macro magic so we don't have to maintain
44every one of these.
45
46What is jump_table.SDL_init()? Eventually, that's a function pointer of the real
47SDL_Init() that you've been calling all this time. But at startup, it looks more
48like this:
49
50 Uint32 SDL_Init_DEFAULT(Uint32 flags)
51 {
52 SDL_InitDynamicAPI();
53 return jump_table.SDL_Init(flags);
54 }
55
56SDL_InitDynamicAPI() fills in jump_table with all the actual SDL function
57pointers, which means that this _DEFAULT function never gets called again.
58First call to any SDL function sets the whole thing up.
59
60So you might be asking, what was the value in that? Isn't this what the operating
61system's dynamic loader was supposed to do for us? Yes, but now we've got this
62level of indirection, we can do things like this:
63
64 export SDL_DYNAMIC_API=/my/actual/libSDL-2.0.so.0
65 ./MyGameThatIsStaticallyLinkedToSDL2
66
67And now, this game that is staticallly linked to SDL, can still be overridden
68with a newer, or better, SDL. The statically linked one will only be used as
69far as calling into the jump table in this case. But in cases where no override
70is desired, the statically linked version will provide its own jump table,
71and everyone is happy.
72
73So now:
74- Developers can statically link SDL, and users can still replace it.
75 (We'd still rather you ship a shared library, though!)
76- Developers can ship an SDL with their game, Valve can override it for, say,
77 new features on SteamOS, or distros can override it for their own needs,
78 but it'll also just work in the default case.
79- Developers can ship the same package to everyone (Humble Bundle, GOG, etc),
80 and it'll do the right thing.
81- End users (and Valve) can update a game's SDL in almost any case,
82 to keep abandoned games running on newer platforms.
83- Everyone develops with SDL exactly as they have been doing all along.
84 Same headers, same ABI. Just get the latest version to enable this magic.
85
86
87A little more about SDL_InitDynamicAPI():
88
89Internally, InitAPI does some locking to make sure everything waits until a
90single thread initializes everything (although even SDL_CreateThread() goes
91through here before spinning a thread, too), and then decides if it should use
92an external SDL library. If not, it sets up the jump table using the current
93SDL's function pointers (which might be statically linked into a program, or in
94a shared library of its own). If so, it loads that library and looks for and
95calls a single function:
96
97 SInt32 SDL_DYNAPI_entry(Uint32 version, void *table, Uint32 tablesize);
98
99That function takes a version number (more on that in a moment), the address of
100the jump table, and the size, in bytes, of the table.
101Now, we've got policy here: this table's layout never changes; new stuff gets
102added to the end. Therefore SDL_DYNAPI_entry() knows that it can provide all
103the needed functions if tablesize <= sizeof its own jump table. If tablesize is
104bigger (say, SDL 2.0.4 is trying to load SDL 2.0.3), then we know to abort, but
105if it's smaller, we know we can provide the entire API that the caller needs.
106
107The version variable is a failsafe switch.
108Right now it's always 1. This number changes when there are major API changes
109(so we know if the tablesize might be smaller, or entries in it have changed).
110Right now SDL_DYNAPI_entry gives up if the version doesn't match, but it's not
111inconceivable to have a small dispatch library that only supplies this one
112function and loads different, otherwise-incompatible SDL libraries and has the
113right one initialize the jump table based on the version. For something that
114must generically catch lots of different versions of SDL over time, like the
115Steam Client, this isn't a bad option.
116
117Finally, I'm sure some people are reading this and thinking,
118"I don't want that overhead in my project!"
119To which I would point out that the extra function call through the jump table
120probably wouldn't even show up in a profile, but lucky you: this can all be
121disabled. You can build SDL without this if you absolutely must, but we would
122encourage you not to do that. However, on heavily locked down platforms like
123iOS, or maybe when debugging, it makes sense to disable it. The way this is
124designed in SDL, you just have to change one #define, and the entire system
125vaporizes out, and SDL functions exactly like it always did. Most of it is
126macro magic, so the system is contained to one C file and a few headers.
127However, this is on by default and you have to edit a header file to turn it
128off. Our hopes is that if we make it easy to disable, but not too easy,
129everyone will ultimately be able to get what they want, but we've gently
130nudged everyone towards what we think is the best solution.
131
README-gesture.md
1Dollar Gestures
2===========================================================================
3SDL provides an implementation of the $1 gesture recognition system. This allows for recording, saving, loading, and performing single stroke gestures.
4
5Gestures can be performed with any number of fingers (the centroid of the fingers must follow the path of the gesture), but the number of fingers must be constant (a finger cannot go down in the middle of a gesture). The path of a gesture is considered the path from the time when the final finger went down, to the first time any finger comes up.
6
7Dollar gestures are assigned an Id based on a hash function. This is guaranteed to remain constant for a given gesture. There is a (small) chance that two different gestures will be assigned the same ID. In this case, simply re-recording one of the gestures should result in a different ID.
8
9Recording:
10----------
11To begin recording on a touch device call:
12SDL_RecordGesture(SDL_TouchID touchId), where touchId is the id of the touch device you wish to record on, or -1 to record on all connected devices.
13
14Recording terminates as soon as a finger comes up. Recording is acknowledged by an SDL_DOLLARRECORD event.
15A SDL_DOLLARRECORD event is a dgesture with the following fields:
16
17* event.dgesture.touchId - the Id of the touch used to record the gesture.
18* event.dgesture.gestureId - the unique id of the recorded gesture.
19
20
21Performing:
22-----------
23As long as there is a dollar gesture assigned to a touch, every finger-up event will also cause an SDL_DOLLARGESTURE event with the following fields:
24
25* event.dgesture.touchId - the Id of the touch which performed the gesture.
26* event.dgesture.gestureId - the unique id of the closest gesture to the performed stroke.
27* event.dgesture.error - the difference between the gesture template and the actual performed gesture. Lower error is a better match.
28* event.dgesture.numFingers - the number of fingers used to draw the stroke.
29
30Most programs will want to define an appropriate error threshold and check to be sure that the error of a gesture is not abnormally high (an indicator that no gesture was performed).
31
32
33
34Saving:
35-------
36To save a template, call SDL_SaveDollarTemplate(gestureId, dst) where gestureId is the id of the gesture you want to save, and dst is an SDL_RWops pointer to the file where the gesture will be stored.
37
38To save all currently loaded templates, call SDL_SaveAllDollarTemplates(dst) where dst is an SDL_RWops pointer to the file where the gesture will be stored.
39
40Both functions return the number of gestures successfully saved.
41
42
43Loading:
44--------
45To load templates from a file, call SDL_LoadDollarTemplates(touchId,src) where touchId is the id of the touch to load to (or -1 to load to all touch devices), and src is an SDL_RWops pointer to a gesture save file.
46
47SDL_LoadDollarTemplates returns the number of templates successfully loaded.
48
49
50
51===========================================================================
52Multi Gestures
53===========================================================================
54SDL provides simple support for pinch/rotate/swipe gestures.
55Every time a finger is moved an SDL_MULTIGESTURE event is sent with the following fields:
56
57* event.mgesture.touchId - the Id of the touch on which the gesture was performed.
58* event.mgesture.x - the normalized x coordinate of the gesture. (0..1)
59* event.mgesture.y - the normalized y coordinate of the gesture. (0..1)
60* event.mgesture.dTheta - the amount that the fingers rotated during this motion.
61* event.mgesture.dDist - the amount that the fingers pinched during this motion.
62* event.mgesture.numFingers - the number of fingers used in the gesture.
63
64
65===========================================================================
66Notes
67===========================================================================
68For a complete example see test/testgesture.c
69
70Please direct questions/comments to:
71 jim.tla+sdl_touch@gmail.com
72
README-hg.md
1Mercurial
2=========
3
4The latest development version of SDL is available via Mercurial.
5Mercurial allows you to get up-to-the-minute fixes and enhancements;
6as a developer works on a source tree, you can use "hg" to mirror that
7source tree instead of waiting for an official release. Please look
8at the Mercurial website ( http://mercurial.selenic.com/ ) for more
9information on using hg, where you can also download software for
10Mac OS X, Windows, and Unix systems.
11
12 hg clone http://hg.libsdl.org/SDL
13
14If you are building SDL with an IDE, you will need to copy the file
15include/SDL_config.h.default to include/SDL_config.h before building.
16
17If you are building SDL via configure, you will need to run autogen.sh
18before running configure.
19
20There is a web interface to the subversion repository at:
21 http://hg.libsdl.org/SDL/
22
23There is an RSS feed available at that URL, for those that want to
24track commits in real time.
25
26
README-ios.md
1iOS
2======
3
4==============================================================================
5Building the Simple DirectMedia Layer for iOS 5.1+
6==============================================================================
7
8Requirements: Mac OS X 10.8 or later and the iOS 7+ SDK.
9
10Instructions:
111. Open SDL.xcodeproj (located in Xcode-iOS/SDL) in Xcode.
122. Select your desired target, and hit build.
13
14There are three build targets:
15- libSDL.a:
16 Build SDL as a statically linked library
17- testsdl:
18 Build a test program (there are known test failures which are fine)
19- Template:
20 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.
21
22
23==============================================================================
24Build SDL for iOS from the command line
25==============================================================================
26
271. cd (PATH WHERE THE SDL CODE IS)/build-scripts
282. ./iosbuild.sh
29
30If everything goes fine, you should see a build/ios directory, inside there's
31two directories "lib" and "include".
32"include" contains a copy of the SDL headers that you'll need for your project,
33make sure to configure XCode to look for headers there.
34"lib" contains find two files, libSDL2.a and libSDL2main.a, you have to add both
35to your XCode project. These libraries contain three architectures in them,
36armv6 for legacy devices, armv7, and i386 (for the simulator).
37By default, iosbuild.sh will autodetect the SDK version you have installed using
38xcodebuild -showsdks, and build for iOS >= 3.0, you can override this behaviour
39by setting the MIN_OS_VERSION variable, ie:
40
41MIN_OS_VERSION=4.2 ./iosbuild.sh
42
43==============================================================================
44Using the Simple DirectMedia Layer for iOS
45==============================================================================
46
47FIXME: This needs to be updated for the latest methods
48
49Here is the easiest method:
501. Build the SDL library (libSDL2.a) and the iPhone SDL Application template.
512. 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.
523. Start a new project using the template. The project should be immediately ready for use with SDL.
53
54Here is a more manual method:
551. Create a new iOS view based application.
562. 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.
573. Include the SDL header files in your project.
584. 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.
595. 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.
60
61==============================================================================
62Notes -- Retina / High-DPI and window sizes
63==============================================================================
64
65Window and display mode sizes in SDL are in "screen coordinates" (or "points",
66in Apple's terminology) rather than in pixels. On iOS this means that a window
67created on an iPhone 6 will have a size in screen coordinates of 375 x 667,
68rather than a size in pixels of 750 x 1334. All iOS apps are expected to
69size their content based on screen coordinates / points rather than pixels,
70as this allows different iOS devices to have different pixel densities
71(Retina versus non-Retina screens, etc.) without apps caring too much.
72
73By default SDL will not use the full pixel density of the screen on
74Retina/high-dpi capable devices. Use the SDL_WINDOW_ALLOW_HIGHDPI flag when
75creating your window to enable high-dpi support.
76
77When high-dpi support is enabled, SDL_GetWindowSize() and display mode sizes
78will still be in "screen coordinates" rather than pixels, but the window will
79have a much greater pixel density when the device supports it, and the
80SDL_GL_GetDrawableSize() or SDL_GetRendererOutputSize() functions (depending on
81whether raw OpenGL or the SDL_Render API is used) can be queried to determine
82the size in pixels of the drawable screen framebuffer.
83
84Some OpenGL ES functions such as glViewport expect sizes in pixels rather than
85sizes in screen coordinates. When doing 2D rendering with OpenGL ES, an
86orthographic projection matrix using the size in screen coordinates
87(SDL_GetWindowSize()) can be used in order to display content at the same scale
88no matter whether a Retina device is used or not.
89
90==============================================================================
91Notes -- Application events
92==============================================================================
93
94On iOS the application goes through a fixed life cycle and you will get
95notifications of state changes via application events. When these events
96are delivered you must handle them in an event callback because the OS may
97not give you any processing time after the events are delivered.
98
99e.g.
100
101 int HandleAppEvents(void *userdata, SDL_Event *event)
102 {
103 switch (event->type)
104 {
105 case SDL_APP_TERMINATING:
106 /* Terminate the app.
107 Shut everything down before returning from this function.
108 */
109 return 0;
110 case SDL_APP_LOWMEMORY:
111 /* You will get this when your app is paused and iOS wants more memory.
112 Release as much memory as possible.
113 */
114 return 0;
115 case SDL_APP_WILLENTERBACKGROUND:
116 /* Prepare your app to go into the background. Stop loops, etc.
117 This gets called when the user hits the home button, or gets a call.
118 */
119 return 0;
120 case SDL_APP_DIDENTERBACKGROUND:
121 /* This will get called if the user accepted whatever sent your app to the background.
122 If the user got a phone call and canceled it, you'll instead get an SDL_APP_DIDENTERFOREGROUND event and restart your loops.
123 When you get this, you have 5 seconds to save all your state or the app will be terminated.
124 Your app is NOT active at this point.
125 */
126 return 0;
127 case SDL_APP_WILLENTERFOREGROUND:
128 /* This call happens when your app is coming back to the foreground.
129 Restore all your state here.
130 */
131 return 0;
132 case SDL_APP_DIDENTERFOREGROUND:
133 /* Restart your loops here.
134 Your app is interactive and getting CPU again.
135 */
136 return 0;
137 default:
138 /* No special processing, add it to the event queue */
139 return 1;
140 }
141 }
142
143 int main(int argc, char *argv[])
144 {
145 SDL_SetEventFilter(HandleAppEvents, NULL);
146
147 ... run your main loop
148
149 return 0;
150 }
151
152
153==============================================================================
154Notes -- Accelerometer as Joystick
155==============================================================================
156
157SDL 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.
158
159The main thing to note when using the accelerometer with SDL is that while the iPhone natively reports accelerometer as floating point values in units of g-force, SDL_JoystickGetAxis() reports joystick values as signed integers. Hence, in order to convert between the two, some clamping and scaling is necessary on the part of the iPhone SDL joystick driver. To convert SDL_JoystickGetAxis() reported values BACK to units of g-force, simply multiply the values by SDL_IPHONE_MAX_GFORCE / 0x7FFF.
160
161==============================================================================
162Notes -- OpenGL ES
163==============================================================================
164
165Your SDL application for iOS uses OpenGL ES for video by default.
166
167OpenGL 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().
168
169If your application doesn't use OpenGL's depth buffer, you may find significant performance improvement by setting SDL_GL_DEPTH_SIZE to 0.
170
171Finally, if your application completely redraws the screen each frame, you may find significant performance improvement by setting the attribute SDL_GL_RETAINED_BACKING to 0.
172
173OpenGL ES on iOS doesn't use the traditional system-framebuffer setup provided in other operating systems. Special care must be taken because of this:
174
175- The drawable Renderbuffer must be bound to the GL_RENDERBUFFER binding point when SDL_GL_SwapWindow() is called.
176- The drawable Framebuffer Object must be bound while rendering to the screen and when SDL_GL_SwapWindow() is called.
177- If multisample antialiasing (MSAA) is used and glReadPixels is used on the screen, the drawable framebuffer must be resolved to the MSAA resolve framebuffer (via glBlitFramebuffer or glResolveMultisampleFramebufferAPPLE), and the MSAA resolve framebuffer must be bound to the GL_READ_FRAMEBUFFER binding point, before glReadPixels is called.
178
179The above objects can be obtained via SDL_GetWindowWMInfo() (in SDL_syswm.h).
180
181==============================================================================
182Notes -- Keyboard
183==============================================================================
184
185The SDL keyboard API has been extended to support on-screen keyboards:
186
187void SDL_StartTextInput()
188 -- enables text events and reveals the onscreen keyboard.
189
190void SDL_StopTextInput()
191 -- disables text events and hides the onscreen keyboard.
192
193SDL_bool SDL_IsTextInputActive()
194 -- returns whether or not text events are enabled (and the onscreen keyboard is visible)
195
196
197==============================================================================
198Notes -- Reading and Writing files
199==============================================================================
200
201Each application installed on iPhone resides in a sandbox which includes its own Application Home directory. Your application may not access files outside this directory.
202
203Once your application is installed its directory tree looks like:
204
205 MySDLApp Home/
206 MySDLApp.app
207 Documents/
208 Library/
209 Preferences/
210 tmp/
211
212When 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".
213
214More information on this subject is available here:
215http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Introduction/Introduction.html
216
217==============================================================================
218Notes -- iPhone SDL limitations
219==============================================================================
220
221Windows:
222 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).
223
224Textures:
225 The optimal texture formats on iOS are SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, and SDL_PIXELFORMAT_RGB24 pixel formats.
226
227Loading Shared Objects:
228 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.
229
230==============================================================================
231Game Center
232==============================================================================
233
234Game 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:
235
236 int SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam);
237
238This 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.
239
240e.g.
241
242 extern "C"
243 void ShowFrame(void*)
244 {
245 ... do event handling, frame logic and rendering ...
246 }
247
248 int main(int argc, char *argv[])
249 {
250 ... initialize game ...
251
252 #if __IPHONEOS__
253 // Initialize the Game Center for scoring and matchmaking
254 InitGameCenter();
255
256 // Set up the game to run in the window animation callback on iOS
257 // so that Game Center and so forth works correctly.
258 SDL_iPhoneSetAnimationCallback(window, 1, ShowFrame, NULL);
259 #else
260 while ( running ) {
261 ShowFrame(0);
262 DelayFrame();
263 }
264 #endif
265 return 0;
266 }
267
README-linux.md
1Linux
2================================================================================
3
4By default SDL will only link against glibc, the rest of the features will be
5enabled dynamically at runtime depending on the available features on the target
6system. So, for example if you built SDL with Xinerama support and the target
7system does not have the Xinerama libraries installed, it will be disabled
8at runtime, and you won't get a missing library error, at least with the
9default configuration parameters.
10
11
12================================================================================
13Build Dependencies
14================================================================================
15
16Ubuntu 13.04, all available features enabled:
17
18sudo apt-get install build-essential mercurial make cmake autoconf automake \
19libtool libasound2-dev libpulse-dev libaudio-dev libx11-dev libxext-dev \
20libxrandr-dev libxcursor-dev libxi-dev libxinerama-dev libxxf86vm-dev \
21libxss-dev libgl1-mesa-dev libesd0-dev libdbus-1-dev libudev-dev \
22libgles1-mesa-dev libgles2-mesa-dev libegl1-mesa-dev libibus-1.0-dev \
23fcitx-libs-dev
24
25Ubuntu 16.04 can also add "libwayland-dev libxkbcommon-dev wayland-protocols"
26to that command line for Wayland support.
27
28Ubuntu 16.10 can also add "libmirclient-dev libxkbcommon-dev" to that command
29line for Mir support.
30
31NOTES:
32- This includes all the audio targets except arts, because Ubuntu pulled the
33 artsc0-dev package, but in theory SDL still supports it.
34- DirectFB isn't included because the configure script (currently) fails to find
35 it at all. You can do "sudo apt-get install libdirectfb-dev" and fix the
36 configure script to include DirectFB support. Send patches. :)
37
38
39================================================================================
40Joystick does not work
41================================================================================
42
43If you compiled or are using a version of SDL with udev support (and you should!)
44there's a few issues that may cause SDL to fail to detect your joystick. To
45debug this, start by installing the evtest utility. On Ubuntu/Debian:
46
47 sudo apt-get install evtest
48
49Then run:
50
51 sudo evtest
52
53You'll hopefully see your joystick listed along with a name like "/dev/input/eventXX"
54Now run:
55
56 cat /dev/input/event/XX
57
58If you get a permission error, you need to set a udev rule to change the mode of
59your device (see below)
60
61Also, try:
62
63 sudo udevadm info --query=all --name=input/eventXX
64
65If you see a line stating ID_INPUT_JOYSTICK=1, great, if you don't see it,
66you need to set up an udev rule to force this variable.
67
68A combined rule for the Saitek Pro Flight Rudder Pedals to fix both issues looks
69like:
70
71 SUBSYSTEM=="input", ATTRS{idProduct}=="0763", ATTRS{idVendor}=="06a3", MODE="0666", ENV{ID_INPUT_JOYSTICK}="1"
72 SUBSYSTEM=="input", ATTRS{idProduct}=="0764", ATTRS{idVendor}=="06a3", MODE="0666", ENV{ID_INPUT_JOYSTICK}="1"
73
74You can set up similar rules for your device by changing the values listed in
75idProduct and idVendor. To obtain these values, try:
76
77 sudo udevadm info -a --name=input/eventXX | grep idVendor
78 sudo udevadm info -a --name=input/eventXX | grep idProduct
79
80If multiple values come up for each of these, the one you want is the first one of each.
81
82On other systems which ship with an older udev (such as CentOS), you may need
83to set up a rule such as:
84
85 SUBSYSTEM=="input", ENV{ID_CLASS}=="joystick", ENV{ID_INPUT_JOYSTICK}="1"
86
87
README-macosx.md
1Mac OS X
2==============================================================================
3
4These instructions are for people using Apple's Mac OS X (pronounced
5"ten").
6
7From the developer's point of view, OS X is a sort of hybrid Mac and
8Unix system, and you have the option of using either traditional
9command line tools or Apple's IDE Xcode.
10
11To build SDL using the command line, use the standard configure and make
12process:
13
14 ./configure
15 make
16 sudo make install
17
18You can also build SDL as a Universal library (a single binary for both
1932-bit and 64-bit Intel architectures), on Mac OS X 10.7 and newer, by using
20the gcc-fat.sh script in build-scripts:
21
22 mkdir mybuild
23 cd mybuild
24 CC=$PWD/../build-scripts/gcc-fat.sh CXX=$PWD/../build-scripts/g++-fat.sh ../configure
25 make
26 sudo make install
27
28This script builds SDL with 10.5 ABI compatibility on i386 and 10.6
29ABI compatibility on x86_64 architectures. For best compatibility you
30should compile your application the same way.
31
32Please note that building SDL requires at least Xcode 4.6 and the 10.7 SDK
33(even if you target back to 10.5 systems). PowerPC support for Mac OS X has
34been officially dropped as of SDL 2.0.2.
35
36To use the library once it's built, you essential have two possibilities:
37use the traditional autoconf/automake/make method, or use Xcode.
38
39==============================================================================
40Caveats for using SDL with Mac OS X
41==============================================================================
42
43Some things you have to be aware of when using SDL on Mac OS X:
44
45- If you register your own NSApplicationDelegate (using [NSApp setDelegate:]),
46 SDL will not register its own. This means that SDL will not terminate using
47 SDL_Quit if it receives a termination request, it will terminate like a
48 normal app, and it will not send a SDL_DROPFILE when you request to open a
49 file with the app. To solve these issues, put the following code in your
50 NSApplicationDelegate implementation:
51
52
53 - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
54 {
55 if (SDL_GetEventState(SDL_QUIT) == SDL_ENABLE) {
56 SDL_Event event;
57 event.type = SDL_QUIT;
58 SDL_PushEvent(&event);
59 }
60
61 return NSTerminateCancel;
62 }
63
64 - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
65 {
66 if (SDL_GetEventState(SDL_DROPFILE) == SDL_ENABLE) {
67 SDL_Event event;
68 event.type = SDL_DROPFILE;
69 event.drop.file = SDL_strdup([filename UTF8String]);
70 return (SDL_PushEvent(&event) > 0);
71 }
72
73 return NO;
74 }
75
76==============================================================================
77Using the Simple DirectMedia Layer with a traditional Makefile
78==============================================================================
79
80An existing autoconf/automake build system for your SDL app has good chances
81to work almost unchanged on OS X. However, to produce a "real" Mac OS X binary
82that you can distribute to users, you need to put the generated binary into a
83so called "bundle", which basically is a fancy folder with a name like
84"MyCoolGame.app".
85
86To get this build automatically, add something like the following rule to
87your Makefile.am:
88
89 bundle_contents = APP_NAME.app/Contents
90 APP_NAME_bundle: EXE_NAME
91 mkdir -p $(bundle_contents)/MacOS
92 mkdir -p $(bundle_contents)/Resources
93 echo "APPL????" > $(bundle_contents)/PkgInfo
94 $(INSTALL_PROGRAM) $< $(bundle_contents)/MacOS/
95
96You should replace EXE_NAME with the name of the executable. APP_NAME is what
97will be visible to the user in the Finder. Usually it will be the same
98as EXE_NAME but capitalized. E.g. if EXE_NAME is "testgame" then APP_NAME
99usually is "TestGame". You might also want to use `@PACKAGE@` to use the package
100name as specified in your configure.in file.
101
102If your project builds more than one application, you will have to do a bit
103more. For each of your target applications, you need a separate rule.
104
105If you want the created bundles to be installed, you may want to add this
106rule to your Makefile.am:
107
108 install-exec-hook: APP_NAME_bundle
109 rm -rf $(DESTDIR)$(prefix)/Applications/APP_NAME.app
110 mkdir -p $(DESTDIR)$(prefix)/Applications/
111 cp -r $< /$(DESTDIR)$(prefix)Applications/
112
113This rule takes the Bundle created by the rule from step 3 and installs them
114into "$(DESTDIR)$(prefix)/Applications/".
115
116Again, if you want to install multiple applications, you will have to augment
117the make rule accordingly.
118
119
120But beware! That is only part of the story! With the above, you end up with
121a bare bone .app bundle, which is double clickable from the Finder. But
122there are some more things you should do before shipping your product...
123
1241) The bundle right now probably is dynamically linked against SDL. That
125 means that when you copy it to another computer, *it will not run*,
126 unless you also install SDL on that other computer. A good solution
127 for this dilemma is to static link against SDL. On OS X, you can
128 achieve that by linking against the libraries listed by
129
130 sdl-config --static-libs
131
132 instead of those listed by
133
134 sdl-config --libs
135
136 Depending on how exactly SDL is integrated into your build systems, the
137 way to achieve that varies, so I won't describe it here in detail
138
1392) Add an 'Info.plist' to your application. That is a special XML file which
140 contains some meta-information about your application (like some copyright
141 information, the version of your app, the name of an optional icon file,
142 and other things). Part of that information is displayed by the Finder
143 when you click on the .app, or if you look at the "Get Info" window.
144 More information about Info.plist files can be found on Apple's homepage.
145
146
147As a final remark, let me add that I use some of the techniques (and some
148variations of them) in Exult and ScummVM; both are available in source on
149the net, so feel free to take a peek at them for inspiration!
150
151
152==============================================================================
153Using the Simple DirectMedia Layer with Xcode
154==============================================================================
155
156These instructions are for using Apple's Xcode IDE to build SDL applications.
157
158- First steps
159
160The first thing to do is to unpack the Xcode.tar.gz archive in the
161top level SDL directory (where the Xcode.tar.gz archive resides).
162Because Stuffit Expander will unpack the archive into a subdirectory,
163you should unpack the archive manually from the command line:
164
165 cd [path_to_SDL_source]
166 tar zxf Xcode.tar.gz
167
168This will create a new folder called Xcode, which you can browse
169normally from the Finder.
170
171- Building the Framework
172
173The SDL Library is packaged as a framework bundle, an organized
174relocatable folder hierarchy of executable code, interface headers,
175and additional resources. For practical purposes, you can think of a
176framework as a more user and system-friendly shared library, whose library
177file behaves more or less like a standard UNIX shared library.
178
179To build the framework, simply open the framework project and build it.
180By default, the framework bundle "SDL.framework" is installed in
181/Library/Frameworks. Therefore, the testers and project stationary expect
182it to be located there. However, it will function the same in any of the
183following locations:
184
185 ~/Library/Frameworks
186 /Local/Library/Frameworks
187 /System/Library/Frameworks
188
189- Build Options
190 There are two "Build Styles" (See the "Targets" tab) for SDL.
191 "Deployment" should be used if you aren't tweaking the SDL library.
192 "Development" should be used to debug SDL apps or the library itself.
193
194- Building the Testers
195 Open the SDLTest project and build away!
196
197- Using the Project Stationary
198 Copy the stationary to the indicated folders to access it from
199 the "New Project" and "Add target" menus. What could be easier?
200
201- Setting up a new project by hand
202 Some of you won't want to use the Stationary so I'll give some tips:
203 * Create a new "Cocoa Application"
204 * Add src/main/macosx/SDLMain.m , .h and .nib to your project
205 * Remove "main.c" from your project
206 * Remove "MainMenu.nib" from your project
207 * Add "$(HOME)/Library/Frameworks/SDL.framework/Headers" to include path
208 * Add "$(HOME)/Library/Frameworks" to the frameworks search path
209 * Add "-framework SDL -framework Foundation -framework AppKit" to "OTHER_LDFLAGS"
210 * Set the "Main Nib File" under "Application Settings" to "SDLMain.nib"
211 * Add your files
212 * Clean and build
213
214- Building from command line
215 Use pbxbuild in the same directory as your .pbproj file
216
217- Running your app
218 You can send command line args to your app by either invoking it from
219 the command line (in *.app/Contents/MacOS) or by entering them in the
220 "Executables" panel of the target settings.
221
222- Implementation Notes
223 Some things that may be of interest about how it all works...
224 * Working directory
225 As defined in the SDL_main.m file, the working directory of your SDL app
226 is by default set to its parent. You may wish to change this to better
227 suit your needs.
228 * You have a Cocoa App!
229 Your SDL app is essentially a Cocoa application. When your app
230 starts up and the libraries finish loading, a Cocoa procedure is called,
231 which sets up the working directory and calls your main() method.
232 You are free to modify your Cocoa app with generally no consequence
233 to SDL. You cannot, however, easily change the SDL window itself.
234 Functionality may be added in the future to help this.
235
236
237Known bugs are listed in the file "BUGS.txt".
238
README-nacl.md
1Native Client
2================================================================================
3
4Requirements:
5
6* Native Client SDK (https://developer.chrome.com/native-client),
7 (tested with Pepper version 33 or higher).
8
9The SDL backend for Chrome's Native Client has been tested only with the PNaCl
10toolchain, which generates binaries designed to run on ARM and x86_32/64
11platforms. This does not mean it won't work with the other toolchains!
12
13================================================================================
14Building SDL for NaCl
15================================================================================
16
17Set up the right environment variables (see naclbuild.sh), then configure SDL with:
18
19 configure --host=pnacl --prefix some/install/destination
20
21Then "make".
22
23As an example of how to create a deployable app a Makefile project is provided
24in test/nacl/Makefile, which includes some monkey patching of the common.mk file
25provided by NaCl, without which linking properly to SDL won't work (the search
26path can't be modified externally, so the linker won't find SDL's binaries unless
27you dump them into the SDK path, which is inconvenient).
28Also provided in test/nacl is the required support file, such as index.html,
29manifest.json, etc.
30SDL apps for NaCl run on a worker thread using the ppapi_simple infrastructure.
31This allows for blocking calls on all the relevant systems (OpenGL ES, filesystem),
32hiding the asynchronous nature of the browser behind the scenes...which is not the
33same as making it disappear!
34
35
36================================================================================
37Running tests
38================================================================================
39
40Due to the nature of NaCl programs, building and running SDL tests is not as
41straightforward as one would hope. The script naclbuild.sh in build-scripts
42automates the process and should serve as a guide for users of SDL trying to build
43their own applications.
44
45Basic usage:
46
47 ./naclbuild.sh path/to/pepper/toolchain (i.e. ~/naclsdk/pepper_35)
48
49This will build testgles2.c by default.
50
51If you want to build a different test, for example testrendercopyex.c:
52
53 SOURCES=~/sdl/SDL/test/testrendercopyex.c ./naclbuild.sh ~/naclsdk/pepper_35
54
55Once the build finishes, you have to serve the contents with a web server (the
56script will give you instructions on how to do that with Python).
57
58================================================================================
59RWops and nacl_io
60================================================================================
61
62SDL_RWops work transparently with nacl_io. Two functions control the mount points:
63
64 int mount(const char* source, const char* target,
65 const char* filesystemtype,
66 unsigned long mountflags, const void *data);
67 int umount(const char *target);
68
69 For convenience, SDL will by default mount an httpfs tree at / before calling
70the app's main function. Such setting can be overridden by calling:
71
72 umount("/");
73
74And then mounting a different filesystem at /
75
76It's important to consider that the asynchronous nature of file operations on a
77browser is hidden from the application, effectively providing the developer with
78a set of blocking file operations just like you get in a regular desktop
79environment, which eases the job of porting to Native Client, but also introduces
80a set of challenges of its own, in particular when big file sizes and slow
81connections are involved.
82
83For more information on how nacl_io and mount points work, see:
84
85 https://developer.chrome.com/native-client/devguide/coding/nacl_io
86 https://src.chromium.org/chrome/trunk/src/native_client_sdk/src/libraries/nacl_io/nacl_io.h
87
88To be able to save into the directory "/save/" (like backup of game) :
89
90 mount("", "/save", "html5fs", 0, "type=PERSISTENT");
91
92And add to manifest.json :
93
94 "permissions": [
95 "unlimitedStorage"
96 ]
97
98================================================================================
99TODO - Known Issues
100================================================================================
101* Testing of all systems with a real application (something other than SDL's tests)
102* Key events don't seem to work properly
103
104
README-pandora.md
1Pandora
2=====================================================================
3
4( http://openpandora.org/ )
5- A pandora specific video driver was written to allow SDL 2.0 with OpenGL ES
6support to work on the pandora under the framebuffer. This driver do not have
7input support for now, so if you use it you will have to add your own control code.
8The video driver name is "pandora" so if you have problem running it from
9the framebuffer, try to set the following variable before starting your application :
10"export SDL_VIDEODRIVER=pandora"
11
12- OpenGL ES support was added to the x11 driver, so it's working like the normal
13x11 driver one with OpenGLX support, with SDL input event's etc..
14
15
16David Carré (Cpasjuste)
17cpasjuste@gmail.com
18
README-porting.md
1Porting
2=======
3
4* Porting To A New Platform
5
6 The first thing you have to do when porting to a new platform, is look at
7include/SDL_platform.h and create an entry there for your operating system.
8The standard format is "__PLATFORM__", where PLATFORM is the name of the OS.
9Ideally SDL_platform.h will be able to auto-detect the system it's building
10on based on C preprocessor symbols.
11
12There are two basic ways of building SDL at the moment:
13
141. The "UNIX" way: ./configure; make; make install
15
16 If you have a GNUish system, then you might try this. Edit configure.in,
17 take a look at the large section labelled:
18
19 "Set up the configuration based on the host platform!"
20
21 Add a section for your platform, and then re-run autogen.sh and build!
22
232. Using an IDE:
24
25 If you're using an IDE or other non-configure build system, you'll probably
26 want to create a custom SDL_config.h for your platform. Edit SDL_config.h,
27 add a section for your platform, and create a custom SDL_config_{platform}.h,
28 based on SDL_config.h.minimal and SDL_config.h.in
29
30 Add the top level include directory to the header search path, and then add
31 the following sources to the project:
32
33 src/*.c
34 src/atomic/*.c
35 src/audio/*.c
36 src/cpuinfo/*.c
37 src/events/*.c
38 src/file/*.c
39 src/haptic/*.c
40 src/joystick/*.c
41 src/power/*.c
42 src/render/*.c
43 src/stdlib/*.c
44 src/thread/*.c
45 src/timer/*.c
46 src/video/*.c
47 src/audio/disk/*.c
48 src/audio/dummy/*.c
49 src/filesystem/dummy/*.c
50 src/video/dummy/*.c
51 src/haptic/dummy/*.c
52 src/joystick/dummy/*.c
53 src/main/dummy/*.c
54 src/thread/generic/*.c
55 src/timer/dummy/*.c
56 src/loadso/dummy/*.c
57
58
59Once you have a working library without any drivers, you can go back to each
60of the major subsystems and start implementing drivers for your platform.
61
62If you have any questions, don't hesitate to ask on the SDL mailing list:
63 http://www.libsdl.org/mailing-list.php
64
65Enjoy!
66 Sam Lantinga (slouken@libsdl.org)
67
68
README-psp.md
1PSP
2======
3SDL port for the Sony PSP contributed by
4 Captian Lex
5
6Credit to
7 Marcus R.Brown,Jim Paris,Matthew H for the original SDL 1.2 for PSP
8 Geecko for his PSP GU lib "Glib2d"
9
10Building
11--------
12To build for the PSP, make sure psp-config is in the path and run:
13 make -f Makefile.psp
14
15
16
17To Do
18------
19PSP Screen Keyboard
20
README-raspberrypi.md
1Raspberry Pi
2================================================================================
3
4Requirements:
5
6Raspbian (other Linux distros may work as well).
7
8================================================================================
9 Features
10================================================================================
11
12* Works without X11
13* Hardware accelerated OpenGL ES 2.x
14* Sound via ALSA
15* Input (mouse/keyboard/joystick) via EVDEV
16* Hotplugging of input devices via UDEV
17
18
19================================================================================
20 Raspbian Build Dependencies
21================================================================================
22
23sudo apt-get install libudev-dev libasound2-dev libdbus-1-dev
24
25You also need the VideoCore binary stuff that ships in /opt/vc for EGL and
26OpenGL ES 2.x, it usually comes pre installed, but in any case:
27
28sudo apt-get install libraspberrypi0 libraspberrypi-bin libraspberrypi-dev
29
30================================================================================
31 Cross compiling from x86 Linux
32================================================================================
33
34To cross compile SDL for Raspbian from your desktop machine, you'll need a
35Raspbian system root and the cross compilation tools. We'll assume these tools
36will be placed in /opt/rpi-tools
37
38 sudo git clone --depth 1 https://github.com/raspberrypi/tools /opt/rpi-tools
39
40You'll also need a Rasbian binary image.
41Get it from: http://downloads.raspberrypi.org/raspbian_latest
42After unzipping, you'll get file with a name like: "<date>-wheezy-raspbian.img"
43Let's assume the sysroot will be built in /opt/rpi-sysroot.
44
45 export SYSROOT=/opt/rpi-sysroot
46 sudo kpartx -a -v <path_to_raspbian_image>.img
47 sudo mount -o loop /dev/mapper/loop0p2 /mnt
48 sudo cp -r /mnt $SYSROOT
49 sudo apt-get install qemu binfmt-support qemu-user-static
50 sudo cp /usr/bin/qemu-arm-static $SYSROOT/usr/bin
51 sudo mount --bind /dev $SYSROOT/dev
52 sudo mount --bind /proc $SYSROOT/proc
53 sudo mount --bind /sys $SYSROOT/sys
54
55Now, before chrooting into the ARM sysroot, you'll need to apply a workaround,
56edit $SYSROOT/etc/ld.so.preload and comment out all lines in it.
57
58 sudo chroot $SYSROOT
59 apt-get install libudev-dev libasound2-dev libdbus-1-dev libraspberrypi0 libraspberrypi-bin libraspberrypi-dev libx11-dev libxext-dev libxrandr-dev libxcursor-dev libxi-dev libxinerama-dev libxxf86vm-dev libxss-dev
60 exit
61 sudo umount $SYSROOT/dev
62 sudo umount $SYSROOT/proc
63 sudo umount $SYSROOT/sys
64 sudo umount /mnt
65
66There's one more fix required, as the libdl.so symlink uses an absolute path
67which doesn't quite work in our setup.
68
69 sudo rm -rf $SYSROOT/usr/lib/arm-linux-gnueabihf/libdl.so
70 sudo ln -s ../../../lib/arm-linux-gnueabihf/libdl.so.2 $SYSROOT/usr/lib/arm-linux-gnueabihf/libdl.so
71
72The final step is compiling SDL itself.
73
74 export CC="/opt/rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc --sysroot=$SYSROOT -I$SYSROOT/opt/vc/include -I$SYSROOT/usr/include -I$SYSROOT/opt/vc/include/interface/vcos/pthreads -I$SYSROOT/opt/vc/include/interface/vmcs_host/linux"
75 cd <SDL SOURCE>
76 mkdir -p build;cd build
77 LDFLAGS="-L$SYSROOT/opt/vc/lib" ../configure --with-sysroot=$SYSROOT --host=arm-raspberry-linux-gnueabihf --prefix=$PWD/rpi-sdl2-installed --disable-pulseaudio --disable-esd
78 make
79 make install
80
81To be able to deploy this to /usr/local in the Raspbian system you need to fix up a few paths:
82
83 perl -w -pi -e "s#$PWD/rpi-sdl2-installed#/usr/local#g;" ./rpi-sdl2-installed/lib/libSDL2.la ./rpi-sdl2-installed/lib/pkgconfig/sdl2.pc ./rpi-sdl2-installed/bin/sdl2-config
84
85================================================================================
86 Apps don't work or poor video/audio performance
87================================================================================
88
89If you get sound problems, buffer underruns, etc, run "sudo rpi-update" to
90update the RPi's firmware. Note that doing so will fix these problems, but it
91will also render the CMA - Dynamic Memory Split functionality useless.
92
93Also, by default the Raspbian distro configures the GPU RAM at 64MB, this is too
94low in general, specially if a 1080p TV is hooked up.
95
96See here how to configure this setting: http://elinux.org/RPiconfig
97
98Using a fixed gpu_mem=128 is the best option (specially if you updated the
99firmware, using CMA probably won't work, at least it's the current case).
100
101================================================================================
102 No input
103================================================================================
104
105Make sure you belong to the "input" group.
106
107 sudo usermod -aG input `whoami`
108
109================================================================================
110 No HDMI Audio
111================================================================================
112
113If you notice that ALSA works but there's no audio over HDMI, try adding:
114
115 hdmi_drive=2
116
117to your config.txt file and reboot.
118
119Reference: http://www.raspberrypi.org/phpBB3/viewtopic.php?t=5062
120
121================================================================================
122 Text Input API support
123================================================================================
124
125The Text Input API is supported, with translation of scan codes done via the
126kernel symbol tables. For this to work, SDL needs access to a valid console.
127If you notice there's no SDL_TEXTINPUT message being emitted, double check that
128your app has read access to one of the following:
129
130* /proc/self/fd/0
131* /dev/tty
132* /dev/tty[0...6]
133* /dev/vc/0
134* /dev/console
135
136This is usually not a problem if you run from the physical terminal (as opposed
137to running from a pseudo terminal, such as via SSH). If running from a PTS, a
138quick workaround is to run your app as root or add yourself to the tty group,
139then re login to the system.
140
141 sudo usermod -aG tty `whoami`
142
143The keyboard layout used by SDL is the same as the one the kernel uses.
144To configure the layout on Raspbian:
145
146 sudo dpkg-reconfigure keyboard-configuration
147
148To configure the locale, which controls which keys are interpreted as letters,
149this determining the CAPS LOCK behavior:
150
151 sudo dpkg-reconfigure locales
152
153================================================================================
154 OpenGL problems
155================================================================================
156
157If you have desktop OpenGL headers installed at build time in your RPi or cross
158compilation environment, support for it will be built in. However, the chipset
159does not actually have support for it, which causes issues in certain SDL apps
160since the presence of OpenGL support supersedes the ES/ES2 variants.
161The workaround is to disable OpenGL at configuration time:
162
163 ./configure --disable-video-opengl
164
165Or if the application uses the Render functions, you can use the SDL_RENDER_DRIVER
166environment variable:
167
168 export SDL_RENDER_DRIVER=opengles2
169
170================================================================================
171 Notes
172================================================================================
173
174* When launching apps remotely (via SSH), SDL can prevent local keystrokes from
175 leaking into the console only if it has root privileges. Launching apps locally
176 does not suffer from this issue.
177
178
179
README-touch.md
1Touch
2===========================================================================
3System Specific Notes
4===========================================================================
5Linux:
6The linux touch system is currently based off event streams, and proc/bus/devices. The active user must be given permissions to read /dev/input/TOUCHDEVICE, where TOUCHDEVICE is the event stream for your device. Currently only Wacom tablets are supported. If you have an unsupported tablet contact me at jim.tla+sdl_touch@gmail.com and I will help you get support for it.
7
8Mac:
9The Mac and iPhone APIs are pretty. If your touch device supports them then you'll be fine. If it doesn't, then there isn't much we can do.
10
11iPhone:
12Works out of box.
13
14Windows:
15Unfortunately there is no windows support as of yet. Support for Windows 7 is planned, but we currently have no way to test. If you have a Windows 7 WM_TOUCH supported device, and are willing to help test please contact me at jim.tla+sdl_touch@gmail.com
16
17===========================================================================
18Events
19===========================================================================
20SDL_FINGERDOWN:
21Sent when a finger (or stylus) is placed on a touch device.
22Fields:
23* event.tfinger.touchId - the Id of the touch device.
24* event.tfinger.fingerId - the Id of the finger which just went down.
25* event.tfinger.x - the x coordinate of the touch (0..1)
26* event.tfinger.y - the y coordinate of the touch (0..1)
27* event.tfinger.pressure - the pressure of the touch (0..1)
28
29SDL_FINGERMOTION:
30Sent when a finger (or stylus) is moved on the touch device.
31Fields:
32Same as SDL_FINGERDOWN but with additional:
33* event.tfinger.dx - change in x coordinate during this motion event.
34* event.tfinger.dy - change in y coordinate during this motion event.
35
36SDL_FINGERUP:
37Sent when a finger (or stylus) is lifted from the touch device.
38Fields:
39Same as SDL_FINGERDOWN.
40
41
42===========================================================================
43Functions
44===========================================================================
45SDL provides the ability to access the underlying SDL_Finger structures.
46These structures should _never_ be modified.
47
48The following functions are included from SDL_touch.h
49
50To get a SDL_TouchID call SDL_GetTouchDevice(int index).
51This returns a SDL_TouchID.
52IMPORTANT: If the touch has been removed, or there is no touch with the given index, SDL_GetTouchDevice() will return 0. Be sure to check for this!
53
54The number of touch devices can be queried with SDL_GetNumTouchDevices().
55
56A SDL_TouchID may be used to get pointers to SDL_Finger.
57
58SDL_GetNumTouchFingers(touchID) may be used to get the number of fingers currently down on the device.
59
60The most common reason to access SDL_Finger is to query the fingers outside the event. In most cases accessing the fingers is using the event. This would be accomplished by code like the following:
61
62 float x = event.tfinger.x;
63 float y = event.tfinger.y;
64
65
66
67To get a SDL_Finger, call SDL_GetTouchFinger(SDL_TouchID touchID, int index), where touchID is a SDL_TouchID, and index is the requested finger.
68This returns a SDL_Finger *, or NULL if the finger does not exist, or has been removed.
69A SDL_Finger is guaranteed to be persistent for the duration of a touch, but it will be de-allocated as soon as the finger is removed. This occurs when the SDL_FINGERUP event is _added_ to the event queue, and thus _before_ the SDL_FINGERUP event is polled.
70As a result, be very careful to check for NULL return values.
71
72A SDL_Finger has the following fields:
73* x, y:
74 The current coordinates of the touch.
75* pressure:
76 The pressure of the touch.
77
78
79===========================================================================
80Notes
81===========================================================================
82For a complete example see test/testgesture.c
83
84Please direct questions/comments to:
85 jim.tla+sdl_touch@gmail.com
86 (original author, API was changed since)
87
README-wince.md
1WinCE
2=====
3
4Windows CE is no longer supported by SDL.
5
6We have left the CE support in SDL 1.2 for those that must have it, and we
7have support for Windows Phone 8 and WinRT in SDL2, as of SDL 2.0.3.
8
9--ryan.
10
11
README-windows.md
1Windows
2================================================================================
3
4================================================================================
5OpenGL ES 2.x support
6================================================================================
7
8SDL has support for OpenGL ES 2.x under Windows via two alternative
9implementations.
10The most straightforward method consists in running your app in a system with
11a graphic card paired with a relatively recent (as of November of 2013) driver
12which supports the WGL_EXT_create_context_es2_profile extension. Vendors known
13to ship said extension on Windows currently include nVidia and Intel.
14
15The other method involves using the ANGLE library (https://code.google.com/p/angleproject/)
16If an OpenGL ES 2.x context is requested and no WGL_EXT_create_context_es2_profile
17extension is found, SDL will try to load the libEGL.dll library provided by
18ANGLE.
19To obtain the ANGLE binaries, you can either compile from source from
20https://chromium.googlesource.com/angle/angle or copy the relevant binaries from
21a recent Chrome/Chromium install for Windows. The files you need are:
22
23 * libEGL.dll
24 * libGLESv2.dll
25 * d3dcompiler_46.dll (supports Windows Vista or later, better shader compiler)
26 or...
27 * d3dcompiler_43.dll (supports Windows XP or later)
28
29If you compile ANGLE from source, you can configure it so it does not need the
30d3dcompiler_* DLL at all (for details on this, see their documentation).
31However, by default SDL will try to preload the d3dcompiler_46.dll to
32comply with ANGLE's requirements. If you wish SDL to preload d3dcompiler_43.dll (to
33support Windows XP) or to skip this step at all, you can use the
34SDL_HINT_VIDEO_WIN_D3DCOMPILER hint (see SDL_hints.h for more details).
35
36Known Bugs:
37
38 * SDL_GL_SetSwapInterval is currently a no op when using ANGLE. It appears
39 that there's a bug in the library which prevents the window contents from
40 refreshing if this is set to anything other than the default value.
41
42
README-winrt.md
1WinRT
2=====
3
4This port allows SDL applications to run on Microsoft's platforms that require
5use of "Windows Runtime", aka. "WinRT", APIs. Microsoft may, in some cases,
6refer to them as either "Windows Store", or for Windows 10, "UWP" apps.
7
8Some of the operating systems that include WinRT, are:
9
10* Windows 10, via its Universal Windows Platform (UWP) APIs
11* Windows 8.x
12* Windows RT 8.x (aka. Windows 8.x for ARM processors)
13* Windows Phone 8.x
14
15
16Requirements
17------------
18
19* Microsoft Visual C++ (aka Visual Studio), either 2015, 2013, or 2012
20 - Free, "Community" or "Express" editions may be used, so long as they
21 include support for either "Windows Store" or "Windows Phone" apps.
22 "Express" versions marked as supporting "Windows Desktop" development
23 typically do not include support for creating WinRT apps, to note.
24 (The "Community" editions of Visual C++ do, however, support both
25 desktop/Win32 and WinRT development).
26 - Visual C++ 2012 can only build apps that target versions 8.0 of Windows,
27 or Windows Phone. 8.0-targetted apps will run on devices running 8.1
28 editions of Windows, however they will not be able to take advantage of
29 8.1-specific features.
30 - Visual C++ 2013 cannot create app projects that target Windows 8.0.
31 Visual C++ 2013 Update 4, can create app projects for Windows Phone 8.0,
32 Windows Phone 8.1, and Windows 8.1, but not Windows 8.0. An optional
33 Visual Studio add-in, "Tools for Maintaining Store apps for Windows 8",
34 allows Visual C++ 2013 to load and build Windows 8.0 projects that were
35 created with Visual C++ 2012, so long as Visual C++ 2012 is installed
36 on the same machine. More details on targeting different versions of
37 Windows can found at the following web pages:
38 - [Develop apps by using Visual Studio 2013](http://msdn.microsoft.com/en-us/library/windows/apps/br211384.aspx)
39 - [To add the Tools for Maintaining Store apps for Windows 8](http://msdn.microsoft.com/en-us/library/windows/apps/dn263114.aspx#AddMaintenanceTools)
40* A valid Microsoft account - This requirement is not imposed by SDL, but
41 rather by Microsoft's Visual C++ toolchain. This is required to launch or
42 debug apps.
43
44
45Status
46------
47
48Here is a rough list of what works, and what doens't:
49
50* What works:
51 * compilation via Visual C++ 2012 through 2015
52 * compile-time platform detection for SDL programs. The C/C++ #define,
53 `__WINRT__`, will be set to 1 (by SDL) when compiling for WinRT.
54 * GPU-accelerated 2D rendering, via SDL_Renderer.
55 * OpenGL ES 2, via the ANGLE library (included separately from SDL)
56 * software rendering, via either SDL_Surface (optionally in conjunction with
57 SDL_GetWindowSurface() and SDL_UpdateWindowSurface()) or via the
58 SDL_Renderer APIs
59 * threads
60 * timers (via SDL_GetTicks(), SDL_AddTimer(), SDL_GetPerformanceCounter(),
61 SDL_GetPerformanceFrequency(), etc.)
62 * file I/O via SDL_RWops
63 * mouse input (unsupported on Windows Phone)
64 * audio, via a modified version of SDL's XAudio2 backend
65 * .DLL file loading. Libraries *MUST* be packaged inside applications. Loading
66 anything outside of the app is not supported.
67 * system path retrieval via SDL's filesystem APIs
68 * game controllers. Support is provided via the SDL_Joystick and
69 SDL_GameController APIs, and is backed by Microsoft's XInput API.
70 * multi-touch input
71 * app events. SDL_APP_WILLENTER* and SDL_APP_DIDENTER* events get sent out as
72 appropriate.
73 * window events
74 * using Direct3D 11.x APIs outside of SDL. Non-XAML / Direct3D-only apps can
75 choose to render content directly via Direct3D, using SDL to manage the
76 internal WinRT window, as well as input and audio. (Use
77 SDL_GetWindowWMInfo() to get the WinRT 'CoreWindow', and pass it into
78 IDXGIFactory2::CreateSwapChainForCoreWindow() as appropriate.)
79
80* What partially works:
81 * keyboard input. Most of WinRT's documented virtual keys are supported, as
82 well as many keys with documented hardware scancodes. Converting
83 SDL_Scancodes to or from SDL_Keycodes may not work, due to missing APIs
84 (MapVirualKey()) in Microsoft's Windows Store / UWP APIs.
85 * SDLmain. WinRT uses a different signature for each app's main() function.
86 SDL-based apps that use this port must compile in SDL_winrt_main_NonXAML.cpp
87 (in `SDL\src\main\winrt\`) directly in order for their C-style main()
88 functions to be called.
89
90* What doesn't work:
91 * compilation with anything other than Visual C++
92 * programmatically-created custom cursors. These don't appear to be supported
93 by WinRT. Different OS-provided cursors can, however, be created via
94 SDL_CreateSystemCursor() (unsupported on Windows Phone)
95 * SDL_WarpMouseInWindow() or SDL_WarpMouseGlobal(). This are not currently
96 supported by WinRT itself.
97 * joysticks and game controllers that aren't supported by Microsoft's XInput
98 API.
99 * turning off VSync when rendering on Windows Phone. Attempts to turn VSync
100 off on Windows Phone result either in Direct3D not drawing anything, or it
101 forcing VSync back on. As such, SDL_RENDERER_PRESENTVSYNC will always get
102 turned-on on Windows Phone. This limitation is not present in non-Phone
103 WinRT (such as Windows 8.x), where turning off VSync appears to work.
104 * probably anything else that's not listed as supported
105
106
107
108Upgrade Notes
109-------------
110
111#### SDL_GetPrefPath() usage when upgrading WinRT apps from SDL 2.0.3
112
113SDL 2.0.4 fixes two bugs found in the WinRT version of SDL_GetPrefPath().
114The fixes may affect older, SDL 2.0.3-based apps' save data. Please note
115that these changes only apply to SDL-based WinRT apps, and not to apps for
116any other platform.
117
1181. SDL_GetPrefPath() would return an invalid path, one in which the path's
119 directory had not been created. Attempts to create files there
120 (via fopen(), for example), would fail, unless that directory was
121 explicitly created beforehand.
122
1232. SDL_GetPrefPath(), for non-WinPhone-based apps, would return a path inside
124 a WinRT 'Roaming' folder, the contents of which get automatically
125 synchronized across multiple devices. This process can occur while an
126 application runs, and can cause existing save-data to be overwritten
127 at unexpected times, with data from other devices. (Windows Phone apps
128 written with SDL 2.0.3 did not utilize a Roaming folder, due to API
129 restrictions in Windows Phone 8.0).
130
131
132SDL_GetPrefPath(), starting with SDL 2.0.4, addresses these by:
133
1341. making sure that SDL_GetPrefPath() returns a directory in which data
135 can be written to immediately, without first needing to create directories.
136
1372. basing SDL_GetPrefPath() off of a different, non-Roaming folder, the
138 contents of which do not automatically get synchronized across devices
139 (and which require less work to use safely, in terms of data integrity).
140
141Apps that wish to get their Roaming folder's path can do so either by using
142SDL_WinRTGetFSPathUTF8(), SDL_WinRTGetFSPathUNICODE() (which returns a
143UCS-2/wide-char string), or directly through the WinRT class,
144Windows.Storage.ApplicationData.
145
146
147
148Setup, High-Level Steps
149-----------------------
150
151The steps for setting up a project for an SDL/WinRT app looks like the
152following, at a high-level:
153
1541. create a new Visual C++ project using Microsoft's template for a,
155 "Direct3D App".
1562. remove most of the files from the project.
1573. make your app's project directly reference SDL/WinRT's own Visual C++
158 project file, via use of Visual C++'s "References" dialog. This will setup
159 the linker, and will copy SDL's .dll files to your app's final output.
1604. adjust your app's build settings, at minimum, telling it where to find SDL's
161 header files.
1625. add files that contains a WinRT-appropriate main function, along with some
163 data to make sure mouse-cursor-hiding (via SDL_ShowCursor(SDL_DISABLE) calls)
164 work properly.
1656. add SDL-specific app code.
1667. build and run your app.
167
168
169Setup, Detailed Steps
170---------------------
171
172### 1. Create a new project ###
173
174Create a new project using one of Visual C++'s templates for a plain, non-XAML,
175"Direct3D App" (XAML support for SDL/WinRT is not yet ready for use). If you
176don't see one of these templates, in Visual C++'s 'New Project' dialog, try
177using the textbox titled, 'Search Installed Templates' to look for one.
178
179
180### 2. Remove unneeded files from the project ###
181
182In the new project, delete any file that has one of the following extensions:
183
184- .cpp
185- .h
186- .hlsl
187
188When you are done, you should be left with a few files, each of which will be a
189necessary part of your app's project. These files will consist of:
190
191- an .appxmanifest file, which contains metadata on your WinRT app. This is
192 similar to an Info.plist file on iOS, or an AndroidManifest.xml on Android.
193- a few .png files, one of which is a splash screen (displayed when your app
194 launches), others are app icons.
195- a .pfx file, used for code signing purposes.
196
197
198### 3. Add references to SDL's project files ###
199
200SDL/WinRT can be built in multiple variations, spanning across three different
201CPU architectures (x86, x64, and ARM) and two different configurations
202(Debug and Release). WinRT and Visual C++ do not currently provide a means
203for combining multiple variations of one library into a single file.
204Furthermore, it does not provide an easy means for copying pre-built .dll files
205into your app's final output (via Post-Build steps, for example). It does,
206however, provide a system whereby an app can reference the MSVC projects of
207libraries such that, when the app is built:
208
2091. each library gets built for the appropriate CPU architecture(s) and WinRT
210 platform(s).
2112. each library's output, such as .dll files, get copied to the app's build
212 output.
213
214To set this up for SDL/WinRT, you'll need to run through the following steps:
215
2161. open up the Solution Explorer inside Visual C++ (under the "View" menu, then
217 "Solution Explorer")
2182. right click on your app's solution.
2193. navigate to "Add", then to "Existing Project..."
2204. find SDL/WinRT's Visual C++ project file and open it. Different project
221 files exist for different WinRT platforms. All of them are in SDL's
222 source distribution, in the following directories:
223 * `VisualC-WinRT/UWP_VS2015/` - for Windows 10 / UWP apps
224 * `VisualC-WinRT/WinPhone81_VS2013/` - for Windows Phone 8.1 apps
225 * `VisualC-WinRT/WinRT80_VS2012/` - for Windows 8.0 apps
226 * `VisualC-WinRT/WinRT81_VS2013/` - for Windows 8.1 apps
2275. once the project has been added, right-click on your app's project and
228 select, "References..."
2296. click on the button titled, "Add New Reference..."
2307. check the box next to SDL
2318. click OK to close the dialog
2329. SDL will now show up in the list of references. Click OK to close that
233 dialog.
234
235Your project is now linked to SDL's project, insofar that when the app is
236built, SDL will be built as well, with its build output getting included with
237your app.
238
239
240### 4. Adjust Your App's Build Settings ###
241
242Some build settings need to be changed in your app's project. This guide will
243outline the following:
244
245- making sure that the compiler knows where to find SDL's header files
246- **Optional for C++, but NECESSARY for compiling C code:** telling the
247 compiler not to use Microsoft's C++ extensions for WinRT development.
248- **Optional:** telling the compiler not generate errors due to missing
249 precompiled header files.
250
251To change these settings:
252
2531. right-click on the project
2542. choose "Properties"
2553. in the drop-down box next to "Configuration", choose, "All Configurations"
2564. in the drop-down box next to "Platform", choose, "All Platforms"
2575. in the left-hand list, expand the "C/C++" section
2586. select "General"
2597. edit the "Additional Include Directories" setting, and add a path to SDL's
260 "include" directory
2618. **Optional: to enable compilation of C code:** change the setting for
262 "Consume Windows Runtime Extension" from "Yes (/ZW)" to "No". If you're
263 working with a completely C++ based project, this step can usually be
264 omitted.
2659. **Optional: to disable precompiled headers (which can produce
266 'stdafx.h'-related build errors, if setup incorrectly:** in the left-hand
267 list, select "Precompiled Headers", then change the setting for "Precompiled
268 Header" from "Use (/Yu)" to "Not Using Precompiled Headers".
26910. close the dialog, saving settings, by clicking the "OK" button
270
271
272### 5. Add a WinRT-appropriate main function, and a blank-cursor image, to the app. ###
273
274A few files should be included directly in your app's MSVC project, specifically:
2751. a WinRT-appropriate main function (which is different than main() functions on
276 other platforms)
2772. a Win32-style cursor resource, used by SDL_ShowCursor() to hide the mouse cursor
278 (if and when the app needs to do so). *If this cursor resource is not
279 included, mouse-position reporting may fail if and when the cursor is
280 hidden, due to possible bugs/design-oddities in Windows itself.*
281
282To include these files:
283
2841. right-click on your project (again, in Visual C++'s Solution Explorer),
285 navigate to "Add", then choose "Existing Item...".
2862. navigate to the directory containing SDL's source code, then into its
287 subdirectory, 'src/main/winrt/'. Select, then add, the following files:
288 - `SDL_winrt_main_NonXAML.cpp`
289 - `SDL2-WinRTResources.rc`
290 - `SDL2-WinRTResource_BlankCursor.cur`
2913. right-click on the file `SDL_winrt_main_NonXAML.cpp` (as listed in your
292 project), then click on "Properties...".
2934. in the drop-down box next to "Configuration", choose, "All Configurations"
2945. in the drop-down box next to "Platform", choose, "All Platforms"
2956. in the left-hand list, click on "C/C++"
2967. change the setting for "Consume Windows Runtime Extension" to "Yes (/ZW)".
2978. click the OK button. This will close the dialog.
298
299
300**NOTE: C++/CX compilation is currently required in at least one file of your
301app's project. This is to make sure that Visual C++'s linker builds a 'Windows
302Metadata' file (.winmd) for your app. Not doing so can lead to build errors.**
303
304
305### 6. Add app code and assets ###
306
307At this point, you can add in SDL-specific source code. Be sure to include a
308C-style main function (ie: `int main(int argc, char *argv[])`). From there you
309should be able to create a single `SDL_Window` (WinRT apps can only have one
310window, at present), as well as an `SDL_Renderer`. Direct3D will be used to
311draw content. Events are received via SDL's usual event functions
312(`SDL_PollEvent`, etc.) If you have a set of existing source files and assets,
313you can start adding them to the project now. If not, or if you would like to
314make sure that you're setup correctly, some short and simple sample code is
315provided below.
316
317
318#### 6.A. ... when creating a new app ####
319
320If you are creating a new app (rather than porting an existing SDL-based app),
321or if you would just like a simple app to test SDL/WinRT with before trying to
322get existing code working, some working SDL/WinRT code is provided below. To
323set this up:
324
3251. right click on your app's project
3262. select Add, then New Item. An "Add New Item" dialog will show up.
3273. from the left-hand list, choose "Visual C++"
3284. from the middle/main list, choose "C++ File (.cpp)"
3295. near the bottom of the dialog, next to "Name:", type in a name for your
330source file, such as, "main.cpp".
3316. click on the Add button. This will close the dialog, add the new file to
332your project, and open the file in Visual C++'s text editor.
3337. Copy and paste the following code into the new file, then save it.
334
335
336 #include <SDL.h>
337
338 int main(int argc, char **argv)
339 {
340 SDL_DisplayMode mode;
341 SDL_Window * window = NULL;
342 SDL_Renderer * renderer = NULL;
343 SDL_Event evt;
344
345 if (SDL_Init(SDL_INIT_VIDEO) != 0) {
346 return 1;
347 }
348
349 if (SDL_GetCurrentDisplayMode(0, &mode) != 0) {
350 return 1;
351 }
352
353 if (SDL_CreateWindowAndRenderer(mode.w, mode.h, SDL_WINDOW_FULLSCREEN, &window, &renderer) != 0) {
354 return 1;
355 }
356
357 while (1) {
358 while (SDL_PollEvent(&evt)) {
359 }
360
361 SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
362 SDL_RenderClear(renderer);
363 SDL_RenderPresent(renderer);
364 }
365 }
366
367
368#### 6.B. Adding code and assets ####
369
370If you have existing code and assets that you'd like to add, you should be able
371to add them now. The process for adding a set of files is as such.
372
3731. right click on the app's project
3742. select Add, then click on "New Item..."
3753. open any source, header, or asset files as appropriate. Support for C and
376C++ is available.
377
378Do note that WinRT only supports a subset of the APIs that are available to
379Win32-based apps. Many portions of the Win32 API and the C runtime are not
380available.
381
382A list of unsupported C APIs can be found at
383<http://msdn.microsoft.com/en-us/library/windows/apps/jj606124.aspx>
384
385General information on using the C runtime in WinRT can be found at
386<https://msdn.microsoft.com/en-us/library/hh972425.aspx>
387
388A list of supported Win32 APIs for WinRT apps can be found at
389<http://msdn.microsoft.com/en-us/library/windows/apps/br205757.aspx>. To note,
390the list of supported Win32 APIs for Windows Phone 8.0 is different.
391That list can be found at
392<http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj662956(v=vs.105).aspx>
393
394
395### 7. Build and run your app ###
396
397Your app project should now be setup, and you should be ready to build your app.
398To run it on the local machine, open the Debug menu and choose "Start
399Debugging". This will build your app, then run your app full-screen. To switch
400out of your app, press the Windows key. Alternatively, you can choose to run
401your app in a window. To do this, before building and running your app, find
402the drop-down menu in Visual C++'s toolbar that says, "Local Machine". Expand
403this by clicking on the arrow on the right side of the list, then click on
404Simulator. Once you do that, any time you build and run the app, the app will
405launch in window, rather than full-screen.
406
407
408#### 7.A. Running apps on older, ARM-based, "Windows RT" devices ####
409
410**These instructions do not include Windows Phone, despite Windows Phone
411typically running on ARM processors.** They are specifically for devices
412that use the "Windows RT" operating system, which was a modified version of
413Windows 8.x that ran primarily on ARM-based tablet computers.
414
415To build and run the app on ARM-based, "Windows RT" devices, you'll need to:
416
417- install Microsoft's "Remote Debugger" on the device. Visual C++ installs and
418 debugs ARM-based apps via IP networks.
419- change a few options on the development machine, both to make sure it builds
420 for ARM (rather than x86 or x64), and to make sure it knows how to find the
421 Windows RT device (on the network).
422
423Microsoft's Remote Debugger can be found at
424<https://msdn.microsoft.com/en-us/library/hh441469.aspx>. Please note
425that separate versions of this debugger exist for different versions of Visual
426C++, one each for MSVC 2015, 2013, and 2012.
427
428To setup Visual C++ to launch your app on an ARM device:
429
4301. make sure the Remote Debugger is running on your ARM device, and that it's on
431 the same IP network as your development machine.
4322. from Visual C++'s toolbar, find a drop-down menu that says, "Win32". Click
433 it, then change the value to "ARM".
4343. make sure Visual C++ knows the hostname or IP address of the ARM device. To
435 do this:
436 1. open the app project's properties
437 2. select "Debugging"
438 3. next to "Machine Name", enter the hostname or IP address of the ARM
439 device
440 4. if, and only if, you've turned off authentication in the Remote Debugger,
441 then change the setting for "Require Authentication" to No
442 5. click "OK"
4434. build and run the app (from Visual C++). The first time you do this, a
444 prompt will show up on the ARM device, asking for a Microsoft Account. You
445 do, unfortunately, need to log in here, and will need to follow the
446 subsequent registration steps in order to launch the app. After you do so,
447 if the app didn't already launch, try relaunching it again from within Visual
448 C++.
449
450
451Troubleshooting
452---------------
453
454#### Build fails with message, "error LNK2038: mismatch detected for 'vccorlib_lib_should_be_specified_before_msvcrt_lib_to_linker'"
455
456Try adding the following to your linker flags. In MSVC, this can be done by
457right-clicking on the app project, navigating to Configuration Properties ->
458Linker -> Command Line, then adding them to the Additional Options
459section.
460
461* For Release builds / MSVC-Configurations, add:
462
463 /nodefaultlib:vccorlib /nodefaultlib:msvcrt vccorlib.lib msvcrt.lib
464
465* For Debug builds / MSVC-Configurations, add:
466
467 /nodefaultlib:vccorlibd /nodefaultlib:msvcrtd vccorlibd.lib msvcrtd.lib
468
469
470#### Mouse-motion events fail to get sent, or SDL_GetMouseState() fails to return updated values
471
472This may be caused by a bug in Windows itself, whereby hiding the mouse
473cursor can cause mouse-position reporting to fail.
474
475SDL provides a workaround for this, but it requires that an app links to a
476set of Win32-style cursor image-resource files. A copy of suitable resource
477files can be found in `src/main/winrt/`. Adding them to an app's Visual C++
478project file should be sufficient to get the app to use them.
479
README.md
1Simple DirectMedia Layer {#mainpage}
2========================
3
4 (SDL)
5
6 Version 2.0
7
8---
9http://www.libsdl.org/
10
11Simple DirectMedia Layer is a cross-platform development library designed
12to provide low level access to audio, keyboard, mouse, joystick, and graphics
13hardware via OpenGL and Direct3D. It is used by video playback software,
14emulators, and popular games including Valve's award winning catalog
15and many Humble Bundle games.
16
17SDL officially supports Windows, Mac OS X, Linux, iOS, and Android.
18Support for other platforms may be found in the source code.
19
20SDL is written in C, works natively with C++, and there are bindings
21available for several other languages, including C# and Python.
22
23This library is distributed under the zlib license, which can be found
24in the file "COPYING.txt".
25
26The best way to learn how to use SDL is to check out the header files in
27the "include" subdirectory and the programs in the "test" subdirectory.
28The header files and test programs are well commented and always up to date.
29
30More documentation and FAQs are available online at [the wiki](http://wiki.libsdl.org/)
31
32- [Android](README-android.md)
33- [CMake](README-cmake.md)
34- [DirectFB](README-directfb.md)
35- [DynAPI](README-dynapi.md)
36- [Emscripten](README-emscripten.md)
37- [Gesture](README-gesture.md)
38- [Mercurial](README-hg.md)
39- [iOS](README-ios.md)
40- [Linux](README-linux.md)
41- [OS X](README-macosx.md)
42- [Native Client](README-nacl.md)
43- [Pandora](README-pandora.md)
44- [Supported Platforms](README-platforms.md)
45- [Porting information](README-porting.md)
46- [PSP](README-psp.md)
47- [Raspberry Pi](README-raspberrypi.md)
48- [Touch](README-touch.md)
49- [WinCE](README-wince.md)
50- [Windows](README-windows.md)
51- [WinRT](README-winrt.md)
52
53If you need help with the library, or just want to discuss SDL related
54issues, you can join the [developers mailing list](http://www.libsdl.org/mailing-list.php)
55
56If you want to report bugs or contribute patches, please submit them to
57[bugzilla](http://bugzilla.libsdl.org/)
58
59Enjoy!
60
61
62Sam Lantinga <mailto:slouken@libsdl.org>
63
64