<html>
<head>
</head><body><pre>
/*
** File:          step0.c
** Description:   Renders a GLUT teapot.
**                Demonstrates aspects of lighting.
** Rev:           1.0
** Created:       07 September 2002
** Last Update:   08 September 2002
** Author:        Fran Soddell
** Email:         F.Soddell@bendigo.latrobe.edu.au
*/
#include &lt;GL/glut.h&gt;
#define TRUE  1
#define FALSE 0
/*
** manage 3D
*/
enum {x,y,z};
/*
** manage window
*/
int width =400;
int height=400;
int xPosition=50;
int yPosition=70;
/*
** manage world projection
*/
enum {xLeft,xRight,yBottom,yTop,zNear,zFar};
GLdouble world[]={
   -2.0,2.0,-2.0,2.0,1,1000
};
GLdouble fovy   =60.0;
GLdouble aspect =1.0;
int perspective =TRUE;
/*
** manage camera
*/
GLdouble eye[]={
   0.0,0.0,4.0
};
GLdouble centre[]={
   0.0,0.0,0.0
};
GLdouble up[]={
   0.0,1.0,0.0
};
/*
** manage colour
*/
#define NUM_COLOURS 8
#define ALPHA 0.0
enum {red,green,blue,
      yellow,magenta,cyan,
      white,black};
typedef GLfloat colourType[4];
colourType colour[NUM_COLOURS]={
   {1.0,0.0,0.0,1.0},{0.0,1.0,0.0,1.0},{0.0,0.0,1.0,1.0},
   {1.0,1.0,0.0,1.0},{1.0,0.0,1.0,1.0},{0.0,1.0,1.0,1.0},
   {1.0,1.0,1.0,1.0},{0.0,0.0,0.0,1.0}
};
/*
** manage model
*/
int wireframe=FALSE;
/*
** manage model transforms
*/
GLdouble ra=0;
GLdouble r[]={0,1,0};
/*
** ***********************************************************
** code
** ***********************************************************
*/
void renderView(){
   glColor3fv(colour[red]);
   glRotated(ra,r[x],r[y],r[z]);
   if(wireframe)
   	glutWireTeapot(1.0);
   else
   	glutSolidTeapot(1.0);
}
void setCamera(){
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   gluLookAt(eye[x], eye[y],eye[z],
             centre[x],centre[y],centre[z],
             up[x],up[y],up[z]);
}
void display(){
   setCamera();
   glClear(GL_COLOR_BUFFER_BIT);
   renderView();
   glutSwapBuffers();
}
void setProjection(){
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   if(!perspective)
      glOrtho(world[xLeft],  world[xRight],
              world[yBottom],world[yTop],
              world[zNear],  world[zFar]);
   else
      gluPerspective(fovy,1,world[zNear],world[zFar]);
}
void reshapeWindow(int w, int h){
   int yOrigin=0, xOrigin=0;
   if(w&gt;h){
      yOrigin=(h-w)/2;
      h=w;
   }
   else{
      xOrigin=(w-h)/2;
      w=h;
   }
   glViewport(xOrigin,yOrigin,(GLsizei)w,(GLsizei)h);
   setProjection();
}
void keyboard(unsigned char key,int xMouse,int yMouse){
   switch(key){
      case 27 : exit(0);
      case &#39;p&#39;: perspective=!perspective;
                setProjection(); break;
      case &#39;r&#39;: ra+=1;
                if(ra&gt;=360)ra=0; break;
      case &#39;w&#39;: wireframe=!wireframe; break;
   }
   glutPostRedisplay();
}

void setUpGLUT(int argc,char ** argv){
   glutInit(&amp;argc,argv);
   glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
   glutInitWindowSize(width,height);
   glutInitWindowPosition(xPosition,yPosition);
   glutCreateWindow(&quot;Light Step 0&quot;);
   /*
   ** Register callbacks.
   */
   glutDisplayFunc(display);
   glutReshapeFunc(reshapeWindow);
   glutKeyboardFunc(keyboard);
}
void initialiseGL(){
   int i;
   glClearColor(0,0,0,ALPHA);
}
int main(int argc,char ** argv){
   setUpGLUT(argc,argv);
   initialiseGL();
   /*
   ** Display window and enter the GLUT event
   ** processing loop.
   */
   glutMainLoop();

   return 0;
}
</pre></body></html>