Showing posts with label osx. Show all posts
Showing posts with label osx. Show all posts

Sunday, 6 March 2011

Allegro 5.0 on Mac Snow Leopard

For more notes on Allegro 5 on Lion and Xcode 4 see this post.

I had been experimenting with Allegro 4.4, but now Allegro 5.0.0 has arrived. Apparently version 5.0 has had its API revamped and more functionality added, so I decided to give it a go. I believe it now expects hardware acceleration and has drivers for OpenGL and DirectX. Its appeal lies in its simplicity, good support, and is very cross platform, supporting Windows, Linux, OSX, iPhone, etc.

Build notes:

Dependencies

Previously I had been building libraries from their source and installing them in /usr/local using the usual UNIX build routine (i.e. download source and make). This is somewhat laborious and can be time consuming if something goes wrong (because not OSX compatible). This time round I decided to use MacPorts to do the lifting for me. This saves a lot of time. Just follow their standard installation instructions.

Then you need to install the libraries that you will need to compile Allegro 5. These are listed on this page, but aren't quite correct. I used:
sudo port install zlib freetype jpeg libogg libvorbis
Some of these need to be compiled in "universal" mode as they are compiled in 64 bit by default (which is the default of the compiler, new on OSX 10.6):
sudo port upgrade --enforce-variants libpng +universal
sudo port upgrade --enforce-variants physfs +universal
This will take a while if you are doing this from scratch (20+ mins). After this you should have a new /opt directory, which contains a load of new libraries. You can type "port installed" to see what you have. Some libraries will have "+universal" next to them.

Now download the Allegro 5 source, or get latest from svn. You can repeat the steps from here onwards when you get new versions of Allegro.

To build Allegro you can either build libraries or a framework, and you can either use makefiles or Xcode project files. I built libraries using Xcode 3, and now frameworks using makefiles. Frameworks are more in fitting with the Mac way of doing things, so probably best to use those.

Xcode 3 - Static library

To build using Xcode: Snow Leopard GCC compiles 64-bit code by default, but Allegro is not a 64-bit library, so we want to compile everything as i386. We first generate the Xcode files and then load them in Xcode 3 and change the settings for 32 bit (i386):
  • cd to/allegro
  • mkdir build
  • cd build
  • cmake -G Xcode ..
This will do a load of scanning for the dependencies it needs and then you'll end up with an Xcode project file: ALLEGRO.xcodeproj. This can be opened using Xcode 3 or 4. Although, at the current point (July 2011) I wouldn't recommend Xcode 4, it's just not ready.

For Xcode 3: open the the project file and (in the root project at the top):
  • Change the Architectures to 32-bit Universal.
  • I chose the RelWithDebInfo configuration. I haven't tried the others.
  • Change the active architecture to i386. This is important as Allegro is 32-bit.
  • Reading this article is useful if you don't know which SDK to use.
Build the ALL_BUILD target. You can run A5teroids and some of the example to check that it all works.

Sorry, I haven't built this using the project for Xcode 4. Use the frameworks below if you can't manage it. That's what I am using.

The install will fail because the script it is trying to run needs root access. So go back to the terminal and run the install command manually:
sudo cmake -DBUILD_TYPE=RelWithDbgInfo -P cmake_install.cmake
Then the Allegro files will be installed in /usr/local and you can include and link then from the usual places.

Frameworks

OSX 10.6 switched from 32 bit to 64 bit. Allegro needs to be compiled as 32 bit (i386). So we do the following in the unpacked allegro directory:
  • mkdir build
  • cd build
  • cmake -DWANT_FRAMEWORKS=1 -DCMAKE_OSX_ARCHITECTURES=i386 ..
  • make
  • make install
And Bob is your Auntie.

Hopefully at some point some kind person will add Allegro 5 to MacPorts to save having to do this.


New Project

The easiest way to set a new project up is to create a command-line application in Xcode. However, if we want to package all the assets, like normal Mac applications, you need to create a Cocoa application ("New Project..." > "Cocoa Application").

In the project settings, add "/usr/local/include" as a user header path. This will include the Allegro file that we just installed above. In targets, right click on your application and choose "Add..." and add existing files "/usr/local/lib/liballegro.dylib" and "/usr/local/lib/liballegro_main.dylib". Now, you should be able to build and run your application. However, two windows will appear! This is because the liballegro_main stub will create a window as well as your default application having one (in the .xib).

To remove the default app window (because we want the Allegro one) look in the "resources" folder and open "MainMenu.xib". This brings up the interface designer. In the list of objects, delete the NSWindow object, this will stop two windows being created when the application starts. We also don't need the auto-generated stub code for the application either, so you delete the "main.m" and "app delegate.m" files. You can also delete items from the menu you don't want by dragging them onto the desktop (and they disappear in a puff of smoke). If you build and run you should have one window now.

There is a tutorial on Allegro 5 on the wiki. The API looks a bit more tidy and better namespaced now.


[6-Mar-11] - Updated for Allegro 5.0.0. Notes were previously for the release candidates.
[25-Mar-11] - Added missing libvorbis to port install.
[26-Apr-11] - Using Xcode 3 for building. Xcode 4 wasn't available when this was written.
[7-Jul-11] - Notes for building with frameworks and Macports 32-bit builds.


Sunday, 24 January 2010

Building pygame on OSX Snow Leopard

The version of pygame available on the pygame site works for the python.org version of Python. I want one for the system Python (2.6.1 64-bit). I decided to revisit this after giving up (very easily) the first time.
  • First, get pygame source. I'm trying with 1.9.1 release. This sounds like recipe now.
  • Untar the source and python config.py reveals some dependencies are necessary. Config will show you which ones you have available.
  • The pygame dependencies are as follows. So we'll need collect these. Notes follow.
    • SDL.
    • SDL_ttf  (fonts).
    • SDL_image.
    • SDL_mixer.
    • smpeg.
    • PNG.
    • JPEG.
    • SCRAP  (cross-platform clipboard).
    • PortMIDI.
SDL
  • There is a Mac SDL 1.2 package on the downloads page.
  • I got SDL-1.2.14.dmg.
  • Version 1.2.14 has Snow Leopard support according to the ReadMe.txt and is the minimum requirement. See notes below from UniversalBinaryNotes file:
64-bit Universal Binary Notes:
SDL 1.2.14 is our first release with Snow Leopard on the market. In order to make SDL compile and run in 64-bit, we had to remove code that depended on deprecated Mac APIs and move over to more modern Mac APIs.
In addition, Apple has stopped shipping gcc 3.3 and the 10.3 SDK.
Because of all these combined factors, we have made the decision to make Mac OS X 10.4 the new minimum requirement for SDL.
Our official SDL.framework is compiled as a 3-way Universal Binary (64-bit Intel, 32-bit Intel, 32-bit PowerPC.)
Certain APIs that SDL relies on were not made 64-bit ready by Apple until 10.6. This means even though 10.5 had preliminary 64-bit support, SDL will not compile or run correctly in 64-bit mode on 10.5. So there are two fallout items from this.
First, you can only compile 64-bit code on Snow Leopard or greater (which removes the possibility of 64-bit PowerPC). 
Second, this presents a corner-case where if you have a 64-bit Intel executable in your Universal binary and try to run on 10.5 on an 64-bit Intel Mac, it will launch and crash. To force 10.5 to use the 32-bit version instead of the 64-bit, you should set the LaunchServices key, LSMinimumSystemVersionByArchitecture, in your application's Info.plist. Our SDL/Xcode templates for Snow Leopard already set this up for you.
One additional fallout item is we had to remove the SDL Custom Cocoa Xcode template project. It depended on NSQuickTimeView which was deprecated and removed from the SDL codebase. It may still be possible to recreate the behavior that this template demonstrated, but we would need a volunteer to investigate this.
In addition, the SDL satellite projects were affected by the 64-bit transition.
- SDL_mixer depended on legacy Quicktime for midi playback support. We had to disable midi. (Recall that we also disabled MP3 support awhile back because we never got SMPEG working during the Tiger/Intel transition.) To fix this, we would need a native Core Audio backend for SDL_mixer.
- Since we have changed the baseline to 10.4, we took this opportunity to switch SDL_image over to a new native ImageIO based backend. This makes the binary about 10x smaller, greatly simplifies our maintenance requirements and build process as we no longer have to maintain build systems for 3rd party dependencies, and gives us access to more image formats.
- The static library target for SDL_ttf no longer works because we no longer have access to a libfreetype.a. We have been relying on Apple's supplied libfreetype.a, but they stopped shipping a static version starting in 10.5 which means we have no static 64-bit version. But since 10.4 is our new baseline, all these systems should have libfreetype.dylib installed, so it shouldn't be much of a problem to use SDL_ttf as a dynamic library which dynamically links to libfreetype.
-Eric Wing 2009-09-23
  • To install SDL 1.2.14 we copy the SDL.framework to /Library/Frameworks:
    • sudo cp -r /Volumes/SDL/SDL.framework/ /Library/Frameworks/SDL.framework
SDL_ttf
  • There is a Mac OSX package on ttf project page.
  • I got version 2.0.9.
  • sudo cp -r /Volumes/SDL_ttf/SDL_ttf.framework/ /Library/Frameworks/SDL_ttf.framework
SDL_image
  • Get package from image project page.
  • I got version 1.2.10.
  • sudo cp -r /Volumes/SDL_image/SDL_image.framework/ /Library/Frameworks/SDL_image.framework
SDL_mixer
  • Get package from mixer project page.
  • I got version 1.2.11.
  • sudo cp -r /Volumes/SDL_mixer/SDL_mixer.framework/ /Library/Frameworks/SDL_mixer.framework
smpeg
  • From icculus page.
  • svn co svn://svn.icculus.org/smpeg/trunk smpeg
  • We'll skip this for, it's optional.
PNG
  • Get libPNG from the Sourceforge project download page. I got 1.2.42.
  • Don't run configure. Instead: cp scripts/makefile.darwin Makefile
  • make
  • sudo make install
JPEG
PortMIDI

  • Source is hosted on Sourceforge. 
  • I got version 2.00. Fairly new. 
  • Note: PortMIDI uses cmake to generate makefiles. So you'll need to have that installed. I have version 2.8.0. 
  • make -f pm_mac/Makefile.osx 
  • cd Release 
  • sudo make install 
SCRAP

I think this is support for the clipboard for pygame. We are missing sdl-config from our SDL framework install so we can't configure SCRAP to build it. We'll skip this.

Building pygame

So after all that palaver, you can now go to the pygame source and run the config.py.

One problem: Portmidi seems to have changed the name of its static library. It now has "_s" appended. config_darwin.py needs editing:
config_darwin.py:    Dependency('PORTMIDI', 'portmidi.h', 'libportmidi_s', ['portmidi']),
    Now:
    • python config.py
    • python setup.py build
    • sudo python setup.py install

    After testing... some of the examples work, but fonts don't. :(  This is something to do with SDL linking with a new dynamic library version of freetype which I think is in the /usr/X11/lib direcotory, but this isn't in the dlopen path... Grrr.


    Sunday, 17 January 2010

    Building PyQt4 on Snow Leopard

    Here are some notes on building PyQt4 on OSX 10.6 as I always seem to miss a step every time I do this! It should be very similar for all POSIX systems except for a few flags here and there.

    My set up: Intel MacBook Pro, OSX 10.6.2, Python 2.6.1 (Apple system python 64-bit, not python.org 32-bit Python).

    Get Qt LGPL package. Note, you want the Qt Cocoa libraries as PyQt4 expects 64 bit libraries. The default libraries in the Qt SDK are for Carbon (32-bit) for backwards compatibility. Snow Leopard gcc compiles 64-bit code by default.
    Get latest sip. Build and install:
    • python configure.py
    • Check configuration is what you want.
    • make
    • sudo make install
    Get QScintilla package from Riverbank.
    • cd Qt4
    • qmake -spec macx-g++ qscintilla.pro
    • make
    • sudo make install
    • make clean
    Now get Mac PyQt4 from Riverbank:
    • python configure.py
    • Accept the GPL license.
    • Check the configuration log doesn't contain anything silly.
    • make
    • Go and make a cup of tea. You have plenty of time.
    • sudo make install
    • Test to see if there: python -c 'import PyQt4; print PyQt4'
    If you get some error about PyQt4 being 64-bit and Qt is 32 bit, you've installed (or built) the default Carbon version of Qt. Build or install the 64 bit Cocoa version, as instructed above.

    Now, back to QScintilla package as we're going to build the Python bindings. This has to be done after PyQt has been built and installed.
    • cd Python
    • python configure.py
    • make
    • sudo make install
    • make clean
    Now the Qt Designer QScintilla plug-in:
    • cd designer-Qt4
    • qmake -spec macx-g++
    • make
    • sudo make install
    • make clean
    • Start Designer and make sure the QScintilla plug-in is there.

    Wednesday, 25 November 2009

    Toneport UX2 4.2.5 Beta drivers

    I tried installing the newer Toneport UX2 4.2.5 beta drivers to see if it fixes the current problem with the 4.2.4 beta drivers. For me, this is: if you disconnect the UX2 USB device and reconnect it, it starts making the choppy noise again. You then have to restart your MacBook with the USB device connected to get it to work properly again (which is a real pain as you have to start all your apps again).

    My spec: MacBook Intel '09, OSX 10.6.2, Toneport UX2.

    Didn't realise the beta drivers existed until today as they are not well publicised. Remember to click the "beta" tick box on the Line 6 download page:


    At first attempt I installed them over the 4.2.4 drivers that I installed, but this doesn't work. I got choppy noise again, but not the same as the first time with the 4.2.4 drivers. Ended up having to uninstall everything and start again.

    To anyone from Line 6 reading this: Why don't you supply an application to clean up all traces of Line 6 applications? Dragging applications to the trash can won't delete all files on a Mac. Most of the hassle I have had was figuring out that you need to remove stuff from /Library etc, and that you need to do a clean install. This might stop a significant number of complaints, which I'm sure is losing you customers. I'm only a casual musician, but I'll bet more dedicated musicians are much more frustrated at the situation.

    I had to use AppCleaner to get rid of everything (otherwise "kext error" appears):
    • Restart (so we start with clean slate).
    • Run AppCleaner.
    • Uninstall Line 6 Gearbox using AppCleaner.
    • Uninstall Line 6 Monkey using AppCleaner.
    • Restart.
    • Uninstall Line 6 drivers (Use program in Line 6 directory in Applications).
    • Restart (to start again with no Line 6 software).
    • Install latest Gearbox (3.70, contains 3.4 drivers).
    • Install latest (4.2.5 beta) drivers (over Gearbox drivers).
    • Restart.
    Don't install Line 6 Monkey. Apparently the current version can't recognise half the hardware and don't know what other problems it causes.

    So, the good news is that you no longer have to restart to get the UX2 to work if you unplugged it.

    The Line 6 site claims:

    This driver addresses the following issue:
    * Various audio pops, clicks, and glitches - FIXED
    I'm not quite sure what problem they are referring to, unless other devices besides the UX2 weren't fixed with 4.2.4. The problem I had was disconnecting the USB device.

    The bad news is that the drivers still aren't there yet as they aren't 64 bit. I.e. you can't run your MacBook in 64 bit kernel mode where it is something like 30% faster in some cases. Snow Leopard defaults to 32 bit mode for safety, which a lot of people won't even realise. You can tell whether you have 32 or 64 bit kernel mode by doing:

    Apple menu > "About this Mac" > "More info..." > Software (In "Contents" left bar) > "64-bit Kernel and Extensions"

    You'll see:

    To use your Line 6 device this must say no. Line 6 haven't added support for the new Snow Leopard 64 bit kernel yet.
    • To boot into 32 bit mode (default) hold down "3" and "2" keys when restarting your Mac.
    • To boot into 64 bit mode hold down "6" and "4" keys when restarting your Mac.



    Monday, 5 October 2009

    Toneport on Snow Leopard

    UPDATE (25-Nov): Please read: 4.2.5 beta drivers are available.

    I managed to get my Toneport UX2 working on my (2009 Intel) MacBook Pro with Snow Leopard after a bit of fiddling around. I installed Snow Leopard before finding out that my UX2 is not officially support yet (doh!), but there are beta drivers. I take this to mean that they haven't ironed all the issues out. I couldn't find anything (easily) on the Line 6 forums to help sorting this out. It seems a lot of people have the same problem.

    Writing drivers is complicated, and converting drivers from 32 to 64 bit is non-trivial. If you've tried to run Vista 64 they had all the same issues (i.e. no/buggy 64 driver support for a lot of things for quite a while).

    Initially I just installed the latest 4.2.4 drivers, but this created "choppy noise" (cutting out, popping, white noise, etc). I did get the "kext" error whilst installing, so assume something was going wrong (but I didn't spend time finding out what). Snow Leopard is all 64 bit now, so some drivers won't work. If you just install the latest drivers something must get confused.

    The trick is to completely remove all Line 6 software and start again. I rebooted several times, cautiously, to allow the OS to remove unwanted files. I used AppCleaner to uninstall applications because otherwise some files get left behind (e.g. config and data files). If you don't use AppCleaner, this won't work.
    • Restart (so we start with clean slate).
    • Run AppCleaner.
    • Uninstall Line 6 Gearbox using AppCleaner.
    • Uninstall Line 6 Monkey using AppCleaner.
    • Restart.
    • Uninstall Line 6 drivers (Use program in Line 6 directory in Applications).
    • Restart (to start again with no Line 6 software).
    • Install latest Gearbox (3.70, contains 3.4 drivers).
    • Install latest (4.2.4) drivers (over Gearbox drivers).
    • Restart.
    After you have done this your Toneport should work as normal. The order is important. My Toneport works fine with Garageband and Gearbox now. I'll keep an eye out for new drivers.

    Not a bad idea to bung the guy who wrote AppCleaner a couple of bucks, because this won't work otherwise. :)

    I'm not a Line 6 support engineer, if this doesn't work for you, sorry!

    UPDATE (7-Oct): After disconnecting the UX2 and using my laptop elsewhere, and then plugging the UX2 back in, the crackling came back again. I managed to get rid of this by leaving the UX2 plugged into the USB port and rebooting the Macbook. It seems like disconnecting the UX2 and/or the Macbook going into sleep breaks something in the 4.2.4 drivers so you have to reset the machine.

    Sunday, 4 October 2009

    Snow Leopard

    Well, I upgraded to Snow Leopard recently (10.6.1). Normally I wait a while with new operating system versions until they've had a chance to patch them (e.g. version X.Y.3). I waited quite a while before installing Leopard as it was such a big upgrade. Snow Leopard is supposed to be a "tweak", with the biggest changes at low level, where everything has gone 64 bit.

    The biggest problems here will be with hardware drivers breaking (as I found out with my Toneport UX2). Still, compared to Vista 64 this doesn't seem to be much of a problem. Microsoft is notorious for releasing beta quality software and then patching it after users have tested it. Apple seem to be a bit better at releasing, but then they control the whole hardware and platform more strictly, so they have less margin for error.

    Snow Leopard does seem more responsive, not that Leopard was slow. Apps seem to start faster, and the Finder is instantaneous. This is a breath of fresh air after using Window's sluggish Explorer (on XP). It's pretty poor that it can take a couple of seconds to refresh, even on a high spec machine.

    Snow Leopard no longer supports PowerPC so my old G5 will have to stay on Leopard, and will probably be appearing on ebay. I believe applications are also compressed, which allows them to load faster. It's faster to decompress something into memory from disc, as the bottleneck is your slow hard drive (especially on a 5400 RPM laptop drive). My laptop does seem more zippy, and I got a massive chunk of hard drive space back, ~10GBs?!! I have XCode and a load of other stuff that would benefit.

    Not really noticed any visual changes, but it does seem strangely more pleasing to the eye. Upgrade cost is relatively cheap and Apple have been smart not to charge a lot for something which doesn't give a lot of end user features, but a lot of work will have gone into all the optimisations it provides. Worth upgrading for the extra responsiveness.