Mac OS X Glut build instructions

 Mac OS X Glut build instructions(在Mac上用glut库编写OpenGL程序)

                                        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:

#include  < iostream >
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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值