Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learn OpenGL

You're reading from   Learn OpenGL Beginner's guide to 3D rendering and game development with OpenGL and C++

Arrow left icon
Product type Paperback
Published in Aug 2018
Publisher Packt
ISBN-13 9781789340365
Length 208 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Frahaan Hussain Frahaan Hussain
Author Profile Icon Frahaan Hussain
Frahaan Hussain
Arrow right icon
View More author details
Toc

Setting up OpenGL using GLFW on a Mac

Here's what we've discussed so far, we discussed about how to set up our project to use GLFW library on Windows. In this section, we'll discuss how to set up OpenGL on a Mac system. So, let's get started.

Downloading the GLFW and GLEW libraries for a Mac

To download and install the essential libraries onto your Mac system, we'll have to install a package manager for Mac known as Homebrew. Homebrew will help us in installing all the necessary packages and libraries to run our OpenGL code.

To install Homebrew, go to https://brew.sh/, copy the path highlighted in the following screenshot, paste it into your Terminal, and then hit Enter. The prompt will download and install Homebrew on your system:

Path on Homebrew homepage

Once we've installed Homebrew, we'll download the GLFW and GLEW libraries onto our system. Let's install GLFW first. To do that, we need to type the following command in the Terminal window:

brew install glfw3 

In the preceding command, you must have observed we've included the number 3; the reason for that is that if you just type glfw, it installs an older version, which we don't want, so inserting glfw3 will install the latest version. Hit Enter and the libraries will be downloaded onto your system.

Now, we're going to do the same process for GLEW; type the following command in the Terminal:

brew install glew  

We don't need to put any version for this; just press Enter and the necessary files will be downloaded. That's it for the libraries to download onto our system.

Make a note that, since we're installing the libraries on the system itself and not in our project, whenever you move your project to a different system, you will have to install these libraries onto that particular system.

Once we've downloaded and installed all the essential libraries with the help of Homebrew, we'll now move on to setting up Xcode for OpenGL.

Make sure Xcode is installed on to your system. If not, please follow these instructions and install it on your system.

Setting up Xcode for OpenGL

In this section, we'll discuss how to set up Xcode to run our OpenGL code. Follow these steps and carry out the setup process:

  1. Open up Xcode and click on the Create a new Xcode project option.
  2. Go to OS X | Application, select Command Line Tool, and then click Next.
  3. You will get the following window; fill in the necessary details, as highlighted in the following screenshot:
Basic details for a project
  1. In the preceding screenshot, make sure that the Language option is always set to C++, and then click Next. The Organization Name and Organization identifier properties, you can set to whatever you want.
  2. Next, set the location you would like to store and save the project to. Then, click on the Create button. Next, we have just a plain C++ project ready. Before we begin with our code, we need to follow a few more steps necessary to set up our project.
  3. First of all, in Xcode, click on your project and go to Build Settings. In Build Settings, go to the Search Paths section and click on Header Search Paths.Then, click on + and type /usr/local/include. This will allow us to #include GLEW and GLFW in our main.cpp file.
  4. Now go to Build Phases, then click on Link Binary With Libraries, and click the + button. Type opengl in the search bar, select OpenGL.framework, and then click on the Add button.
  1. Again click on the + button, then click on Add Other.... Now, press Cmd + Shift + G, and it will open up a go-to folder search bar. In it, type /usr/local. Then click on Cellar, go to the glew | lib folder, select libGLEW.1.12.0.dylib without the little arrow, and then click Open.
The arrow is just a shortcut, an alias, and we don't want that. We also don't want the MX version, just the regular .dy non-alias lib.
  1. Click + again, then click Add Other... , press Cmd + Shift + G, and type /usr/local. Now go to Cellar, and go to glfw | lib. Select the non-alias libglfw3.3.1.dylib and click Open.

With all the steps executed, our project is now set up to use GLEW and GLFW with OpenGL on Mac. We can now go to the main.cpp file on Xcode and start writing our code for creating the OpenGL rendering window.

You have been reading a chapter from
Learn OpenGL
Published in: Aug 2018
Publisher: Packt
ISBN-13: 9781789340365
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime