AntTweakBar GLUT example app using Xcode

Alec Jacobson

October 11, 2010

weblog/

Here is a short tutorial to create a simple GLUT xcode project using the prototyping UI library AntTweakBar. I expect that you have compiled AntTweakBar as a static libary.

Create an xcode project

Open Xcode. File > New Project. Then choose Other > Empty Project. (The dialog looks different for different versions of Xcode, so just find "Empty Project" some place). anttweak bar glut example tutorial Call your project: AntTweakBarGLUTStarter anttweak bar glut example tutorial

Add a target executable

Right-click on Targets then select Add > New Target... (or go to Project > New Target...) anttweak bar glut example tutorial Choose Cocoa > Application as the template of your new target (Don't worry we're not really making a cocoa app, it's still going to be in pure GLUT. This just helps make the bundle). anttweak bar glut example tutorial Call your target: AntTweakBarGLUTStarter anttweak bar glut example tutorial Important: Under the Build settings of your new target (Right-click on the AntTweakBarGLUTStarter target and select Get Info, then choose the Build tab), you need to remove the GCC_PREFIX_HEADER entry. anttweak bar glut example tutorial anttweak bar glut example tutorial

Link to libraries

Right-click on your target and select Add > Existing Frameworks. anttweak bar glut example tutorial This will open up your target's general info tab. At the bottom left click the "+" sign to add linked libraries. Select GLUT.framework and OpenGL.framework. anttweak bar glut example tutorial Click the "+" sign again and then "Add Other...". Add your libAntTweakBar.a file. I always copy my external dependencies into a folder called [my xcode project]/external. So mine is located at AntTweakBarGLUTStarter/external/AntTweakBar/lib/libAntTweakBar.a anttweak bar glut example tutorial This will prompt you with some options. Just choose "add". anttweak bar glut example tutorial

Add AntTweakBar header

I'm not sure if there is a more pleasant way to do this. I add the AntTweakBar.h file directly to my xcode project. Right-click on AntTweakBarGLUTStarter > Add > Existing Files... . anttweak bar glut example tutorial Then add AntTweakBar.h (mine is located at AntTweakBarGLUTStarter/external/AntTweakBar/include/AntTweakBar.h). anttweak bar glut example tutorial Again, just click "add" at the prompt. anttweak bar glut example tutorial

Create a main program

Right-click on AntTweakBarGLUTStarter > Add > New File. anttweak bar glut example tutorial Choose C++ file. anttweak bar glut example tutorial Call it main.cpp anttweak bar glut example tutorial Now you are ready to put whatever you want in your program. I copied the contents from the AntTweakBar GLUT example (TwSimpleGLUT.c) into main.cpp. This works almost as is. Just add at the very top you:
#ifdef __APPLE__
#define _MACOSX
#endif

Build and go

anttweak bar glut example tutorial

Adding an icon

You'll see in the above screen shot that I have a beautiful dock icon for my app. This is very easy in the current setup. Make some icon using Photoshop/Gimp whatever you like. I just save the image as a .png file and use http://iconverticons.com/ to convert it to a .icns file. Once you have the .icns file add it to your project. I made a new folder AntTweakBarGLUTStarter/data and put my icon there: AntTweakBarGLUTStarter/data/AntTweakBarGLUTStarter.icns. So Right-click on AntTweakBarGLUTStarter > Add > Existing File. anttweak bar glut example tutorial Choose your icon file. anttweak bar glut example tutorial Again, just click "add" at the prompt. anttweak bar glut example tutorial To set this file as your icon Right-click on your target and select Get Info... anttweak bar glut example tutorial Then choose the Properties tab. Under "Icon file:" type the name of your icon file. anttweak bar glut example tutorial

Download

The source and .xcodeproj file in a zipped directory The application binary (10.5 32-bits) Source: The above is largely based off of: http://blog.onesadcookie.com/2007/12/xcodeglut-tutorial.html