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.
Setting up OpenGL using SDL on a Mac
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:
- Open up Xcode and click on Create a new Xcode project.
- Go to OS X | Application, then select Command Line Tool, and click Next.
- 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
- Then, set the location where you would like to store and save the project, and then click on the Create button.
- 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.
- 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.
- 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.
- 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.