Mac OS X glut build instructions

Source: Internet
Author: User
Mac OS X glut build instructions (OpenGL program written on Mac using GLUT Library)

Wentao sun, Autodesk, Inc.

 

1. Building glut apps under Mac OS X

There are only a few modifications you need to make to
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 ();

Gluswapbuffers ();
}

Void angleupdate (INT delay)
{
Float twopi = 2 * m_pi;
Mytime = (mytime> twopi )? 0: mytime +. 03;
Myangle = sinf (twopi * mytime );
Glutimerfunc (delay, angleupdate, delay );
Glupostredisplay ();
}

Int main (INT argc,
Char * argv [])
{
Gluinit (& argc, argv );

// Choose a visual and create a window
Gluinitdisplaystring ("stenpencil> = 2 RGB ~ 8 double depth> = 16 samples ");
// Gluinitdisplaymode (glu_rgb | glu_double | glu_depth );
Gluinitwindowsize (450,300 );
Glucreatewindow ("glut configuration example ");

// Initalize our OpenGL (context is now valid)
Prepareopengl ();

// Register callback Functions
Int delay = 50;
Glutimerfunc (delay, angleupdate, delay );
Gludisplayfunc (draw );
Glumainloop ();

}

// Codefragmentend, app

Void altinit ()
{
// Codefragmentbegin, stringinit
Gluinitdisplaystring ("stenpencil> = 2 RGB ~ 8 double depth> = 16 samples ");
// Codefragmentend, stringinit
}

 

Build commands:

 

G ++-framework glut-framework OpenGL main. cpp-o Test

 

Run:

./Test

 

 

 


Notice:

(1) The LIB provided by the framework type is different from that provided by other. A &. dylib library files;

(2) Use the-framework glut compilation option during compilation.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.