<html>
** File: teapot1.c
** Description: Renders a 3D wireframe image
** of a teapot.
** Rev: 1.01
** Created: 06 August 2001
** Last Update: 22 August 2002
** Author: Fran Soddell
** Email: F.Soddell@bendigo.latrobe.edu.au
*/
#include &lt;GL/glut.h&gt;
/*
** manage 3D
*/
enum {x,y,z};
/*
** manage window
*/
int width =500;
int height=500;
int xPosition=50;
int yPosition=70;
/*
** manage world
*/
enum {xLeft,xRight,yBottom,yTop,zNear,zFar};
GLdouble world[]={
-1.0,1.0,-1.0,1.0,0.1,100
};
/*
** manage camera
*/
GLdouble eye[]={
2.0,2.0,2.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,colours};
typedef GLfloat colourType[3];
colourType colour[NUM_COLOURS]={
{1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0},
{1.0,1.0,0.0},{1.0,0.0,1.0},{0.0,1.0,1.0},
{1.0,1.0,1.0},{0.0,0.0,0.0}
};
/*
** model transform management
*/
enum {teapot,models};
GLdouble t[][3]={
{0.1,0.0,0.0}
};
/*
** ***********************************************************
** code
** ***********************************************************
*/
void renderView(){
glColor3fv(colour[red]);
glTranslated(t[teapot][x],t[teapot][y],t[teapot][z]);
glutWireTeapot(0.5);
}
void display(){
/*
** Clear window with background colour before (re)rendering.
*/
glClear(GL_COLOR_BUFFER_BIT);
renderView();
glFlush();
}
void reshapeWindow(int w, int h){
glViewport(0,0,(GLsizei)w,(GLsizei)h);
/*
** specify orthogonal 3D projection
** and set world coordinates
*/
glOrtho(world[xLeft],world[xRight],
world[yBottom],world[yTop],
world[zNear],world[zFar]);
/*
** set up camera
*/
gluLookAt(eye[x], eye[y],eye[z],
centre[x],centre[y],centre[z],
up[x],up[y],up[z]);
}
void keyboard(unsigned char key,int xMouse,int yMouse){
switch(key){
case 27: exit(0);
}
glutPostRedisplay();
}
void specialKeys(int key,int xMouse,int yMouse){
int i;
for(i=0;i&lt;=z;i++) t[teapot][i]=0.0;
switch(key){
case GLUT_KEY_PAGE_UP : t[teapot][z]= 0.1;break;
case GLUT_KEY_PAGE_DOWN: t[teapot][z]=-0.1;break;
case GLUT_KEY_RIGHT : t[teapot][x]= 0.1;break;
case GLUT_KEY_LEFT : t[teapot][x]=-0.1;break;
case GLUT_KEY_UP : t[teapot][y]= 0.1;break;
case GLUT_KEY_DOWN : t[teapot][y]=-0.1;break;
}
glutPostRedisplay();
}
void mouse(int button,int state,int xMouse,int yMouse){
glutPostRedisplay();
}
void setUpGLUT(int argc,char ** argv){
glutInit(&amp;argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(width,height);
glutInitWindowPosition(xPosition,yPosition);
glutCreateWindow(&quot;Single Buffered 3D Teapot&quot;);
/*
** Register callbacks.
*/
glutDisplayFunc(display);
glutReshapeFunc(reshapeWindow);
glutSpecialFunc(specialKeys);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
}
void initialiseGL(){
glClearColor(1,1,1,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></pre></body></html>