README.MacOSX
author Sam Lantinga <slouken@libsdl.org>
Thu, 02 Apr 2009 04:43:36 +0000
branchSDL-1.2
changeset 4167 a6f635e5eaa6
parent 1839 78da406ad139
child 5895 402eac854030
child 6987 7084af936d82
permissions -rw-r--r--
Fixed bug #611

From Tim Angus 2008-08-12 11:18:06

I'm one of the maintainers of ioquake3.org, an updated version of the
Quake 3 engine. Relatively recently, we moved ioq3 to use SDL as a
replacement for 95% of the platform specific code that was there. On the
whole it's doing a great job but unfortunately since the move we've been
getting complaints about the quality of the mouse input on the Windows
platform to the point where for many the game is unplayable. Put in
other terms, the current stable SDL 1.2 is basically not fit for purpose
if you need high quality mouse input as you do in a first person shooter.

Over the weekend I decided to pull my finger out and actually figure out
what's going on. There are basically two major problems. Firstly, when
using the "windib" driver, mouse input is gathered via the WM_MOUSEMOVE
message. Googling for this indicates that often this is known to result
in "spurious" and/or "missing" mouse movement events; this is the
primary cause of the poor mouse input. The second problem is that the
"directx" driver does not work at all in combination with OpenGL meaning
that you can't use DirectInput if your application also uses OpenGL. In
other words you're locked into using the "windib" driver and its poor
mouse input.

In order to address these problems I've done the following:

* Remove WM_MOUSEMOVE based motion event generation and replace with
calls to GetCursorPos which seems much more reliable. In order to
achieve this I've moved mouse motion out into a separate function that
is called once per DIB_PumpEvents.

* Remove the restriction on the "directx" driver being inoperable in
combination with OpenGL. There is a bug for this issues that I've
hijacked to a certain extent
(http://bugzilla.libsdl.org/show_bug.cgi?id=265). I'm the first to admit
I don't really understand why this restriction is there in the first
place. The commit message for the bug fix that introduced this
restriction (r581) isn't very elaborate and I couldn't see any other bug
tracking the issue. If anyone has more information on the bug that was
avoided by r581 it would be helpful as I/someone could then look into
addressing the problem without disabling the "directx" driver.

* I've also removed the restriction on not being allowed to use
DirectInput in windowed mode. I couldn't see any reason for this, at
least not from our perspective. I have my suspicions that it'll be
something like matching up the cursor with the mouse coordinates...

* I bumped up the DirectInput API used to version 7 in order to get
access to mouse buttons 4-7. I've had to inject a little bit of the DX7
headers into SDL there as the MinGW ones aren't up to date in this respect.
slouken@0
     1
==============================================================================
slouken@0
     2
Using the Simple DirectMedia Layer with Mac OS X
slouken@0
     3
==============================================================================
slouken@0
     4
slouken@0
     5
These instructions are for people using Apple's Mac OS X (pronounced
slouken@0
     6
"ten").
slouken@0
     7
slouken@0
     8
From the developer's point of view, OS X is a sort of hybrid Mac and
slouken@0
     9
Unix system, and you have the option of using either traditional
slouken@1006
    10
command line tools or Apple's IDE Xcode.
slouken@0
    11
slouken@869
    12
To build SDL using the command line, use the standard configure and make
slouken@0
    13
process:
slouken@0
    14
slouken@0
    15
	./configure
slouken@0
    16
	make
slouken@869
    17
	sudo make install
slouken@0
    18
slouken@1649
    19
You can also build SDL as a Universal library (a single binary for both
slouken@1649
    20
PowerPC and Intel architectures), on Mac OS X 10.4 and newer, by using
slouken@1649
    21
the fatbuild.sh script in build-scripts:
slouken@1649
    22
	sh build-scripts/fatbuild.sh
slouken@1649
    23
	sudo build-scripts/fatbuild.sh install
slouken@1839
    24
This script builds SDL with 10.2 ABI compatibility on PowerPC and 10.4
slouken@1839
    25
ABI compatibility on Intel architectures.  For best compatibility you
slouken@1839
    26
should compile your application the same way.  A script which wraps
slouken@1839
    27
gcc to make this easy is provided in test/gcc-fat.sh
slouken@0
    28
slouken@172
    29
To use the library once it's built, you essential have two possibilities:
slouken@1650
    30
use the traditional autoconf/automake/make method, or use Xcode.
slouken@172
    31
slouken@172
    32
==============================================================================
slouken@172
    33
Using the Simple DirectMedia Layer with a traditional Makefile
slouken@172
    34
==============================================================================
slouken@172
    35
slouken@221
    36
An existing autoconf/automake build system for your SDL app has good chances
slouken@1621
    37
to work almost unchanged on OS X. However, to produce a "real" Mac OS X binary
slouken@221
    38
that you can distribute to users, you need to put the generated binary into a
slouken@221
    39
so called "bundle", which basically is a fancy folder with a name like
slouken@221
    40
"MyCoolGame.app".
slouken@172
    41
slouken@221
    42
To get this build automatically, add something like the following rule to
slouken@221
    43
your Makefile.am:
slouken@172
    44
slouken@199
    45
bundle_contents = APP_NAME.app/Contents
slouken@199
    46
APP_NAME_bundle: EXE_NAME
slouken@199
    47
	mkdir -p $(bundle_contents)/MacOS
slouken@199
    48
	mkdir -p $(bundle_contents)/Resources
slouken@199
    49
	echo "APPL????" > $(bundle_contents)/PkgInfo
slouken@199
    50
	$(INSTALL_PROGRAM) $< $(bundle_contents)/MacOS/
slouken@172
    51
slouken@221
    52
You should replace EXE_NAME with the name of the executable. APP_NAME is what
slouken@221
    53
will be visible to the user in the Finder. Usually it will be the same
slouken@221
    54
as EXE_NAME but capitalized. E.g. if EXE_NAME is "testgame" then APP_NAME 
slouken@221
    55
usually is "TestGame". You might also want to use @PACKAGE@ to use the package
slouken@221
    56
name as specified in your configure.in file.
slouken@172
    57
slouken@221
    58
If your project builds more than one application, you will have to do a bit
slouken@221
    59
more.  For each of your target applications, you need a seperate rule.
slouken@172
    60
slouken@221
    61
If you want the created bundles to be installed, you may want to add this
slouken@221
    62
rule to your Makefile.am:
slouken@172
    63
slouken@199
    64
install-exec-hook: APP_NAME_bundle
slouken@199
    65
	rm -rf $(DESTDIR)$(prefix)/Applications/APP_NAME.app
slouken@199
    66
	mkdir -p $(DESTDIR)$(prefix)/Applications/
slouken@199
    67
	cp -r $< /$(DESTDIR)$(prefix)Applications/
slouken@172
    68
slouken@221
    69
This rule takes the Bundle created by the rule from step 3 and installs them
slouken@221
    70
into $(DESTDIR)$(prefix)/Applications/.
slouken@172
    71
slouken@221
    72
Again, if you want to install multiple applications, you will have to augment
slouken@221
    73
the make rule accordingly.
slouken@172
    74
slouken@0
    75
slouken@869
    76
But beware! That is only part of the story! With the above, you end up with
slouken@869
    77
a bare bone .app bundle, which is double clickable from the Finder. But
slouken@869
    78
there are some  more things you should do before shipping yor product...
slouken@869
    79
slouken@869
    80
1) The bundle right now probably is dynamically linked against SDL. That 
slouken@869
    81
   means that when you copy it to another computer, *it will not run*,
slouken@869
    82
   unless you also install SDL on that other computer. A good solution
slouken@869
    83
   for this dilemma is to static link against SDL. On OS X, you can
slouken@869
    84
   achieve that by linkinag against the libraries listed by
slouken@869
    85
     sdl-config --static-libs
slouken@869
    86
   instead of those listed by
slouken@869
    87
     sdl-config --libs
slouken@869
    88
   Depending on how exactly SDL is integrated into your build systems, the
slouken@869
    89
   way to achieve that varies, so I won't describe it here in detail
slouken@869
    90
2) Add an 'Info.plist' to your application. That is a special XML file which
slouken@869
    91
   contains some meta-information about your application (like some copyright
slouken@869
    92
   information, the version of your app, the name of an optional icon file,
slouken@869
    93
   and other things). Part of that information is displayed by the Finder
slouken@869
    94
   when you click on the .app, or if you look at the "Get Info" window.
slouken@869
    95
   More information about Info.plist files can be found on Apple's homepage.
slouken@869
    96
slouken@869
    97
slouken@869
    98
As a final remark, let me add that I use some of the techniques (and some
slouken@869
    99
variations of them) in Exult and ScummVM; both are available in source on
slouken@869
   100
the net, so feel free to take a peek at them for inspiration!
slouken@869
   101
slouken@869
   102
slouken@47
   103
==============================================================================
slouken@1006
   104
Using the Simple DirectMedia Layer with Xcode
slouken@47
   105
==============================================================================
slouken@0
   106
slouken@1006
   107
These instructions are for using Apple's Xcode IDE to build SDL applications.
slouken@0
   108
slouken@53
   109
- First steps
slouken@53
   110
slouken@1006
   111
The first thing to do is to unpack the Xcode.tar.gz archive in the
slouken@1006
   112
top level SDL directory (where the Xcode.tar.gz archive resides).
slouken@53
   113
Because Stuffit Expander will unpack the archive into a subdirectory,
slouken@53
   114
you should unpack the archive manually from the command line:
slouken@53
   115
	cd [path_to_SDL_source]
slouken@1006
   116
	tar zxf Xcode.tar.gz
slouken@1006
   117
This will create a new folder called Xcode, which you can browse
slouken@53
   118
normally from the Finder.
slouken@53
   119
slouken@47
   120
- Building the Framework
slouken@47
   121
slouken@47
   122
The SDL Library is packaged as a framework bundle, an organized
slouken@47
   123
relocatable folder heirarchy of executible code, interface headers, 
slouken@47
   124
and additional resources. For practical purposes, you can think of a 
slouken@47
   125
framework as a more user and system-friendly shared library, whose library
slouken@47
   126
file behaves more or less like a standard UNIX shared library.
slouken@47
   127
slouken@47
   128
To build the framework, simply open the framework project and build it. 
slouken@47
   129
By default, the framework bundle "SDL.framework" is installed in 
slouken@1006
   130
/Library/Frameworks. Therefore, the testers and project stationary expect
slouken@47
   131
it to be located there. However, it will function the same in any of the
slouken@47
   132
following locations:
slouken@47
   133
slouken@47
   134
    ~/Library/Frameworks
slouken@47
   135
    /Local/Library/Frameworks
slouken@47
   136
    /System/Library/Frameworks
slouken@47
   137
slouken@47
   138
- Build Options
slouken@47
   139
    There are two "Build Styles" (See the "Targets" tab) for SDL.
slouken@47
   140
    "Deployment" should be used if you aren't tweaking the SDL library.
slouken@47
   141
    "Development" should be used to debug SDL apps or the library itself.
slouken@47
   142
slouken@47
   143
- Building the Testers
slouken@47
   144
    Open the SDLTest project and build away!
slouken@47
   145
slouken@47
   146
- Using the Project Stationary
slouken@47
   147
    Copy the stationary to the indicated folders to access it from
slouken@47
   148
    the "New Project" and "Add target" menus. What could be easier?
slouken@47
   149
slouken@47
   150
- Setting up a new project by hand
slouken@47
   151
    Some of you won't want to use the Stationary so I'll give some tips:
slouken@47
   152
    * Create a new "Cocoa Application"
slouken@207
   153
    * Add src/main/macosx/SDLMain.m , .h and .nib to your project
slouken@47
   154
    * Remove "main.c" from your project
slouken@47
   155
    * Remove "MainMenu.nib" from your project
slouken@47
   156
    * Add "$(HOME)/Library/Frameworks/SDL.framework/Headers" to include path
slouken@47
   157
    * Add "$(HOME)/Library/Frameworks" to the frameworks search path
slouken@207
   158
    * Add "-framework SDL -framework Foundation -framework AppKit" to "OTHER_LDFLAGS"
slouken@207
   159
    * Set the "Main Nib File" under "Application Settings" to "SDLMain.nib"
slouken@47
   160
    * Add your files
slouken@47
   161
    * Clean and build
slouken@47
   162
slouken@47
   163
- Building from command line
slouken@47
   164
    Use pbxbuild in the same directory as your .pbproj file
slouken@47
   165
         
slouken@47
   166
- Running your app
slouken@47
   167
    You can send command line args to your app by either invoking it from
slouken@47
   168
    the command line (in *.app/Contents/MacOS) or by entering them in the
slouken@47
   169
    "Executibles" panel of the target settings.
slouken@47
   170
    
slouken@47
   171
- Implementation Notes
slouken@47
   172
    Some things that may be of interest about how it all works...
slouken@47
   173
    * Working directory
slouken@191
   174
        As defined in the SDL_main.m file, the working directory of your SDL app
slouken@47
   175
        is by default set to its parent. You may wish to change this to better
slouken@47
   176
        suit your needs.
slouken@47
   177
    * You have a Cocoa App!
slouken@47
   178
        Your SDL app is essentially a Cocoa application. When your app
slouken@47
   179
        starts up and the libraries finish loading, a Cocoa procedure is called,
slouken@47
   180
        which sets up the working directory and calls your main() method.
slouken@47
   181
        You are free to modify your Cocoa app with generally no consequence 
slouken@47
   182
        to SDL. You cannot, however, easily change the SDL window itself.
slouken@47
   183
        Functionality may be added in the future to help this.
slouken@207
   184
	
slouken@207
   185
slouken@0
   186
Known bugs are listed in the file "BUGS"