zoukankan      html  css  js  c++  java
  • 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, .81 );
        glClear( GL_COLOR_BUFFER_BIT 
    | GL_DEPTH_BUFFER_BIT );

        glMatrixMode( GL_MODELVIEW );
        glLoadIdentity();
        glRotatef( myAngle, 
    001 );

        glTranslatef( 
    001 );
        glColor3f( 
    010 );
        glBegin( GL_QUADS );
        
    float ww = .9;
        
    float hh = .9;
        glTexCoord2f( 
    00 );
        glVertex3f( 
    -ww, -hh, 0 );
        glTexCoord2f( 
    10 );
        glVertex3f(  ww, 
    -hh, 0 );
        glTexCoord2f( 
    11 );
        glVertex3f(  ww,  hh, 
    0 );
        glTexCoord2f( 
    01 );
        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( 450300 );
        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的编译选项。


  • 相关阅读:
    2017-5-21 Asp.Net内置对象 和 DropDownList时间年月日的三级联动
    【2017-04--28】Winform中ListView控件
    【2017-04-27】布局及容器控件、打开多窗体、构造函数传值、打开唯一窗口
    【2017-04-25】winform公共控件、菜单和工具栏
    【2017-04-24】WinForm基础、登录窗口、窗口属性
    【2017-04-20】Sql字符串注入式攻击与防御,实体类,数据访问类
    【2017-04-18】Ado.Net C#连接数据库进行增、删、改、查
    【2017-04-17】类库、通用变量、is和as、委托
    【2017-04-16】抽象类、接口、构造函数、重载、静态成员和方法
    【面向对象】类、访问修饰符、封装、继承、多态
  • 原文地址:https://www.cnblogs.com/SunWentao/p/1270497.html
Copyright © 2011-2022 走看看