DEV Community

Shadoweaver
Shadoweaver

Posted on

How I learned to compile example from GLFW3 on macOS

I'm just starting to learn graphics.

Where it all began: the CG textbook we currently use (Hearn, Baker, Carithers) uses OpenGL 2.0 (using things like GLUT), while on my system (macOS 10.12.6 @ rMBP 13” late 2013), it’s simply deprecated as per compiler warning. Also I read that modern OpenGL does things differently and handsomely, so why not just go 4.1 (up to my system’s highest support)? (I even attempted Vulkan, but it’s too new for my system.)

I learned that I should use GLFW to interact with desktop window manager, and GLEW to manage OpenGL extensions. On macOS they are readily brewed:

$ brew install glfw --with-examples --with-test
$ brew install glew
Enter fullscreen mode Exit fullscreen mode

but I was at lost when I tried to compile simple.c in GLFW examples. linmath.h was readily found, but what was I supposed to do with GLAD?

Apparently I can directly compile some even simpler code, as found in this post, which didn’t use GLAD as in simple.c.

I didn’t install the full Xcode, but used brewed gcc-7. It took me some time to figure out that I should compile the above code with

$ g++-7 -lglfw -lglew -framework OpenGL [filename]
Enter fullscreen mode Exit fullscreen mode

and it runs fine.

And today I stumbled upon learn OpenGL which shows how to set up GLAD. I should download a certain version of it, put the headers into /usr/include, and also compile and link the accompanying C code. Following this instruction I finally get my own “simple.c” compiled.

Top comments (0)