Setting up a Mac-based development platform
One important advantage of using OpenGL is the possibility of cross-compiling the same source code on different platforms. If you are planning to develop your application on a Mac platform, you can easily set up your machine for development using the upcoming steps. We assume that you have either Mac OS X 10.9 or higher installed. OpenGL updates are integrated into the system updates for Mac OS X through the graphics driver.
Installing Xcode and command-line tools
The Xcode development software from Apple provides developers with a comprehensive set of tools, which include an IDE, OpenGL headers, compilers, and debugging tools, to create native Mac applications. To simplify the process, we will compile our code using the command-line interface that shares most of the common features in Linux.
Getting ready
If you are using Mac OS X 10.9 or higher, you can download Xcode through the App Store shipped with Mac OS. Full installation support and instructions are available on the Apple Developer website (https://developer.apple.com/xcode/).
How to do it...
We can install the command-line tools in Xcode through the following steps:
- Search for the keyword
Terminal
in Spotlight and run Terminal. - Execute the following command in the terminal:
xcode-select --install
Note that if you have previously installed the command-line tools, an error stating "command-line are already installed" will appear. In this case, simply skip to step 4 to verify the installation.
- Click on the Install button to directly install the command-line tools. This will install basic compiling tools such as gcc and make for application development purposes (note that CMake needs to be installed separately).
- Finally, enter
gcc --version
to verify the installation.
See also
If you encounter the command not found error or other similar issues, make sure that the command-line tools are installed successfully. Apple provides an extensive set of documentation, and more information on installing Xcode can be found at https://developer.apple.com/xcode.
Installing MacPorts and CMake
In this section, we outline the steps to install MacPorts, which greatly simplifies the subsequent setup steps, and CMake for Mac.
Getting ready
Similar to the Windows installation, you can download the binary distribution of CMake from http://www.cmake.org/cmake/resources/software.html and manually configure the command-line options. However, to simplify the installation and automate the configuration process, we highly recommend that you use MacPorts.
How to do it...
To install MacPorts, follow these steps:
- Download the MacPorts package installer for the corresponding version of Mac OS X (https://guide.macports.org/#installing.macports):
- Mac OS X 10.10 Yosemite: https://distfiles.macports.org/MacPorts/MacPorts-2.3.3-10.10-Yosemite.pkg
- Mac OS X 10.9 Mavericks: https://distfiles.macports.org/MacPorts/MacPorts-2.3.3-10.9-Mavericks.pkg
- Double-click on the package installer and follow the onscreen instructions.
- Verify the installation in the terminal by typing in
port version
, which returns the version of MacPorts currently installed (Version: 2.3.3
in the preceding package).
To install CMake on Mac, follow these steps:
- Open the Terminal application.
- Execute the following command:
sudo port install cmake +gui
To verify the installation, enter cmake –version
to show the current version installed and enter cmake-gui
to explore the GUI.
At this point, your Mac is configured for OpenGL development and is ready to compile your first OpenGL application. For those who have been more accustomed to GUIs, using the command-line interface in Mac can initially be an overwhelming experience. However, in the long run, it is a rewarding learning experience due to its overall simplicity. Command-line tools and interfaces are often more time-invariant compared to constantly evolving GUIs. At the end of the day, you can just copy and paste the same command lines, thereby saving precious time needed to consult new documentation every time a GUI changes.