Mac OS X Glut build instructions
生活随笔
收集整理的這篇文章主要介紹了
Mac OS X Glut build instructions
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Mac OS X Glut build instructions(在Mac上用glut庫編寫OpenGL程序)
1. Building?GLUT?apps?under?Mac?OS?X
There?are?only?a?few?modifications?you?need?to?make?to?the
??robot.c?sample?to?get?it?compiled?on?your?Mac.??These
??instructions?were?tested?under?OS?X?10.3?(Panther)?with?XCode?1.1.
?
XCode?comes?with?everything?you?need?to?build?GL?apps,?including
??stable?versions?of?OpenGL,?GLUT,?gcc?and?all?the?related?make?tools.
?
XCode?by?default?places?the?include?files?for?GLUT?in?a?different
??location?than?MESA,?so?to?build?robot.c?you?need?to?change?line
??46?from
#include?<GL/glut.h>
to
#include?<GLUT/glut.h>
After?making?this?change?you?are?ready?to?build?from?the?command
??line:
gcc?-framework?GLUT?-framework?OpenGL?-framework?Cocoa
??robot.c?-o?robot
Note?the?use?of?the?-framework?option?to?make?use
??of?OS?X's?packaged?libraries.??The?Cocoa?framework?provides?the?OS
??services?required?by?GLUT,?such?as?interfacing?with?the?window
??manager?(Aqua).
I?will?post?a?sample?makefile?here?which?can?be?used?to?compile your?files?under?OS?X?or?Linux?as?necessary?without?modification;?as soon?as?my?Sutherland?account?is?activated.
using?namespace?std;
#include?<math.h>
float?myAngle;
float?myTime;
//codefragmentbegin,headerInclude
#include?<GLUT/glut.h>
//codefragmentend,headerInclude
//codefragmentbegin,app
void?prepareOpenGL()
{
????myAngle?=?0;
????myTime?=?0;
}
void?draw()
{
????glClearColor(?0,?.5,?.8,?1?);
????glClear(?GL_COLOR_BUFFER_BIT?|?GL_DEPTH_BUFFER_BIT?);
????glMatrixMode(?GL_MODELVIEW?);
????glLoadIdentity();
????glRotatef(?myAngle,?0,?0,?1?);
????glTranslatef(?0,?0,?1?);
????glColor3f(?0,?1,?0?);
????glBegin(?GL_QUADS?);
????float?ww?=?.9;
????float?hh?=?.9;
????glTexCoord2f(?0,?0?);
????glVertex3f(?-ww,?-hh,?0?);
????glTexCoord2f(?1,?0?);
????glVertex3f(??ww,?-hh,?0?);
????glTexCoord2f(?1,?1?);
????glVertex3f(??ww,??hh,?0?);
????glTexCoord2f(?0,?1?);
????glVertex3f(?-ww,??hh,?0?);
????glEnd();
????glutSwapBuffers();
}
void?angleUpdate(?int?delay?)
{
????float?twopi?=?2?*?M_PI;
????myTime?=?(?myTime?>?twopi?)???0?:?myTime?+?.03;
????myAngle?=?sinf(?twopi?*?myTime?);
????glutTimerFunc(?delay,?angleUpdate,?delay?);
????glutPostRedisplay();
}
int?main(?int?argc,
??????????char?*?argv[]?)
{
????glutInit(?&argc,?argv?);
????//?choose?a?visual?and?create?a?window
????glutInitDisplayString(??"stencil>=2?rgb~8?double?depth>=16?samples"?);
//????glutInitDisplayMode(?GLUT_RGB?|?GLUT_DOUBLE?|?GLUT_DEPTH?);
????glutInitWindowSize(?450,?300?);
????glutCreateWindow(?"GLUT?Configuration?Example"?);
????//?initalize?our?opengl?(context?is?now?valid)
????prepareOpenGL();
????//?register?callback?functions
????int?delay?=?50;
????glutTimerFunc(?delay,?angleUpdate,?delay?);
????glutDisplayFunc(?draw?);
????glutMainLoop();
}
//codefragmentend,app
void?altinit()
{
//codefragmentbegin,stringinit
????glutInitDisplayString(??"stencil>=2?rgb~8?double?depth>=16?samples"?);
//codefragmentend,stringinit
}
??????????????????????????????????????? Wentao Sun, Autodesk, Inc.
?
1. Building?GLUT?apps?under?Mac?OS?X
There?are?only?a?few?modifications?you?need?to?make?to?the
??robot.c?sample?to?get?it?compiled?on?your?Mac.??These
??instructions?were?tested?under?OS?X?10.3?(Panther)?with?XCode?1.1.
?
XCode?comes?with?everything?you?need?to?build?GL?apps,?including
??stable?versions?of?OpenGL,?GLUT,?gcc?and?all?the?related?make?tools.
?
XCode?by?default?places?the?include?files?for?GLUT?in?a?different
??location?than?MESA,?so?to?build?robot.c?you?need?to?change?line
??46?from
#include?<GL/glut.h>
to
#include?<GLUT/glut.h>
After?making?this?change?you?are?ready?to?build?from?the?command
??line:
gcc?-framework?GLUT?-framework?OpenGL?-framework?Cocoa
??robot.c?-o?robot
Note?the?use?of?the?-framework?option?to?make?use
??of?OS?X's?packaged?libraries.??The?Cocoa?framework?provides?the?OS
??services?required?by?GLUT,?such?as?interfacing?with?the?window
??manager?(Aqua).
I?will?post?a?sample?makefile?here?which?can?be?used?to?compile your?files?under?OS?X?or?Linux?as?necessary?without?modification;?as soon?as?my?Sutherland?account?is?activated.
?
?Source code:
using?namespace?std;
#include?<math.h>
float?myAngle;
float?myTime;
//codefragmentbegin,headerInclude
#include?<GLUT/glut.h>
//codefragmentend,headerInclude
//codefragmentbegin,app
void?prepareOpenGL()
{
????myAngle?=?0;
????myTime?=?0;
}
void?draw()
{
????glClearColor(?0,?.5,?.8,?1?);
????glClear(?GL_COLOR_BUFFER_BIT?|?GL_DEPTH_BUFFER_BIT?);
????glMatrixMode(?GL_MODELVIEW?);
????glLoadIdentity();
????glRotatef(?myAngle,?0,?0,?1?);
????glTranslatef(?0,?0,?1?);
????glColor3f(?0,?1,?0?);
????glBegin(?GL_QUADS?);
????float?ww?=?.9;
????float?hh?=?.9;
????glTexCoord2f(?0,?0?);
????glVertex3f(?-ww,?-hh,?0?);
????glTexCoord2f(?1,?0?);
????glVertex3f(??ww,?-hh,?0?);
????glTexCoord2f(?1,?1?);
????glVertex3f(??ww,??hh,?0?);
????glTexCoord2f(?0,?1?);
????glVertex3f(?-ww,??hh,?0?);
????glEnd();
????glutSwapBuffers();
}
void?angleUpdate(?int?delay?)
{
????float?twopi?=?2?*?M_PI;
????myTime?=?(?myTime?>?twopi?)???0?:?myTime?+?.03;
????myAngle?=?sinf(?twopi?*?myTime?);
????glutTimerFunc(?delay,?angleUpdate,?delay?);
????glutPostRedisplay();
}
int?main(?int?argc,
??????????char?*?argv[]?)
{
????glutInit(?&argc,?argv?);
????//?choose?a?visual?and?create?a?window
????glutInitDisplayString(??"stencil>=2?rgb~8?double?depth>=16?samples"?);
//????glutInitDisplayMode(?GLUT_RGB?|?GLUT_DOUBLE?|?GLUT_DEPTH?);
????glutInitWindowSize(?450,?300?);
????glutCreateWindow(?"GLUT?Configuration?Example"?);
????//?initalize?our?opengl?(context?is?now?valid)
????prepareOpenGL();
????//?register?callback?functions
????int?delay?=?50;
????glutTimerFunc(?delay,?angleUpdate,?delay?);
????glutDisplayFunc(?draw?);
????glutMainLoop();
}
//codefragmentend,app
void?altinit()
{
//codefragmentbegin,stringinit
????glutInitDisplayString(??"stencil>=2?rgb~8?double?depth>=16?samples"?);
//codefragmentend,stringinit
}
?
Build commands:
?
?g++?-framework?GLUT?-framework?OpenGL??main.cpp?-o?test?
Run:
./test
?
?
?
Notice:
(1) Framework 類型提供的lib和其他.a & .dylib的庫文件不同;
(2) 編譯時使用 -framework GLUT的編譯選項。
?
轉載于:https://www.cnblogs.com/SunWentao/archive/2008/08/18/1270497.html
總結
以上是生活随笔為你收集整理的Mac OS X Glut build instructions的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 索尼发布外挂手柄:iPhone秒变PS掌
- 下一篇: 北京海淀一小区现长牙怪鱼 野保站:入侵生