Hot on the heels of the Raspberry Pi 2 Model B+ with its quad core processor, Arduino are set to release the Arduino TRE consisting of an AVR arduino and a 1-GHz Sitara AM335x processor, which allows makers to get up to 100 times more performance than the Arduino Leonardo or Uno. The TRE is set to host a Linux operating system that will allow users to run processing-intensive algorithm and high-speed communications, alongside the Arduino's traditional applications. Sounds similar to Intel's Galileo doesn't it? Also, this will be the first Arduino manufactured in the U.S and not in Italy or China.
As the title of this blog suggests this post is about installing and building an application using XCode on a Mac OS X system in general and on a Mac OS X with Mavericks 10.9.5 installed in particular. The purpose of the installation is to use it to program an OpenGL example from the legendary OpenGL red book.
However, while installing Xcode is straightforward understanding the mechanisms required to run an OpenGL example are not. For example, should one install MacPorts, XQuartz, both or neither to run X11 applications? Should Glut or FreeGlut be installed? The decisions I made to compile and run a basic OpenGL tutorial are the subject of this blog post.
Installing Xcode 6.0.1
First released in 2003, Xcode is an Integrated Development Environment (IDE) containing a suite of software development tools, developed by Apple, for developing software for OS X and iOS devices.
To install the environment on a Macbook Air running on Mavericks 10.9.5 I did the following:
Firstly, I went to the App Store and located and download the Xcode application. It's free, which sounded suspicious. Is this apple doing their part for the community or a cunning ploy? Anyway, it installed okay and to prove it I typed gcc -v in a Terminal window to determine the version of GCC Xcode installed. The result can be seen in the Bash shell output below.
gcc -v Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1 Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn) Target: x86_64-apple-darwin13.4.0 Thread model: posix
Xcode version 6.0.1 installed GCC 4.2.1. Once installed I doubled clicked on the newly available Xcode icon, which rewarded me with the welcoming Xcode splash screen seen, in the image, below. This was a promising start and I suppose they, being Apple, can afford to develop free software if the main focus of their business is in selling hardware. I was now less suspicious, although years of avoiding using Microsoft Windows products warned me to not let my guard down. All in all a promising start.
So having installed the first building block in my Macbook Air development environment the next step in the process was to decide whether to install MacPorts or XQuartz. However, before I could do that I needed to know the difference between the two!
MacPorts or XQuartz
So what is MacPorts? Well, according to the MacPorts website (www.macports.org) "The MacPorts Project is an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, X11 or Aqua based open-source software on the OSX operating system".
The XQuartz project (www.macosforge.org) on the other hand also has blurb on their website stating the following "... is an open-source effort to develop a version of the X.Org X Window System that runs on OS X. Together with supporting libraries and applications, it forms the X11.app that Apple has shipped with OS X since version 10.5".
So after visiting both websites I still didn't have a clue, which one should I install. Although I did get an inkling from the Apple development forums that actually I could install both. However, my gut feeling was to install MacPorts and after reading the corresponding Wikipedia page my mind was almost made up.
According to Wikipedia (http://en.wikipedia.org/wiki/MacPorts) "MacPorts, formerly called DarwinPorts, is a package management system that simplifies the installation of software on the Mac OS X and Darwin operating systems. It is a free/open source software project to simplify installation of other free/open source software. ... It allows the installation of a number of packages by entering the command
sudo port install packagename
in a Terminal window, which will then download, ...,compile and install the requested software, while also installing any required dependencies automatically. Installed packages can be updated with the command
sudo port upgrade installed
So it looks like I needed both! Still unsure and just to throw a cat amongst the pigeons, using LaunchPad I navigated to the X11 icon and clicked on it. The result was the dialog shown in the image on the left.
So it seems that X11 is no longer included in Mavericks 10.9.5 and you need to install an open source community version. So I clicked on the Continue button, which took me to the webpage shown in the screenshot below. According to this page, on the apple developers forum, one needs to install XQuartz to provide OS X Mavericks with X11 server and client libraries.
So now secure with the knowledge that I understood the relationship between Mac OS X Mavericks 10.9.5, MacPorts and XQuartz I downloaded and installed both. To install MacPorts, which I decided to do first, navigate to the MacPorts website and install the version that matches your operating system, which in my case is OS X 10.9 Mavericks.
Not feeling daunted by the different installation options available I opted for the easiest and doubled clicked on the pre-packaged one, which was promptly downloaded to my Macbook. This should be done after the Xcode and the Xcode command line tools have been installed.
Once downloaded and after clicking on the downloaded installer a series of dialogs walk you through the installation process. The first dialog to appear can be seen, in the screenshot, above. After clicking on the continue button the usual options are available that allow one to choose an installation location, as well as providing an option to accept a license agreement. Once all this had been done I had MacPorts-2.3.1-10.9-Mavericks.pkg downloaded and installed on 14.6MB of my disk space. This was confirmed by the final dialog that appeared, seen below.
In a terminal window I confirmed that the version of MacPorts installed is 2.3.1 by typing port version in a terminal window.
port version Version: 2.3.1
Now for the installation of XQuartz. To do this I simply navigated to the XQuartz website and doubled clicked on the XQuartz-2.7.7.dmg, as shown in the image below.
This downloaded the .dmg package and hence the XQuartz installer onto my PC. Again, clicking on the Continue button, seen in the Figure below, led me through a series of dialogs of important information, Software License Agreement and a dialog informing me that 166.5MB of disk space would be required to install the application. I agreed to everything, as there was no point in questioning things at this stage.
Once XQuartz had been installed I was rewarded with the same "This installation has been successful" dialog seen previously. Now I could get down to the business end of things and finally program an OpenGL example.
OpenGL and FreeGlut
To do this I had to scrape myself out of my chair to get to my bookshelf where I found a copy of the OpenGL Programming Guide, Third Edition, Version 1.2, that dates back to 1999. Although a bit long in the tooth it was good enough for this elementary exercise. However, it was a telltale sign that it has been quite a while, since I had programmed in OpenGL in anger. For most of the last couple of years I have been programming in Hardware Description Languages (HDLs), but returning to software was most welcome.
However, on opening the book I soon realised that I would need to study close to a hundred pages to get back up to scratch. Instead I decided to follow a tutorial on the web. However, to do so I needed to install FreeGlut and so I did.
"FreeGLUT is a completely OpenSourced alternative to the OpenGL Utility Toolkit (GLUT) library. GLUT was originally written by Mark Kilgard to support the sample programs in the second edition OpenGL 'RedBook'. Since then, GLUT has been used in a wide variety of practical applications because it is simple, widely available and highly portable". - The FreeGlut Project (free glut.sourceforge.net)
Initially, to install FreeGlut I went to the FreeGlut Project website and downloaded the latest stable version. Then a thought came to me, which suggested that it would be a good idea to see Xcode in action. So instead I had to log out of my account and log back in again to enable XQuartz's X11 server, as the default one.
Once I had logged back in to my account I clicked on the XQuartz icon that now appeared in the Launchpad's view. I think this enables the server, but I'm not too sure. Next, in a terminal window, I typed sudo port install freeglut as suggested above, which gladly worked, as can be seen in the Figure below.
Good, I now had the recipe to create, not the perfect storm, but an OpenGL example. So I launched Xcode. In the Welcome to Xcode splash screen, described previously, I clicked on Create a New Xcode Project.
The dialog that results allows one to choose the project's application and application type. For this example I choose to create an application for OS X to be run from the command line tool. I did this because the example I found on the Internet from Lazyfoo's website (www.lazyfoo.net) suggested that I should.
The next dialog was annoying, because all the options had to be filled in before one can advance. So I randomly filled it in and moved on. The dialogue after that was quite interesting, as one has the option of automatically creating a Git repository for the project, but before I could take a screenshot it disappeared when I tried changing the project's directory. Never mind, I will need to investigate Git's integration into Xcode on another day. The main Xcode application window was now visible, as seen below.
I deleted the main.c file, as suggested by Lazyfoo's tutorial and replaced it with the files from his example, as shown by item (1) in the Figure above. In order for this application to compile and link successfully the location of the include and library directories need to be provided in the Build Settings tab, on the right-hand side of the Xcode application window above.
In the search paths section, item (2) in the Figure above, add the following, such that the XQuartz headers and libraries can be found in /opt/X11/ and FreeGlut headers and libraries can be found in /usr/local/ as one can partly see above.
Header Path Section: /opt/X11/include; /usr/local/include
Library Search Paths: /opt/X11/lib; /usr/local/lib
Finally, for the OpenGL libraries to be recognised open the Build Phases Tab, Item (1), in the Figure above, and in the Link Binary with Libraries Section, item (2), add the OpenGL framework, as seen in the dialogue of item (3). When I first ran this example it failed to compile, because I forgot to add the -lGLUT libraries to the the Other Linker Flags section. Also, it looks like things have changed since Lazyfoo's implementation as the directory /usr/local/lib does not exist and can be removed from the instructions above. The result of this exercise can be seen below, which is the basic display of a polygon using OpenGL.
This installation exercise has required a lot of patience and persistence to get to this point, but it has been done not only willingly, but out of necessity. This is because I intend to use OpenGL to provide a visual representation of the values of a 3 Degrees-Of-Freedom (DOF) gyroscope and a 3 DOF accelerometer of the MPU-6050 and other MEMS sensors in general, as part of my 17 DOF Robot Kit project.
I envision this framework being used for other projects too. Also, because the tools I have chosen to use, not out of coincidence, are X11 based it means that applications developed on this platform should be readily portable to LINUX.
However, I am not out of the woods yet, this is because apart from visually displaying MEMs values I also need to display numerical values in text windows. To this end, for historical purposes, l need to install Openmotif (GLUI may be an alternative). Also, to communicate with my hardware debug environment I need to install the FTDI library files, ftd2xx.lib.
A preliminary investigation into both would suggest that both installations are possible on the Mac OS X Maverics platform. Having been a LINUX devotee for years I can say that I am truly impressed with Xcode and its whole IDE framework. Stay turned for updates on this and other projects.