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 SDL on a Mac

Here, we'll take a look at how to set up OpenGL using SDL on a Mac system. We'll begin by downloading the essential libraries on your system. As seen in the previous sections, we'll be using Homebrew to download the packages and libraries.

Downloading the SDL and GLEW libraries

In the Terminal, type the following command to download and install the SDL libraries:

brew install sdl2

Now, just press Enter and the SDL library will be downloaded onto your system. Next, we'll download the GLEW library, but since we've already downloaded it in the previous section, you can refer to that. If you want a quick review on downloading GLEW, you can refer to the Downloading the GLFW and GLEW libraries for a Mac section.

Setting up Xcode for OpenGL using SDL

Follow these steps:

  1. Open up Xcode and click on Create a new Xcode project.
  2. Go to OS X | Application, then select Command Line Tool, and click Next.
  3. You will get the following window. Fill in the necessary details, as highlighted in the screenshot, and make sure for the Language option, C++ is selected:
Details of the project
  1. Then, set the location where you would like to store and save the project, and then click on the Create button.
  1. Next, 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 SDL header files in our main.cpp.
  2. 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.
  3. Again click on the + button, and 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 click on Open.
  4. Click + again, then click Add Other.... Press Cmd + Shift + G and type /usr/local. Now go to Cellar, and go to sdl | lib. Select the non-alias libSDL2-2.0.0.dylib and click on the Open button.

With all the steps executed, our project is now set up to use SDL and GLEW with OpenGL on a Mac. We can now go to the main.cpp file 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 €18.99/month. Cancel anytime