Monday, September 6, 2010

OpenGL and GLUT on Mac

I have been having a bunch of problems with GLUT and OpenGL on mac, but I finally got it!



Before I continue, go into terminal and type in:
"man make"
"man g++"
"man manuals are not found you NEED to upgrade Xcode! (I have no idea how you got MacPorts to work if you have not done this already)
Xcode is about 2.5gB, so it will take a while. But the upgrade is really nice (at least in my opinion). But it is needed for MacPorts.

Next, I will go over all the wrong steps.
MacPorts is a really nice tool, but you will NOT need it to install OpenGL and GLUT. It uses the "port" command from Terminal. Such as: "sudo port install cmake", which installs cmake. I tried installing glut though MacPorts, but it did not help. So I tried installing it manually from a zip file. Which include files are located (from what I currently know of) in two spots on the computer: "/opt/local/include/" and "/usr/local/include". I dragged and dropped some files in there (as well as some "Allegro" files, which is another library. I will be going over "Allegro" for a little bit in here since it also messed me up. I copied .../Allegro5/* into the include folders, but I really needed to copy .../* of the zip into the folder (leaving the Allegro5 folder intact though the copy). This left conflicting packages (ie. Memory.h!). Allegro needed to install something in "/Allegro5/platform/". (try to compile with #include , and it will point out the file). It has a cmake file in that folder, which I believe comments/uncomments out the installed setting or something like that. I tried to install cmake, but it got hung up while installing/compiling. Reading the log file, it died trying to #include . I fixed that by formatting the folder how it was supposed to be. And more useless stuff.

So what should you do?
NOTHING! Thats right, nothing! It is ALREADY INSTALLED ON MACS!!! Lucky you!
But to use it the right way you need to:

Use the right includes:
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>

Terminal users:
g++ main.cpp -o main -framework GLUT -framework OpenGL
gcc main.c -o main -framework GLUT -framework OpenGL
make is the same way

Xcode users:
Right click project in the "Groups & Files" bar (left side)
Add
Existing Frameworks...
Select Glut and OpenGl
You should see them added with your project

No comments: