Example of macOS OpenGL hook with dylib injection.
OpenGLSimpleApp - Simple MacOS Application, using NSOpenGLView, drawing simple triangle with custom drawing loop with 1 sec interval.
Artificially we call
CGLContextObj ctx = 0;
CGLFlushDrawable(ctx);
to simulate usual open-gl game/app based behaviour.
This example shows hooking CGLFlushDrawable method.
opengl_hook - Our custom library which is going to be injected.
Easiest way to inject dylib is using osxinj. However mach_inject can be used directly as well. I do recommend using my fork of osxinj with fixed bootstrap.dylib and few misc fixes.
sudo osxinj OpenGLSimpleAPP libopengl_hook.dylib
That's it. OpenGLSimpleApp should now additionally draw rectangle over triangle.