Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling OpenGL and GLUT OSX

Tags:

c

macos

opengl

I am having difficulty compiling a C program using the OpenGL and GLUT frameworks on Mac OSX. I am just getting started and I attempted to run code from this tutorial, on how to install OpenGL. http://www.prinmath.com/csci5229/misc/install.html.

Here is the code:

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

int main(){
    return 0;
}

I am trying to compile it with:

gcc -o foo foo.c -framework GLUT -framework OpenGL

I am receiving this error:

foo.c:2:23: error: GLUT/glut.h: No such file or directory

After doing some further research here, http://web.eecs.umich.edu/~sugih/courses/eecs487/glut-howto/, I looked in /System/Library/Frameworks/ and both OpenGL.framework, and GLUT.framework where present.

Any help is greatly appreciated! Thank you!

like image 503
Jacthoma Avatar asked Aug 22 '13 05:08

Jacthoma


People also ask

Does glut work on Mac?

Installing GLUTThere is no need to install GLUT on a Mac. It comes as part of the package. If you have XCode, you can make a GLUT application.

Can you run OpenGL on Mac?

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.


2 Answers

Without installing glutg3-dev you can use OS X GLUT and OpenGL frameworks as follows

gcc -o foo foo.c -L/System/Library/Frameworks -framework GLUT -framework OpenGL

notice that it is important to tell the compiler the path to the frameworks

like image 78
BRabbit27 Avatar answered Sep 23 '22 00:09

BRabbit27


You need to install OpenGL Utility Toolkit glutg3-dev lib.If it is already there then compile with -lglut -lGLU -lGL option.

like image 23
Dayal rai Avatar answered Sep 27 '22 00:09

Dayal rai