主要参考文章:
http://lazyfoo.net/tutorials/OpenGL/01_hello_opengl/mac/index.php
1) The first issue is that newer versions of OS X don't have X11. You'll have to install XQuartz, a quartz based port of X.org. Download the dmg and install it.
2) Download the latest source from the freeGLUT website.
Extract the archive, open a terminal window, cd to the extracted folder.
3) Configure the installation using this command in the extracted folder
env CPPFLAGS="-I/opt/X11/include" LDFLAGS="-L/opt/X11/lib" ./configure
When you installed XQuartz, it installs X11 to /opt/X11/lib. This command configures the build and tells it to look in /opt/X11/include for headers and /opt/X11/lib for library files.4) In freeGLUT 2.8.0 there's a bug in the source code that causes to break in OS X. In the freeGLUT source directory you extracted go to progs -> demos -> smooth_opengl3 and open up smooth_openg13.c.
Between lines 101 and 102 there's a bunch type definitions that are already in glext.h that cause a conflict.
make all
Now using root privileges, install the library with the command:sudo make install
6) Now that you've installed the development libraries, it's time to start up your IDE/compiler.smooth_opengl3.c:122:1: error:unknown type name 'PFNGLGENBUFFERSPROC'
PFNGLGENBUFFERSPROC gl_GenBuffers;
^
smooth_opengl3.c:123:1: error:unknown type name 'PFNGLBINDBUFFERPROC'
PFNGLBINDBUFFERPROC gl_BindBuffer;
^
smooth_opengl3.c:124:1: error:unknown type name 'PFNGLBUFFERDATAPROC'
PFNGLBUFFERDATAPROC gl_BufferData;
^
smooth_opengl3.c:125:1: error:unknown type name 'PFNGLCREATESHADERPROC'
PFNGLCREATESHADERPROC gl_CreateShader;
^
smooth_opengl3.c:126:1: error:unknown type name 'PFNGLSHADERSOURCEPROC'
PFNGLSHADERSOURCEPROC gl_ShaderSource;
^
smooth_opengl3.c:127:1: error:unknown type name 'PFNGLCOMPILESHADERPROC'
PFNGLCOMPILESHADERPROC gl_CompileShader;
^
smooth_opengl3.c:128:1: error:unknown type name 'PFNGLCREATEPROGRAMPROC'
PFNGLCREATEPROGRAMPROC gl_CreateProgram;
^
smooth_opengl3.c:129:1: error:unknown type name 'PFNGLATTACHSHADERPROC'
PFNGLATTACHSHADERPROC gl_AttachShader;
^
smooth_opengl3.c:130:1: error:unknown type name 'PFNGLLINKPROGRAMPROC'
PFNGLLINKPROGRAMPROC gl_LinkProgram;
^
smooth_opengl3.c:131:1: error:unknown type name 'PFNGLUSEPROGRAMPROC'
PFNGLUSEPROGRAMPROC gl_UseProgram;
^
smooth_opengl3.c:132:1: error:unknown type name 'PFNGLGETSHADERIVPROC'
PFNGLGETSHADERIVPROC gl_GetShaderiv;
^
smooth_opengl3.c:133:1: error:unknown type name 'PFNGLGETSHADERINFOLOGPROC'
PFNGLGETSHADERINFOLOGPROC gl_GetShaderInfoLog;
^
smooth_opengl3.c:134:1: error:unknown type name 'PFNGLGETPROGRAMIVPROC'
PFNGLGETPROGRAMIVPROC gl_GetProgramiv;
^
smooth_opengl3.c:135:1: error:unknown type name 'PFNGLGETPROGRAMINFOLOGPROC'
PFNGLGETPROGRAMINFOLOGPROC gl_GetProgramInfoLog;
^
smooth_opengl3.c:136:1: error:unknown type name 'PFNGLGETATTRIBLOCATIONPROC'
PFNGLGETATTRIBLOCATIONPROC gl_GetAttribLocation;
^
smooth_opengl3.c:137:1: error:unknown type name 'PFNGLVERTEXATTRIBPOINTERPROC'
PFNGLVERTEXATTRIBPOINTERPROC gl_VertexAttribPointer;
^
smooth_opengl3.c:138:1: error:unknown type name
'PFNGLENABLEVERTEXATTRIBARRAYPROC'
PFNGLENABLEVERTEXATTRIBARRAYPROC gl_EnableVertexAttribArray;
^
smooth_opengl3.c:139:1: error:unknown type name 'PFNGLGETUNIFORMLOCATIONPROC'
PFNGLGETUNIFORMLOCATIONPROC gl_GetUniformLocation;
^
smooth_opengl3.c:140:1: error:unknown type name 'PFNGLUNIFORMMATRIX4FVPROC'
PFNGLUNIFORMMATRIX4FVPROC gl_UniformMatrix4fv;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[4]: *** [smooth_opengl3-smooth_opengl3.o] Error 1
make[3]: *** [all-recursive] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
有问题,于是把修改的宏去掉。重新make all。没有报错。make install.
再参考:
http://lazyfoo.net/tutorials/OpenGL/01_hello_opengl/mac/xcode/index.php
Remove the main.cpp file autogenerated for the project as we're not using it. Go download the source for lesson 01. Add the source files inside to your project.
2)Click on your project to reveal the Build Settings tab. Click on the Build Settings tab. Under in the Linking section in the Other Linker Flags add -lGLUT. This will make the project link with the freeGLUT Unix library we installed.
3)In the Search Paths section add
"/opt/X11/include" "/usr/local/include"
to the Header Search Paths and"/opt/X11/lib" "/usr/local/lib"
to the Library Search PathsThis makes it so XCode will find the header/library files for XQuartz (/opt/X11/) and freeGLUT (/usr/local/).
4)Click on the Build Phases Tab, open up Link Binary with Libraries and add the OpenGL framework.
Now build. If there are any errors, make sure you didn't skip a step.
Now that you have OpenGL and freeGLUT compiling, it time to go onto part 2 of the tutorial.