Showing posts with label mac. Show all posts
Showing posts with label mac. Show all posts

Tuesday, December 11, 2007

Changing SDL's Working Directory on Mac OS X

The Mac OS X version of SDL sets the working directory to the directory containing the application bundle. This default behavior makes loading images and sounds more difficult because the images and sounds most likely reside in the application bundle's Resources folder. What would be nice would be to set the working directory to the Resources folder. How do you do this?

You change the working directory by modifying the method -setupWorkingDirectory: in the file SDLMain.m. You'll want to change the code in SDLMain.m in SDL's Xcode templates so your changes take effect for any new SDL projects you create. Just to be safe, you should comment out the original code or save a copy of it so you can go back to the original if things go wrong. Enter the following code in the -setupWorkingDirectory: method:


NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
[[NSFileManager defaultManager]
changeCurrentDirectoryPath
:resourcePath];


Thanks to Keith Bauer, aka OneSadCookie, for the source code to change the working directory.

Thursday, December 6, 2007

New Article: Playing Audio Files with QTKit

I have a new article on my website that explains how to load and play audio files using the QTKit framework. It should be especially helpful to any Cocoa developer who wants to loop an audio file because information on looping was hard to find in Apple's QTKit documentation.

Thursday, October 11, 2007

New Article: Mac Game Programming Roadmap

I have a new article available that provides an overview of the technologies to learn to write Mac games. The article was motivated by a discussion that has been brewing on Apple's game development mailing list for several list. The discussion revolved around Apple's lack of support for games, and one complaint was that Apple did not have a game library like DirectX. Without a game library getting started with Mac game development can be difficult because he or she may not know where to begin. My article helps them know where to begin. If you're new to Mac game development, check out the article.

Thursday, May 10, 2007

New Bundles Article

I have a new article on bundles available. It introduces bundles, focusing on application bundles. After reading the article, you will know how to create a bundle, add files to the bundle, and retrieve files from the bundle.

Monday, April 2, 2007

Using Saturn on Intel Macs

I read a post on Apple's performance and optimization mailing list that tells you what to do to use Saturn on Intel Macs. This information may be useful to some of you so I am writing about it here.

To use Saturn to profile your code, you must compile your code with either the -pg compiler flag (Generate Profiling Code build setting in Xcode) or the -finstrument-functions compiler flag. The -pg compiler flag is the flag most people use, but Apple hasn't added the support for -pg on Intel Macs yet so using the -pg flag won't allow you to run your code with Saturn on an Intel Mac.

The solution is to use the -finstrument-functions flag to compile your code. I didn't see an Xcode build setting for this flag so you'll have to add the flag to the Other C Flags or Other C++ Flags build setting in Xcode.

I don't have an Intel Mac so I can't test this for myself, but the information came from an Apple engineer so I will assume the information is accurate.

Wednesday, January 31, 2007

Writing C++ Programs on Mac OS X

A frequently asked question on Mac programming forums is "Can I write C++ programs on Mac OS X?". Yes, you can write C++ programs on Mac OS X

Install the Xcode Tools

The Xcode Tools contain everything you need to write Mac OS X applications, including C++ programs. Every copy of Mac OS X contains the Xcode Tools. If you have Mac OS X 10.4, there should be an item called Xcode Tools on the Mac OS X DVD. This item contains the installer. Older versions of Mac OS X that ship on multiple CDs contain either an Xcode Tools or Developer Tools CD.

Apple frequently updates the Xcode Tools so the version that shipped with your copy of Mac OS X is most likely not the most recent version. If you have a broadband Internet connection, I recommend going to Apple's developer page and signing up for a free ADC membership. After signing up for an ADC membership, you can download the most recent version of the Xcode Tools.

One common concern people have when installing the Xcode Tools is the size of the install. The easy install of the Xcode Tools is over 1.5 GB, which is overkill if all you want to do is learn C++. You can perform a custom install of the Xcode Tools to reduce the size of the install. If you are low on disk space, the easiest way to save space is to not install the developer documentation. The developer documentation takes about 1 GB of disk space, and you can view all the documentation online anyway.

Writing Standard C++ Programs

The people most likely to ask if they can write C++ programs on Mac OS X are Mac-using college students who are taking a class on C++ programming. C++ programming classes normally teach standard C++, which will run on most operating systems, including Mac OS X.

To write a standard C++ program with Xcode, you must create a C++ Tool project. C++ Tool projects are used to write command-line programs without a GUI, which makes programming easier. You can read an article on the Xcode Tools Sensei page that contains detailed instructions on creating and building a C++ Tool project.

Writing C++ GUI Programs

After learning C++ you may want to use your newfound knowledge to write Mac OS X GUI programs. You have three options for writing Mac GUI applications in C++. First, you can use Cocoa, writing your user interface code in Objective C and the rest of your code in C++. You must give your Objective C files the extension .mm, which tells Xcode to treat them as Objective C++ files. Objective C++ lets you mix C++ and Objective C code in the same source file.

Second, you can use Carbon, which is Apple's C API for writing GUI applications. If you choose to use Carbon, you may want to look into Nano, an open-source C++ framework built on top of Carbon.

Third, you can use a C++ cross-platform GUI framework like Qt or wxWidgets. I haven't used either of these frameworks, but you should check them out if you are interested in supporting Linux and Windows as well as Mac OS X.