float spin=20;
float cw,ccw;
int x;
void init(void)
{
x=1;
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat reflectability[] = { 100.0 };
GLfloat ambient[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat diffuse[] = { 1.0, 3.0, 0.0, 1.0 };
GLfloat specular[] = { 1.0, 3.0, 0.0, 1.0 };
GLfloat position[] = { 3.0, 3.0, 0.0, 0.0 };
GLfloat lmodel_ambient[] = { 0.2, 0.2, 0.2, 1.0 };
GLfloat local_view[] = { 0.0 };
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, reflectability);
glFrontFace (GL_CW);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
glEnable(GL_DEPTH_TEST);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClearAccum(0.0, 0.0, 0.0, 0.0);
}
void display()
{
cw=0+spin;
ccw=0-spin;
static GLfloat red[]={1.0, 0.0, 0.8, 1.0};
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(-0.5, 0.5, 0.0);
glRotatef(cw, 0.0, 1.0, 0.0);
glColor3f(1.0f, 0.0f, 0.0f);
glutWireTeapot(0.2);
glPopMatrix();
glFlush();
glPushMatrix();
glTranslatef(0.5, 0.5, 0.0);
glRotatef( cw, 0.0, 1.0, 0.0);
glColor3f(1.0f, 0.0f, 0.0f);
glutWireTeapot(0.2);
glPopMatrix();
glFlush();
glPushMatrix();
glTranslatef(0.5, -0.5, 0.0);
glRotatef(ccw, 0.0, 1.0, 0.0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, red);
glutSolidTeapot(0.2);
glPopMatrix();
glFlush();
glPushMatrix();
glTranslatef(-0.5, -0.5, 0.0);
glRotatef(ccw, 0.0, 1.0,0.0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, red);
glutSolidTeapot(0.2);
glutSwapBuffers();
glPopMatrix();
glFlush();
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (0.0, 0.0, -5.0, 0.5, 0.5, 20.0);
glMatrixMode (GL_MODELVIEW);
}
void keyboard(unsigned char k, int t, int q)
{
switch (k)
{
case 'a':
x = (x+1);
break;
case 'd':
x =(x-1);
break;
case 'x':
exit(0);
}
glutPostRedisplay();
}
static void _Timer(int value)
{
spin=spin+x;
glutPostRedisplay();
glutTimerFunc(1, _Timer, 0);
}
int main(int argc,char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE| GLUT_RGBA | GLUT_ACCUM | GLUT_DEPTH);
glutInitWindowSize (600, 600);
glutInitWindowPosition (300, 300);
glutCreateWindow ("Tea Pot Window");
glutKeyboardFunc(keyboard);
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutTimerFunc(1, _Timer, 0);
init();
glutMainLoop();
return 0;
return 0;
}