OpenGL on MacOS (C / C++)

Disclaimer

OpenGL is deprecated on MacOS in favor of Metal. If you still want to use OpenGL, it is still possible to compile applications. Also as another disclaimer, the examples I post use deprecated OpenGL constructs. OpenGL changed over the time and added new features whereas older features were depreacted. As I am learning myself, I am using deprecated features until I get comfortable with the newer stuff. So be aware and inform yourself about the most current OpenGL features.

Compiling OpenGL applications on MacOS

Reading this post, it is necessary to import OpenGL headers from specific folders on MacOS instead of the default paths used on Windows and Linux.

#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <GLUT/glut.h>
#else
#include <GL/gl.h>
#include <GL/glut.h>
#endif

The command line for compiling is:

g++ blender.c -framework OpenGL -framework GLUT

You will get a lot of warnings, because all OpenGL calls are deprecated but the compiler should generate a a.out nevertheless, which you can execute using

./a.out

Resolution on Retina-Displays

Running a glut application on a retina display displays in a real low resolution. I did not figure out the solution for this but there are some pages explaining solutions:

https://www.opengl.org/discussion_boards/showthread.php/178916-Using-the-retina-display-on-a-macbook-pro

http://iihm.imag.fr/blanch/software/glut-macosx/

Leave a Reply