顯示具有 01161053_許佳欣 標籤的文章。 顯示所有文章
顯示具有 01161053_許佳欣 標籤的文章。 顯示所有文章

2014年6月6日 星期五

運鏡喔


#include <GL/glut.h>
#include <math.h>
#include <stdlib.h>
float angleX =0,angle2=0,angle3=0,angleY=0;
float eyeX=0.2,eyeY=0.2,eyeZ=0.7, objX=0, objY=0, objZ=0, upX=1, upY=0, upZ=0;
float theSize=0.5;
void timerRotateShow(int t)
{
//if(t%10==0) glClearColor((rand()%255/255.0), (rand()%255/255.0), (rand()%255/255.0), (rand()%255/255.0));
glutTimerFunc(30,timerRotateShow, t+1);
eyeX=cos(t/100.0*3.1415);
eyeZ=sin(t/100.0*3.1415);
//eyeY-=0.005;
theSize+=0.005;
glutPostRedisplay();
}
void keyboard(unsigned char key, int x, int y)
{
if(key=='1') angleX+=5;
if(key=='2') angleX-=5;
if(key=='3') angle2+=5;
if(key=='4') angle2-=5;
if(key=='5') angle3+=3;
if(key=='6') angle3-=3;
if(key=='0') angleY+=5;
if(key==' ') 
{
eyeX-=0.01;
eyeY-=0.01;
}
if(key=='o')
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1, 1, -1, 1, -1, 1);
glMatrixMode(GL_MODELVIEW);
}
if(key=='r')
{
glutTimerFunc(0, timerRotateShow, 0);
}
glutPostRedisplay();//請電腦重新畫一次畫面
}

void myLight()
{
const GLfloat light_position[] = { 2.0f, 5.0f, -5.0f, 0.0f };
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
}

void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix();
   gluLookAt(eyeX, eyeY, eyeZ, objX, objY, objZ, upX, upY, upZ);  
glScalef(theSize, theSize, theSize);     
   glTranslatef(0,0.08,0);
   glColor3f(1,0.76,0.76);
glRotatef(angleX, 0,1,0);
glRotatef(angleY,0,0,1);
/*body*/
glPushMatrix();
glScalef(1.2,0.8,1);
glutSolidSphere(0.25,30,30);
glPopMatrix();
/*head*/
        glPushMatrix();
        glTranslatef(0,0.5,0);
            glutSolidSphere(0.35,30,30);
        glPopMatrix();
/*leftshoudler*/
glPushMatrix();
        glTranslatef(-0.3,0.1,0);
            glutSolidSphere(0.15,30,30);
//leftarm
glPushMatrix();
   glTranslatef(-0.05,-0.04,0);
glRotatef(-angle2, 1,0,0);
glRotatef(-angle3, 0,0,1);
glTranslatef(0,-0.15,0);
glPushMatrix();
glScalef(0.2,3,0.3);
glutSolidCube(0.2);
glPopMatrix();
//lefthand
glPushMatrix();
glTranslatef(-0.07,-0.3,0);
glScalef(1.3,0.5,0.5);
glutSolidCube(0.15);
glPopMatrix();
glPopMatrix();
        glPopMatrix();
        /*rightshoudler*/
glPushMatrix();
        glTranslatef(0.3,0.1,0);
            glutSolidSphere(0.15,30,30);
            //rightarm
            glPushMatrix();
                glTranslatef(0.05,-0.04,0);
glRotatef(angle2, 1,0,0);
glRotatef(angle3, 0,0,1);
glTranslatef(0,-0.15,0);
glPushMatrix();
glScalef(0.2,3,0.3);
glutSolidCube(0.2);
glPopMatrix();
//righthand
glPushMatrix();
glTranslatef(0.07,-0.3,0);
glScalef(1.3,0.5,0.5);
glutSolidCube(0.15);
glPopMatrix();
glPopMatrix();
        glPopMatrix();
        /*peepee*/
        glPushMatrix();
        glTranslatef(0,-0.15,0);
        glScalef(0.6,1,1);
            glutSolidCube(0.2);
        glPopMatrix();
/*downpee*/
glPushMatrix();
            glTranslatef(0,-0.28,0);
            glScalef(1.2,0.5,1);
glutSolidSphere(0.15,30,30);
glPopMatrix();
/**/
glPushMatrix();
   glTranslatef(-0.15,-0.28,0);
glutSolidSphere(0.08,30,30);
glPopMatrix();
/**/
glPushMatrix();
   glTranslatef(0.15,-0.28,0);
glutSolidSphere(0.08,30,30);
glPopMatrix();
/*leftthigh*/
glPushMatrix();
            glTranslatef(-0.15,-0.25,0);
glRotatef(angle2, 1,0,0);
glTranslatef(0,-0.15,0);
glPushMatrix();
glScalef(0.5,0.8,0.5);
glutSolidCube(0.2);
glPopMatrix();
glPushMatrix();//KNEE
   glTranslatef(0,-0.1,0);
glutSolidSphere(0.05,30,30);
glPushMatrix();//LEFTLEG
   glTranslatef(0,0,0);
   glPushMatrix();
   glRotatef(-angle2+5, 0.5,0,0);
   glTranslatef(0,-0.1,0);
glScalef(0.5,1.5,0.5);
glutSolidCube(0.2);
glPushMatrix();//FOOT
glTranslatef(0,-0.1,-0.15);
      glScalef(1.58,0.5,2.8);
glutSolidCube(0.2);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
/*rightthigh*/
glPushMatrix();
            glTranslatef(0.15,-0.25,0);
glRotatef(-angle2, 1,0,0);
glTranslatef(0,-0.15,0);
glPushMatrix();
glScalef(0.5,0.8,0.5);
glutSolidCube(0.2);
glPopMatrix();
glPushMatrix();//KNEE 
   glTranslatef(0,-0.1,0);
glutSolidSphere(0.05,30,30);
glPushMatrix();//RIGHTLEG
glRotatef(angle2+5, 1,0,0);
   glTranslatef(0,-0.1,0);
   glScalef(0.5,1.5,0.5);
glutSolidCube(0.2);
glPushMatrix();//FOOT
glTranslatef(0,-0.1,-0.15);
      glScalef(1.58,0.5,2.8);
glutSolidCube(0.2);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
/*righteye*/
glPushMatrix();
glTranslatef(0.15,0.5,-0.2);
glColor3f(0.25,0.41,1);
glutSolidSphere(0.15,30,30);
  glPopMatrix();
  /*righteye*/
  glPushMatrix();
glTranslatef(-0.15,0.5,-0.2);
glColor3f(0.25,0.41,1);
glutSolidSphere(0.15,30,30);
  glPopMatrix();
 
glPopMatrix();

glutSwapBuffers();
}

int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("homework robot");

glutDisplayFunc(display);
glutKeyboardFunc(keyboard);

myLight();
glutMainLoop();
}


2014年5月30日 星期五

內插 好難轉喔

/*都轉到哪去惹*/
#include <GL/glut.h>
#include <stdio.h>
float angle[20]={0,90,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
float angleOld[20]={0,90,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
float angleNew[20]={90,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
float a=0;
FILE *fout=NULL,*fin=NULL;
int angleID=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(angle[3], angle[4], angle[5]);
glPushMatrix();
glRotatef(angle[0], 0, 0, 1);
glutSolidTeapot(0.3);
glPopMatrix();
glPushMatrix();
glTranslatef(0.5, 0, 0);
glRotatef(angle[1], 0, 0, 1);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
void readNext()
{
if(fin==NULL) fin=fopen("animation.txt","r");
a+=0.01;
for(int i=0;i<20;i++)
{
angle[i]=angleOld[i]*(1-a)+ angleNew[i] * a;
if(a>=1.0)
{
a=0.0;
for(int i=0;i<20;i++)
{
angleOld[i]=angleNew[i];
fscanf(fin,"%f",&angleNew[i]);
}
}
}
}
void timer(int t)
{
glutTimerFunc(100, timer, 0);
readNext();
glutPostRedisplay();
}
int OldX=0,OldY=0;
void mouse(int button,int state, int x, int y)
{
OldX=x; OldY=y;
}
void motion(int x, int y)
{
angle[angleID] +=(x-OldX);
OldX=x;
glutPostRedisplay();
}
void keyboard(unsigned char key, int x, int y)
{
if(key=='1') angleID=0;
if(key=='2') angleID=1;
if(key=='3') angleID=2;
if(key=='4') angleID=3;
if(key=='s'){
if(fout==NULL) fout=fopen("animation.txt","w+");
for(int i=0;i<20;i++)
{
printf("%f ",angle[i]);
fprintf(fout,"%f ",angle[i]);
}
printf("\n");
    fprintf(fout,"\n");
}
if(key=='r')
readNext();
else if(key=='p')
glutTimerFunc(0, timer, 0);

glutPostRedisplay();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE| GLUT_DEPTH);
glutCreateWindow("week15");
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyboard);
glutDisplayFunc(display);
glutMainLoop();
}

2014年5月23日 星期五

今天來播音樂

/*連放wav*/
/*mp3*/
/*開讀檔*/
if(key=='s') 
{
if(fout==NULL) fout=fopen("a.txt","w+");
printf("%f %f %f %f %f %f %f\n",angle[0],angle[1],angle[2],angle[3],angle[4],angle[5],angle[6],angle[7]);
fprintf(fout,"%f %f %f %f %f %f %f\n",angle[0],angle[1],angle[2],angle[3],angle[4],angle[5],angle[6],angle[7]);
}
if(key=='r') 
{
if(fin==NULL) fin=fopen("a.txt","r");
fscanf(fin,"%f %f %f %f %f %f %f\n",&angle[0],&angle[1],&angle[2],&angle[3],&angle[4],&angle[5],&angle[6],&angle[7]);
printf("%f %f %f %f %f %f %f\n",angle[0],angle[1],angle[2],angle[3],angle[4],angle[5],angle[6],angle[7]);
}

/*泰捫*/

void timer(int t)
{
glutTimerFunc(1000,timer,0);
if(fin==NULL) fin=fopen("a.txt","r");
fscanf(fin,"%f %f %f %f %f %f %f\n",&angle[0],&angle[1],&angle[2],&angle[3],&angle[4],&angle[5],&angle[6],&angle[7]);
printf("%f %f %f %f %f %f %f\n",angle[0],angle[1],angle[2],angle[3],angle[4],angle[5],angle[6],angle[7]);
glutPostRedisplay();
}
if(key=='p')
{
glutTimerFunc(1000,timer,0);
}






2014年5月16日 星期五

mouse旋轉機器人 好了啦超會跳


/*dancing robot*/
#include <GL/glut.h>
#include <opencv/highgui.h>
#include <opencv/cv.h>
//float angleX =0, angle0=0, angle1=0, angle2=0, angle3=0;
int angleID=0;
float angle[8]={0,0,0,0,0,0,0,0};
GLuint id[5];//技巧2: 使用陣列, 讓變數 變 簡單 simple
IplImage * img[5];
char filename[5][100]={"imgBody.png", "imgHand0.png", "imgLeg0.png", "imgLeg1.png","imgarm.png"};
void myTexture()
{
    glEnable(GL_TEXTURE_2D);
    for(int i=0; i<5; i++){//技巧3: 迴圈, 可以讓程式碼, 做重覆的事可以很爽 清爽
    img[i] = cvLoadImage( filename[i] );
    cvCvtColor(img[i], img[i], CV_BGR2RGB);
    glGenTextures(1, &id[i]);
    glBindTexture(GL_TEXTURE_2D, id[i]);//head
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img[i]->width, img[i]->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img[i]->imageData); 
}
}
void myRect()//技巧1: 重覆的程式碼, 用函式拉出來, 就不用一直copy啦
{//函式就是 黑盒子 幫你做事情!
    glPushMatrix();
    glScalef(0.2, 0.5, 0.5);
    glBegin(GL_POLYGON);
    glTexCoord2f(0,0);  glVertex3f(-0.5, 0.5,0);
    glTexCoord2f(0,1);  glVertex3f(-0.5,-0.5,0);
    glTexCoord2f(1,1);  glVertex3f( 0.5,-0.5,0);
    glTexCoord2f(1,0);  glVertex3f( 0.5, 0.5,0);
    glEnd();
    glPopMatrix(); 
}
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, id[0]);
myRect();//body//技巧1: 用函式, 哥就是帥!
glPushMatrix();//left hand
glTranslatef(-0.1, 0.15, 0);
glRotatef(angle[0], 0,0,1);
glTranslatef(0, -0.25, 0);
glBindTexture(GL_TEXTURE_2D, id[1]);
myRect();//技巧1: 用函式, 哥就是帥!
glPushMatrix();//left arm
glTranslatef(0, -0.25, 0);
glutSolidSphere(0.12,20,20);
//glTranslatef(0, -0.25, 0);
glRotatef(angle[1], 0,0,1);
glTranslatef(0, -0.25, 0);
glBindTexture(GL_TEXTURE_2D, id[4]);
myRect();//技巧1: 用函式, 哥就是帥!
glPopMatrix();
glPopMatrix();
glPushMatrix();//right hand
glTranslatef(0.1, 0.15, 0);
glRotatef(angle[2], 0,0,1);
glTranslatef(0, -0.25, 0);
glBindTexture(GL_TEXTURE_2D, id[1]);
myRect();//技巧1: 用函式, 哥就是帥!
glPushMatrix();//right arm
glTranslatef(0, -0.25, 0);
glutSolidSphere(0.12,20,20);
//glTranslatef(0, -0.25, 0);
glRotatef(angle[3], 0,0,1);
glTranslatef(0, -0.25, 0);
glBindTexture(GL_TEXTURE_2D, id[4]);
myRect();//技巧1: 用函式, 哥就是帥!
glPopMatrix();
glPopMatrix();
glPushMatrix();//left leg
glTranslatef( -0.05, -0.25, 0);
glRotatef(angle[4], 0,0,1);
glTranslatef(0, 0.25, 0);
glBindTexture(GL_TEXTURE_2D, id[2]);
myRect();
glPushMatrix();//left foot
glTranslatef(0, 0.25, 0);
glutSolidSphere(0.15,20,20);
//glTranslatef( 0, 0.25, 0);
glRotatef(angle[5], 0,0,1);
glTranslatef(0, 0.2, 0);
glBindTexture(GL_TEXTURE_2D, id[3]);
myRect();
glPopMatrix();   
glPopMatrix();
glPushMatrix();//right leg
glTranslatef( 0.05, -0.25, 0);
glRotatef(angle[6], 0,0,1);
glTranslatef(0, 0.25, 0);
glBindTexture(GL_TEXTURE_2D, id[2]);
myRect();
glPushMatrix();//right foot
glTranslatef(0, 0.25, 0);
glutSolidSphere(0.15,20,20);
//glTranslatef( 0, 0.25, 0);
glRotatef(angle[7], 0,0,1);
glTranslatef(0, 0.2, 0);
glBindTexture(GL_TEXTURE_2D, id[3]);
myRect();
glPopMatrix();
glPopMatrix();
glTranslatef(0, 0.4, 0);
glutSolidSphere(0.2,30,30);
glPopMatrix();
glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{
if(key=='0') angleID=0;
if(key=='1') angleID=1;
if(key=='2') angleID=2;
if(key=='3') angleID=3;
if(key=='4') angleID=4;
if(key=='5') angleID=5;
if(key=='6') angleID=6;
if(key=='7') angleID=7;
 
glutPostRedisplay();//請電腦重新畫一次畫面
}
int oldX=0, oldY=0;
void motion(int x, int y)
{
angle[angleID] += x-oldX;  oldX=x;
glutPostRedisplay();
}
void mouse(int button, int state, int x, int y)
{
oldX=x; oldY=y;
}

int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week13");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);//記得呼叫
glutMotionFunc(motion);
myTexture();
glutMainLoop();
}


2014年4月25日 星期五

茶壺轉轉

                                                                     /*鍵盤控制*/
#include <GL/glut.h>
#include <stdio.h>
float angleX=0;
void keyboard(unsigned char key, int x,int y)
{
printf("%c  %d %d\n",key,x,y);//xy座標
     if(key=='a') angleX +=3;
     if(key=='b') angleX -=3;
     glutPostRedisplay();
}
void mylight()//打光
{
const GLfloat light_position[] = { 2.0f, 5.0f, 0.0f, 0.0f };
glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_LIGHTING);
        glLightfv(GL_LIGHT0, GL_POSITION, light_position);
}
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angleX,0,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week10");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
mylight();
glutMainLoop();
}


/*滑鼠控制*/

void mouse(int button,int state,int x,int y)
{
printf("%d %d %d %d\n",button,state,x,y);
startX=x;
}
void motion(int x,int y)
{
printf("%d %d\n",x,y);
angleX=x-startX;
glutPostRedisplay();
}
void keyboard(unsigned char key, int x,int y)
{
printf("%c  %d %d\n",key,x,y);//xy座標 
     if(key=='a') angleX +=3;
     if(key=='b') angleX -=3;
     glutPostRedisplay();
}


/*加上y軸控制*/
void mouse(int button,int state,int x,int y)
{
printf("%d %d %d %d\n",button,state,x,y);
startX=x;
startY=y;
}
void motion(int x,int y)
{
printf("%d %d\n",x,y);
angleX+=x-startX; startX=x;
angleY+=y-startY; startY=y;
glutPostRedisplay();
}


/*完整版*/

#include <GL/glut.h>
#include <stdio.h>
#include <math.h>
float m[16]={1,0,0,0, 0,1,0,0 , 0,0,1,0, 0,0,0,1};
float angleX=0,angleY=0;
float startX=0,startY=0; 
void mouse(int button,int state,int x,int y)
{
printf("%d %d %d %d\n",button,state,x,y);
startX=x;
startY=y;
}
void motion(int x,int y)
{
printf("%d %d\n",x,y);
angleX=x-startX; startX=x;
angleY=y-startY; startY=y;
glutPostRedisplay();
}
void keyboard(unsigned char key, int x,int y)
{
printf("%c  %d %d\n",key,x,y);//xy座標 
     if(key=='a') angleX +=3;
     if(key=='b') angleX -=3;
     glutPostRedisplay();
}
void mylight()//打光 
{
const GLfloat light_position[] = { 2.0f, 5.0f, 0.0f, 0.0f };
glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_LIGHTING);
        glLightfv(GL_LIGHT0, GL_POSITION, light_position);
}
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
/* glRotatef(angleX,0,1,0);
glRotatef(angleY,1,0,0);
glutSolidTeapot(0.3);
*/
float dist=sqrt(angleX*angleX+angleY*angleY);
glRotatef(dist,-angleY,-angleX,0);
glMultMatrixf(m);
glGetFloatv(GL_MODELVIEW_MATRIX,m);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week10");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
mylight();
glutMainLoop();
}




2014年4月11日 星期五

timer 哆啦



#include <GL/glut.h>
#include "glm.h"
float angle=0;

void head()
{
glPushMatrix();
    glTranslatef(0,0.3,0);
    glColor3f(0,0,1);
    glutSolidSphere(0.3,30,30);
   
    glColor3f(1,1,1);
    glTranslatef(0,-0.1,0.1);
    glutSolidSphere(0.25,30,30);
    glPopMatrix();
}
void reye()
{
glPushMatrix();
    glTranslatef(0,0.3,0);
    glColor3f(1,1,1);
    glutSolidSphere(0.1,20,20);
   
    glColor3f(0,0,0);
    glTranslatef(0,0,0.1);
    glutSolidSphere(0.03,30,30);
   
    glPopMatrix();
 
}
void leye()
{
glPushMatrix();
    glTranslatef(0,0.3,0);
    glColor3f(1,1,1);
    glutSolidSphere(0.1,20,20);
   
    glColor3f(0,0,0);
    glTranslatef(0,0,0.1);
    glutSolidSphere(0.03,30,30);
   
    glPopMatrix();
 
}
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
     glPushMatrix();
      glRotatef(angle,0,1,0);
   
      head();
     
      glTranslatef(0.14,0,0.25);
      reye();
     
      glTranslatef(-0.25,0,0.03);
      leye();
     
      glPushMatrix();
    glTranslatef(0,-0.3,0);
    glColor3f(1,1,1);
    // glutSolidSphere(0.2,30,30);
      glPopMatrix();
     
     glPopMatrix();
   
     glutSwapBuffers();
     }
void timer(int t)
{
glutTimerFunc(20,timer,t+1);//停兩秒再開始
angle+=1;
glutPostRedisplay();
}

const GLfloat light_ambient[]  = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[]  = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, -5.0f, 0.0f };
int main()
{
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week08");
glutDisplayFunc(display);
//glutIdleFunc(idle);
/*timer*/
glutTimerFunc(2000,timer,1);
glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_LIGHTING);

glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_diffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);

glutMainLoop();
}