您的位置:首页 > 运维架构

OpenGL on Mac OS X

2012-06-06 10:13 501 查看
转载自:http://alumni.cs.ucsb.edu/~wombatty/tutorials/opengl_mac_osx.html

OpenGL on Mac OS X

Using XCode | Using GNU tools | Porting
to/from OS X ]

Using XCode

This will get you an XCode project with all of the necessary frameworks added to it.
Make sure you have XCode installed. If you don't (it doesn't come installed on new Apple machines), you'll need to dig around on your supplied OS X CDs/DVDs. Usually it is on disc 2 of the install set. Install the whole thing.
Fire up XCode and create a new project: 
File:New Project
.
In the Assistant screen, scroll down to Command Line Utility and choose Standard Tool. Give it a name and a location. This will give you a barebones project without any of the Cocoa stuff included. You could, of course, use a more inclusive
project option, but I'm talking barebones here.
In the project window, Control+Click (or Right-click, if your mouse has more than one button...) and choose Add...:Existing Frameworks. You should get a file dialog that is already showing/System/Library. Just choose /System/LibraryFrameworks/OpenGL.framework,
for the base OpenGL framework and GLU, or /System/Library/Frameworks/GLUT.framework, if you want GLUT.
In your source files, be sure to include OpenGL/gl.h, OpenGL/glu.h, and/or GLUT/glut.h.

Using GNU tools

This will get you going on the command line. This ought to be easier if you plan on moving between operating systems.
coming soon!

Porting to/from OS X

OpenGL == cross-platform, right? Almost. Porting an existing OpenGL application to or from OS X is largely a matter of headers (I think...). For some unknown reason, OS X puts the headers in a different location
in the include path than Windows and Linux (and probably a bunch of other *n?x OSes). Here's the skinny:
Header DescriptionMac OS XThe Rest of the World
GL - OpenGL Base
#include <OpenGL/gl.h>
#include <GL/gl.h>
GLU - OpenGL Utility
#include <OpenGL/glu.h>
#include <GL/glu.h>
GLUT - OpenGL Utility Toolkit
#include <GLUT/glut.h>
#include <GL/glut.h>
The other headache(?) that you will come across if you are doing things on the command line is what switches to feed 
gcc
. The proper Mac switches are
available above, but what do you do if you want to move your app to Linux? Or, heaven forbid, Windows?
Well, for Linux, you will replace those short little 
-framework
 flags with something like the following (stolen, unceremoniously, from the CS280: Real-time Graphics class website at UCSB):
-lglut -lGLU -lGL -L/usr/X11R6/lib/ -lXmu -lXi -lXext -lX11 -lXt

For Windows I have, admittedly, no idea.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息