I'm trying to run this openGL example on my Mac from command line using gcc. The XCode is installed, gcc was used many time with other programs (w\o graphics).
Following to this topic I run:
g++ 1.cpp -framework OpenGL -lGLU -lglut
and get:
1.cpp:12:21: fatal error: GL/glut.h: No such file or directory
I found glut.h
at /System/Library/Frameworks/GLUT.framework/Headers/
and noted that structure is different (not GL folder). But even removing GL/
and using -I/System/Library/Frameworks/GLUT.framework/Headers
/ does not help a lot..
So I wonder - how to use openGL with gcc on Mac properly?
OpenGL is available to all Macintosh applications. OpenGL for OS X is implemented as a set of frameworks that contain the OpenGL runtime engine and its drawing software. These frameworks use platform-neutral virtual resources to free your programming as much as possible from the underlying graphics hardware.
1.2 Writing Your First OpenGL ProgramCreate a new C++ project: Select "File" menu ⇒ New ⇒ Project... ⇒ C/C++ ⇒ C++ Project ⇒ Next. In "Project name", enter " Hello " ⇒ In "Project type", select "Executable", "Empty Project" ⇒ In "Toolchain", select "Cygwin GCC" or "MinGW GCC" (depending on your setup) ⇒ Next ⇒ Finish.
The m1 mac is an awesome machine, but lacks of continuity for OpenGL (especially as OpenGL 4.5 >= introduces a lot of new exciting features that make the code less verbose). As OpenGL 4.1 is still robust and, as Apple did not completely removed OpenGL from the stack, it is still interesting to draw things with OpenGL.
Your first problem is that Apple's Framework infrastructure actively sabotages portability of code by placing OpenGL headers in a nonstandard path. On Apple platforms the OpenGL headers are located in a directory named OpenGL
instead of just GL
.
So to portably include the headers you have to write
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
Your other problem is, that GLUT is not part of OpenGL and an independent, third party library, that's no longer contained within the OpenGL framework. You need to use the GLUT Framework. And of course that one uses nonstandard include paths as well:
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
Compile with the -framework OpenGL -framework GLUT
options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With