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 sdl2Now, 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:
- Open up Xcode and click on
Create a new Xcode project. - Go to
OS X|Application, then selectCommand Line Tool, and clickNext. - You will get the following window. Fill in the necessary details, as highlighted in the screenshot, and make sure for the
Languageoption,C++is selected:

Details of the project
- Then, set the location where you would like to store and save the project, and then click on the
Createbutton.
- Next, click on your project and go to
Build Settings. InBuild Settings, go to theSearch Pathssection and click onHeader Search Paths. Then, click on+and type/usr/local/include. This will allow us to #include GLEW and SDL header files in ourmain.cpp. - Now go to
Build Phases, then click onLink Binary With Libraries, and click the+button. Typeopenglin the search bar, selectOpenGL.framework, and then click on theAddbutton. - Again click on the
+button, and then click onAdd Other.... Now, press Cmd + Shift + G, and it will open up ago-tofolder search bar. In it, type/usr/local. Then click onCellar, go to theglew|libfolder, selectlibGLEW.1.12.0.dylibwithout the little arrow, and click onOpen. - Click
+again, then clickAdd Other....Press Cmd + Shift + G and type/usr/local. Now go toCellar, and go tosdl | lib. Select the non-aliaslibSDL2-2.0.0.dyliband click on theOpenbutton.
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.