top of page
Writer's pictureLuke Chikkala

OpenGL on macOS

Updated: Nov 6, 2021

Apple officially deprecated the support for OpenGL since macOS 10.14 Mojave. As such, building a basic window (or a triangle, if you’re adventurous) does come with a couple of complications (read “errors”).

But the easiest way to get started would be to:

  1. Download 64-bit GLFW’s macOS pre-compiled binaries.

  2. glfw-3.3.4.bin.MACOS.zip is the latest file at the time of writing this post.

  3. Unzip and copy “GLFW” directory from glfw-3.3.4.bin.MACOS/include/ to a new directory somewhere, say: ~/dev/OpenGL_test_luke/

  4. Additionally, copy libglfw.3.dylib from glfw-3.3.4.bin.MACOS/lib-x86_64/ to ~/dev/OpenGL_test_luke/

  5. Copy the example code from GLFW Documentation.

  6. Paste it in an IDE (I used VS Code & Sublime Text; Xcode related linking libraries is below)

  7. Save it in the same directory as main.cpp

  8. Open a terminal and compile using:

g++ -framework OpenGL main.cpp libglfw.3.dylib -o Application

This might throw in deprecated warnings like:

Application.cpp:25:9: warning: 'glClear' is deprecated: first deprecated in macOS 10.14 - OpenGL API deprecated. (Define
	      GL_SILENCE_DEPRECATION to silence these warnings) [-Wdeprecated-declarations]
	        glClear(GL_COLOR_BUFFER_BIT);
	        ^
	/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenGL.framework/Headers/gl.h:2394:13: note: 
	      'glClear' has been explicitly marked deprecated here
	extern void glClear (GLbitfield mask) OPENGL_DEPRECATED(10.0, 10.14);
	            ^
	1 warning generated. 

To silence these warnings, simply add #define GL_SILENCE_DEPRECATION before GLFW’s header:

#define GL_SILENCE_DEPRECATION // Important to define before OpenGL headers.
#include  

Linking Libraries on Xcode

  1. In the project settings, go to:

  2. General > Frameworks and Libraries and add: OpenGL.framework

  3. Additionally, we will also need to add the libglfw.3.dylib library that we added earlier in ~/dev/OpenGL_test_luke/

  4. Make sure to set Embed options to Do Not Embed for both the libraries.

  1. Xcode will generally throw in about 331 issues, only one of these is related to the deprecation of OpenGL syntax.

  2. The others are due to Xcode’s feature of displaying errors in documentation comments that are toggled “ON” by default🤦‍♂️

  3. These can be silenced in the project’s Build Settings

  1. And here’s also a short video I made as a part of another documentation.


Final Result


3,755 views0 comments
Post: Blog2_Post

©2021 by lukechikkala.

bottom of page