OpenGL on MacOS (C / C++)


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>
#include <GL/gl.h>
#include <GL/glut.h>

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


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: