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:
glfw-3.3.4.bin.MACOS.zip is the latest file at the time of writing this post.
Unzip and copy “GLFW” directory from glfw-3.3.4.bin.MACOS/include/ to a new directory somewhere, say: ~/dev/OpenGL_test_luke/
Additionally, copy libglfw.3.dylib from glfw-3.3.4.bin.MACOS/lib-x86_64/ to ~/dev/OpenGL_test_luke/
Copy the example code from GLFW Documentation.
Paste it in an IDE (I used VS Code & Sublime Text; Xcode related linking libraries is below)
Save it in the same directory as main.cpp
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:
Linking Libraries on Xcode
In the project settings, go to:
General > Frameworks and Libraries and add: OpenGL.framework
Additionally, we will also need to add the libglfw.3.dylib library that we added earlier in ~/dev/OpenGL_test_luke/
Make sure to set Embed options to Do Not Embed for both the libraries.
Xcode will generally throw in about 331 issues, only one of these is related to the deprecation of OpenGL syntax.
The others are due to Xcode’s feature of displaying errors in documentation comments that are toggled “ON” by default🤦♂️
These can be silenced in the project’s Build Settings
And here’s also a short video I made as a part of another documentation.