Note for Xcode 4 Users

The Xcode setup information on this page (everything up to the screenshot) was written for earlier versions of Xcode. If you are using Xcode 4, read the Using SDL with Xcode 4 article on my blog for instructions on how to setup SDL on Xcode 4.

Setting Up SDL in Xcode

Xcode doesn’t ship with SDL support so you must download the SDL libraries from the SDL website. At the download site you will see two types of libraries: runtime and development. You must download both libraries. The runtime library contains the SDL framework. The development libraries install documentation and SDL Xcode project templates on your computer. Copy the SDL.framework folder that is part of the runtime library download to /Library/Frameworks. The development library download contains instructions on how to install the documentation and project templates.

After installing SDL, launch Xcode and choose File > New Project to create a new project. In the Applications collection of project templates, you will see a SDL OpenGL Application project. Select that project and click the Next button. Give your project a name, choose a location to store the project, and click the Finish button.

When you create a SDL OpenGL application project, the detail view looks like the figure below. The project template provides files to create an application without having to write any code, but these files get in the way when writing your own programs. You can remove the GLUT framework from the project as well as the files atlantis.c, atlantis.h, dolphin.c, shark.c, swim.c, and whale.c. If you want to write your program in C++, you can also remove the main.c file from the project and add a file named main.cpp to the project.

Figure 1

The files SDLMain.h and SDLMain.m contain glue code that allow SDL applications to run on Mac OS X. Make sure you keep them in the project. If you decide to use a nib file for your application’s menu bar, you must change the value of the following line of code in SDLMain.m:

#define SDL_USE_NIB_FILE 0

To the following:

#define SDL_USE_NIB_FILE 1

In your source code files you must include the header SDL.h.

#include “SDL.h”

To use OpenGL with SDL, include the SDL header file SDL_opengl.h. SDL_opengl.h includes the OpenGL header files gl.h and glu.h for you. Including SDL_opengl.h is much easier for cross-platform games than manually including gl.h and glu.h because Mac OS X, Linux, and Windows have different syntax for including OpenGL header files.

#include “SDL_opengl.h”

Next (Initializing SDL)

Previous (Introduction)