You can create your Mac OS X applications in two ways:
By default, on Mac OS X, this means that your applications will use Carbon, which is a built-in library on Mac OS X. So, your programs don't require anything extra.
(You can switch Lazarus widgetset, though, to use a different library under the hood.)
Alternatively, you can create your windows using our own TCastleWindow class.
By default, on Mac OS X, this means that your applications will use X11, GTK and GtkGLExt libraries. These are not installed by default on Mac OS X, at least not all of them. To install them:
Or, you can switch the backend of
TCastleWindow to use Lazarus under the hood, and this way we will use Carbon instead.
This means that TCastleWindow will actually use Lazarus
To do this, use the package
This will give you
CastleWindow unit that uses LCL and requires
the castle_components package.
If you open an existing source code,
like view3dscene, you will have to change the dependencies in Lazarus Project inspector
alternative_castle_window_based_on_lcl instead of
On Mac OS X, the default LCL widgetset is Carbon right now.
Good: native look, application has a normal menu bar,
shows native dialog boxes (to open/save file, choose color and such)
and generally looks and feels like every other Mac OS X application.
Lazarus compiles it into a bundle like
that can be easily installed by dragging to your Applications
Good: no extra dependencies, Carbon is already part of every Mac OS X installation. (No dependencies on X11, GTK, GTKGlExt etc.)
Bad: Unfortunately, Carbon is deprecated by Apple (although there are many applications using it, including Lazarus IDE itself). It is available only for 32-bit applications.
In time, this will be resolved in LCL when Cocoa widgetset will be more complete. Right now, Carbon implementation is just more complete than Cocoa in LCL, see also Choice of Lazarus LCL widgetsets (for Mac OS X).
It may also be resolved on our side if we ever make direct
CastleWindow backend based on Cocoa (without using Lazarus LCL):
It's a matter of creating and implementing a file
See engine sources.
See at other "backends" (like GTK, WinAPI, Xlib, LCL)
for examples how to implement such thing, everything is inside
Alternatively, send Michalis a simple and clear example of FPC program using Cocoa that 1. creates and shows a window 2. with menu bar 3. and with OpenGL context area covering the window. I should be able to port such example to my "CastleWindow" then.
Bad: There are issues with LCL event loop. Some of them (not being able to get Update events continously) are in bare LCL, some of them (the need to call Application.Run, not just loop using Application.ProcessMessages) are specific to LCL-Carbon. The former (Update issues when using mouse look or dragging with mouse) is somewhat workarounded on our side now (to not "stutter" when using mouse look), but the problem is still noticeable (mouse look under other TCastleWindow backends is much smoother).
For the above reasons:
Although full-screen is ugly on Xlib, there's no way to hide dock over fullscreen application in this situation... Easiest solution in this case is to keep your game windowed on Mac OS X.
view3dscene uses a standard OS console for some stuff (e.g. for Console -> Print Current Camera...). You will not see this console if you run the program using the bundle (by double-clicking on the app in Finder, or in dock...).
To see the console output, run view3dscene from terminal:
cd directory-where-you-installed-view3dscene/ ./view3dscene.app/Contents/MacOS/view3dscene
For Mac OS X older than Tiger (that is, 10.3 or older): install OpenAL to have game sounds. It may be downloaded from Creative, see download links from openal.org downloads. For Mac OS X since Tiger, OpenAL comes already preinstalled. Even without OpenAL installed, all our programs will still work fine, you just will not get any sound.
Without vorbisfile, all our programs will still work fine, but you will not hear OggVorbis music.
If you decide to use external libpng implementation in your programs, that you will also need libpng to open and save images and textures in PNG format. It may be installed using MacPorts, Homebrew or Fink.
Note that this is not necessary by default.
By default, we use FpImage right now to read PNG,
and it works without the need for libpng.
You can edit the
configuration file to change this.
To actually compile our programs on Mac OS X, you need the Free Pascal Compiler. For comfortable RAD development, install also Lazarus (FPC is already included inside Lazarus installations, if you choose normal packages).
Besides easy upgrades, the advantage of using the package manager to install the compiler is that it's easier then to install the libraries (like GTK2 and GtkGLExt) with the same architecture (32-bit vs 64-bit). Otherwise, be careful to watch for it yourself: your system may host both 32-bit and 64-bit binaries and libraries, but to compile a 64-bit application, you will need a compiler (FPC) that targets 64-bit processors and 64-bit libraries.
On modern Mac OS X versions, you usually just want to install x86_64 libraries, and the FPC compiler for Darwin+x86_64.
To install GTK, GtkGLExt and FPC, simply do:
sudo port install gtkglext sudo port install fpc
Then create your local FPC config, and add there macports libraries:
~/.fpc.cfgand paste there
~/.fpc.cfgadd this line:
/opt/local/lib/fpc/bin, so add something like this to your
To install FPC with Homebrew, you simply do
brew install fpc
fpc is already on $PATH, so it's comfortable out-of-the-box.
Installing additional libraries, like GTK or GtkGLExt, is equally trivial.
As of fink 0.29.21 (on Mac OS X 10.6.7), you should additionally install
the fink "
pango1-xft2-shlibs" package. Simple "
fink install pango1-xft2-shlibs"
should do the trick. This is necessary for successful linking.
For libraries installed by fink, you may have to add them to your libs path by command like
before executing programs. (you can add this to your
or similar file for comfort).
For developers: The linker must know the location of fink and X11
libraries. If you have installed fink and X11 in standard locations,
you can simply add these lines to your
(see FPC documentation "Configuration file" to know where you can find your
A bunch of information about packaging your programs for Mac OS X follows.
Make "Mac OS X bundle". It's basically a directory pretending to be an application.
You can use Lazarus to create Mac OS X bundle. Or you can use our script (see script create_macosx_bundle.sh in our SVN repository), example usage is inside view3dscene sources.
Optionally, add libraries (like libpng and vorbisfile) to the bundle.
If you link to them dynamically (e.g. using our
you should load them from a path relative to
BundlePath + 'Contents/MacOS/libpng.dylib'.
See Mac OS X Libraries on FPC wiki for general instructions how to include library inside a bundle.
Pack into a nice .dmg file. See Building Fancy DMG Images on Mac OS X for nice description how to make the directories inside dmg look pretty, so you can visually suggest user to drag your application in the Applications folder.
Alternative method of distribution Mac OS X applications is the package manager (.pkg). For normal applications (like games) the simpler .dmg is a better choice.