顯示具有 04160453_蔡明諺 標籤的文章。 顯示所有文章
顯示具有 04160453_蔡明諺 標籤的文章。 顯示所有文章

2019年5月23日 星期四

Week14-04160453

1.計時器

先用出茶壺
#include <GL/glut.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glutSolidTeapot( 0.3 );

    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(500,500);///變大了
    glutCreateWindow("week 14 timer");

    glutDisplayFunc(display);
    glutMainLoop();
}

用timer做出定時放P聲

#include <GL/glut.h>
#include <mmsystem.h>///Now (1)
#include <stdio.h>///printf()
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glutSolidTeapot( 0.3 );
    glutSwapBuffers();
}
void timer(int t)///NOW timer!!!!
{
    glutTimerFunc(1000, timer, t+1 );///NOW timer!!!! 起床要播下一個鬧鐘
    printf("timer(t) 的 t是 %d\n", t);///順便印一下現在的t是多少
    PlaySoundA("fart.wav", NULL, SND_ASYNC);///Now (2) ///NOW timer!!!!
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(500,500);
    glutCreateWindow("week 14 timer");

    glutDisplayFunc(display);
    glutTimerFunc(3000, timer, 0);///NOW timer!!!!

    glutMainLoop();
}

2.內插法

#include <GL/glut.h>
#include <mmsystem.h>
float angle=0;
float nowX=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        
        glTranslatef(nowX, 0, 0);
        glutSolidTeapot( 0.3 );
    glPopMatrix();
    glutSwapBuffers();
}
void timer(int t)///NOW timer!!!!
{
    /// 1000 ms = 1 sec,  30 ms = 1/33 sec , 33 fps
    glutTimerFunc(30, timer, t+1 );///NOW timer!!!! 起床要播下一個鬧鐘
    float alpha = (t%33) / 33.0;///NOW2 alpha 內插
    nowX = alpha* 1 + (1-alpha)* -1 ;///NOW2

    angle += 1;
    glutPostRedisplay();///系統重繪畫面
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(500,500);
    glutCreateWindow("week 14 timer");

    glutDisplayFunc(display);
    glutTimerFunc(1000, timer, 0);///NOW timer!!!!

    glutMainLoop();
}





2019年5月16日 星期四

Week13-04160453

1.檔案

1)codeblock>File>New>Project>Console application
2)
#include <stdio.h>
FILE * fout=NULL;
int main()
{
    fout = fopen("filename.txt","w+");
    for(int i=0;i<20;i++)
    {
        fprintf(fout,"Hello World\n");
    }
}
結果會在城市資料夾新增一個txt文字檔

3)
#include <stdio.h>
FILE * fout2=NULL;
FILE * fin3=NULL;
float angle[20];
int main()
{
    fout2 = fopen("motion.txt","w+");
    for(int i=0;i<20;i++)
    {
        fprintf(fout2,"%.2f\n",angle[i]);
    }
}

2.關節擺動作

#include <GL/glut.h>
float angle[20];///NOW2
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glColor3f(1, 1, 1);///white
        glutSolidTeapot( 0.3 );///body
        glPushMatrix();
            glTranslatef(0.2, 0, 0);///NOW2 (3)掛上去
            glRotatef(angle[1], 0,0,1);///NOW2 ///(2)旋轉
            glTranslatef(0.15, 0, 0);///NOW2 (1)旋轉中心
            glColor3f(0, 1, 1);///red
            glutSolidTeapot( 0.2 );///right arm
        glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();
}
int oldX=0;
void mouse(int button, int state, int x, int y)
{
    oldX = x;
}
void motion(int x, int y)
{
    angle[1] += x-oldX;
    oldX = x;
    display();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    ///glutInitWindowSize(600,600);///可以開大一點的window
    glutCreateWindow("Week 13 angle motion file");
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutDisplayFunc(display);

    glutMainLoop();
}

3.擺動作

#include <GL/glut.h>
float angle[20];
int angleID=1;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glColor3f(1, 1, 1);///white
        glutSolidTeapot( 0.3 );///body

        glPushMatrix();///右邊
            glTranslatef(0.2, 0, 0);(3)掛上去
            glRotatef(angle[1], 0,0,1); ///(2)旋轉
            glTranslatef(0.15, 0, 0);/// (1)旋轉中心
            glColor3f(1, 0, 0);///red
            glutSolidTeapot( 0.2 );///right arm
            glPushMatrix();
                glTranslatef(0.2, 0, 0); (3)掛上去
                glRotatef(angle[2], 0,0,1); ///(2)旋轉
                glTranslatef(0.15, 0, 0); (1)旋轉中心
                glColor3f(1, 0, 0);///red
                glutSolidTeapot( 0.2 );///right lower arm
            glPopMatrix();
        glPopMatrix();

        glPushMatrix();///左邊
            glTranslatef(-0.2, 0, 0); (3)掛上去
            glRotatef(angle[3], 0,0,1);///(2)旋轉
            glTranslatef(-0.15, 0, 0); (1)旋轉中心
            glColor3f(1, 0, 0);///red
            glutSolidTeapot( 0.2 );///right arm
            glPushMatrix();
                glTranslatef(-0.2, 0, 0);/// (3)掛上去
                glRotatef(angle[4], 0,0,1); ///(2)旋轉
                glTranslatef(-0.15, 0, 0);/// (1)旋轉中心
                glColor3f(1, 0, 0);///red
                glutSolidTeapot( 0.2 );///right lower arm
            glPopMatrix();
        glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();
}
int oldX=0;
void mouse(int button, int state, int x, int y)
{
    oldX = x;
}
#include <stdio.h>
void motion(int x, int y)
{
    angle[angleID] += x-oldX;
    oldX = x;
    for(int i=0;i<20;i++){
        printf(" %.2f ", angle[i]);
    }
    printf("\n");
    display();
}
void keyboard(unsigned char key, int x, int y)
{///NOW3
    if(key=='1') angleID=1;
    if(key=='2') angleID=2;
    if(key=='3') angleID=3;
    if(key=='4') angleID=4;
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    ///glutInitWindowSize(600,600);///可以開大一點的window
    glutCreateWindow("Week 13 angle motion file");
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutDisplayFunc(display);

    glutMainLoop();
}

4.讀錄檔

#include <GL/glut.h>
#include <stdio.h>///NOW_FILE (0)
float angle[20];
int angleID=1;
FILE * fout = NULL;///NOW_FILE (1)
FILE * fin = NULL;///NOW_FILE_READ (1)
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glColor3f(1, 1, 1);
        glutSolidTeapot( 0.3 );///body

        glPushMatrix();///右邊
            glTranslatef(0.2, 0, 0);/// (3)掛上去
            glRotatef(angle[1], 0,0,1);///(2)旋轉
            glTranslatef(0.15, 0, 0);/// (1)旋轉中心
            glColor3f(1, 0, 0);///red
            glutSolidTeapot( 0.2 );///right arm
            glPushMatrix();
                glTranslatef(0.2, 0, 0);/// (3)掛上去
                glRotatef(angle[2], 0,0,1); ///(2)旋轉
                glTranslatef(0.15, 0, 0);///(1)旋轉中心
                glColor3f(1, 0, 0);///red
                glutSolidTeapot( 0.2 );///right lower arm
            glPopMatrix();
        glPopMatrix();

        glPushMatrix();///左邊
            glTranslatef(-0.2, 0, 0);/// (3)掛上去
            glRotatef(angle[3], 0,0,1);///(2)旋轉
            glTranslatef(-0.15, 0, 0);/// (1)旋轉中心
            glColor3f(1, 0, 0);///red
            glutSolidTeapot( 0.2 );///right arm
            glPushMatrix();
                glTranslatef(-0.2, 0, 0);///(3)掛上去
                glRotatef(angle[4], 0,0,1);///(2)旋轉
                glTranslatef(-0.15, 0, 0);/// (1)旋轉中心
                glColor3f(1, 0, 0);///red
                glutSolidTeapot( 0.2 );///right lower arm
            glPopMatrix();
        glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();
}
int oldX=0;
void mouse(int button, int state, int x, int y)
{
    oldX = x;
}

void motion(int x, int y)
{
    angle[angleID] += x-oldX;
    oldX = x;
    if(fout == NULL) fout = fopen("motion.txt", "w+");///NOW_FILE (2)
    for(int i=0;i<20;i++){
        printf(" %.2f ", angle[i]);
        fprintf(fout, " %.2f ", angle[i]);///NOW_FILE
    }
    printf("\n");
    fprintf(fout, "\n");///NOW_FILE
    display();///NOW2
}
void keyboard(unsigned char key, int x, int y)
{///NOW3
    if(key=='1') angleID=1;
    if(key=='2') angleID=2;
    if(key=='3') angleID=3;
    if(key=='4') angleID=4;
    if(key=='w'){///NOW_FILE
        fout = fopen("motion.txt", "w+");///NOW_FILE (2)
    }
    if(key=='r'){
        if(fin==NULL) fin = fopen("motion.txt", "r");///NOW_FILE_READ (2)
        ///scanf("%d", &n);
        for(int i=0;i<20; i++){///NOW_FILE_READ
            fscanf(fin, "%f", &angle[i]);///NOW_FILE_READ
            printf(" %.2f ", angle[i]);///順便印出來看數字對不對
        }
    }
    glutPostRedisplay();很像///NOW_FILE_READ 和 display()
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("Week 13 angle motion file");
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutDisplayFunc(display);

    glutMainLoop();
}


先跑一次專案
然後再次跑的是喉按'r'可以呈現剛剛的動作


2019年5月2日 星期四

Week11-04160453

主題:階層,轉動,骨架

茶壺來當作身體與手臂

#include <GL/glut.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glColor3f(255,255,255);///白色
    glutSolidTeapot( 0.3 );///身體
    ///右邊的手臂
    glPushMatrix();
        glTranslatef(0.2, 0,0 );///(3)往右移動, 掛在身體的右肩
        glRotatef(angle, 0,0,1);///(2)旋轉
        glTranslatef(0.28, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸

        glColor3f(255,0,0);///紅色
        glutSolidTeapot( 0.2 );///手臂
    glPopMatrix();

    glutSwapBuffers();
    angle++;
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week11 TRT");
    glutIdleFunc(display);///Now!!!!
    glutDisplayFunc(display);

    glutMainLoop();
}

#include <GL/glut.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glColor3f(255,255,255);///白色
    glutSolidTeapot( 0.3 );///身體

    glPushMatrix();///右邊的手臂
        glTranslatef(0.2, 0,0 );///(3)往右移動, 掛在身體的右肩
        glRotatef(angle, 0,0,1);///(2)旋轉
        glTranslatef(0.28, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸

        glColor3f(255,0,0);///紅色
        glutSolidTeapot( 0.2 );///上手臂

        glPushMatrix();///右下手臂
            glTranslatef(0.2, 0,0 );///(3)往右移動, 掛在身體的右肘
            glRotatef(angle, 0,0,1);///(2)旋轉
            glTranslatef(0.28, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸

            glColor3f(255,0,0);///紅色
            glutSolidTeapot( 0.2 );///上手臂
        glPopMatrix();
    glPopMatrix();


    glPushMatrix();///左邊的手臂
        glTranslatef(-0.2, 0,0 );///(3)往左移動, 掛在身體的左肩
        glRotatef(angle, 0,0,1);///(2)旋轉
        glTranslatef(-0.28, 0,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸

        glColor3f(255,0,0);///紅色
        glutSolidTeapot( 0.2 );///上手臂

        glPushMatrix();///左下手臂
            glTranslatef(-0.2, 0,0 );
            glRotatef(angle, 0,0,1);
            glTranslatef(-0.28, 0,0);

            glColor3f(255,0,0);
            glutSolidTeapot( 0.2 );
        glPopMatrix();
    glPopMatrix();

    glutSwapBuffers();
    angle++;
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week11 TRT");
    glutIdleFunc(display);///Now!!!!
    glutDisplayFunc(display);

    glutMainLoop();
}

利用滑鼠控制

#include <GL/glut.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glColor3f(255,255,255);///白色
    glutSolidTeapot( 0.3 );///身體

    glPushMatrix();///右邊的手臂
        glTranslatef(0.2, 0,0 );///(3)往右移動, 掛在身體的右肩
        glRotatef(angle, 0,0,1);///(2)旋轉
        glTranslatef(0.2, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸

        glColor3f(0,255,0);///綠色
        glutSolidCube( 0.3 );///上手臂

        glPushMatrix();///右下手臂
            glTranslatef(0.1, 0,0 );///(3)往右移動, 掛在身體的右肘
            glRotatef(angle, 0,0,1);///(2)旋轉
            glTranslatef(0.2, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸

            glColor3f(255,0,0);///紅色
            glutSolidCube( 0.3 );///上手臂
        glPopMatrix();
    glPopMatrix();


    glPushMatrix();///左邊的手臂
        glTranslatef(-0.2, 0,0 );///(3)往左移動, 掛在身體的左肩
        glRotatef(-angle, 0,0,1);///(2)旋轉
        glTranslatef(-0.2, 0,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸

        glColor3f(0,0,255);///藍色
        glutSolidCube( 0.3 );///上手臂

        glPushMatrix();///左下手臂
            glTranslatef(-0.1, 0,0 );///(3)往左移動, 掛在身體的左肘
            glRotatef(-angle, 0,0,1);///(2)旋轉
            glTranslatef(-0.2, 0,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸

            glColor3f(255,0,0);///紅色
            glutSolidCube( 0.3 );///上手臂
        glPopMatrix();
    glPopMatrix();

    glutSwapBuffers();
    ///angle++;
}
void motion (int x, int y)
{
    angle= x; ///now2!!
    display(); /// now2!!
}

int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week11 TRT");
    glutIdleFunc(display);///Now!!!!
    glutDisplayFunc(display);
    glutMotionFunc(motion);///now2!!!

    glutMainLoop();
}

利用鍵盤控制
#include <GL/glut.h>
float angle[20];  ///now3
int jointID=1;  ///now3!!! ///1,2,3,4
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glColor3f(255,255,255);///白色
    glutSolidTeapot( 0.3 );///身體

    glPushMatrix();///右邊的手臂
        glTranslatef(0.2, 0,0 );///(3)往右移動, 掛在身體的右肩
        glRotatef(angle[1], 0,0,1);///(2)旋轉
        glTranslatef(0.2, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸

        glColor3f(0,255,0);///綠色
        glutSolidCube( 0.25 );///上手臂

        glPushMatrix();///右下手臂
            glTranslatef(0.05, 0,0 );///(3)往右移動, 掛在身體的右肘
            glRotatef(angle[2], 0,0,1);///(2)旋轉
            glTranslatef(0.1, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸

            glColor3f(255,0,0);///紅色
             glRotatef(90,0,0.5,0);
             glutSolidCone(0.1,0.5,30,30);///下手臂
        glPopMatrix();
    glPopMatrix();


    glPushMatrix();///左邊的手臂
        glTranslatef(-0.2, 0,0 );///(3)往左移動, 掛在身體的左肩
        glRotatef(-angle[3], 0,0,1);///(2)旋轉
        glTranslatef(-0.2, 0,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸

        glColor3f(0,0,255);///藍色
        glutSolidCube( 0.25 );///上手臂

        glPushMatrix();///左下手臂
            glTranslatef(-0.05, 0,0 );///(3)往左移動, 掛在身體的左肘
            glRotatef(-angle[4], 0,0,1);///(2)旋轉
            glTranslatef(-0.1, 0,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸

            glColor3f(255,0,0);///紅色
             glRotatef(-90,0,0.5,0);
             glutSolidCone(0.1,0.5,30,30);///下手臂
        glPopMatrix();
    glPopMatrix();

    glutSwapBuffers();
    ///angle++;
}
void motion (int x, int y)///now2!!!
{
    angle[jointID] = x; ///now3!!!
 
  display(); /// now2!!
}
void keyboard(unsigned char key,int x, int y)///now3!!!
{
    if(key=='1') jointID=1; ///NOW3!!!
    if(key=='2') jointID=2; ///NOW3!!!
    if(key=='3') jointID=3; ///NOW3!!!
    if(key=='4') jointID=4; ///NOW3!!!


}


int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week11 TRT");
    glutIdleFunc(display);///Now!!!!
    glutDisplayFunc(display);
    glutMotionFunc(motion);///now2!!!
    glutKeyboardFunc(keyboard);///NOW3!!!

    glutMainLoop();
}

2019年4月25日 星期四

Week10_04160453

TRT旋轉


#include <GL/glut.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslated(0,0.5,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glPushMatrix();
        glTranslatef(0.50,0.625,0);///三角形位置
        glRotatef(angle,0,0,1);
        glTranslatef(0.6,0,0);///旋轉中心

        glRotatef(-90,0,1,0);
        glutSolidCone(0.2,0.6,30,30);///三角形
    glPopMatrix();
    glutSwapBuffers();
}
void motion(int x,int y)
{
    angle = x;
    display();
}
int main(int argc, char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week10");

    glutDisplayFunc(display);
    glutMotionFunc(motion);///滑鼠動作

    glutMainLoop();
}


2019年4月11日 星期四

Week08-04160453

1.主題;貼圖Texture

下載windows3個檔案打開Texture檔案

2.實作:OpenCV

去網站:https://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.1/

並且安裝好


#include <stdio.h>
#include <GL/glut.h>
#include <opencv/highgui.h>

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

    glutSolidTeapot(0.3);
    glutSwapBuffers();
}
int main(int argc,char**argv)
{
    IplImage*img=cvLoadImage("earth.png");
    cvShowImage("opencv Window",img);
    cvWaitKey(0);

    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week08");

    glutDisplayFunc(display);
    glutMainLoop();
}

右鍵點Build options
Search drectones>Add>C:\OpenCV2.1\include
Link>Add>C:OpenCV2.1\lib
Linker settings>Add>cv210      
                                   cxcore210
                                   highgui210




2019年3月28日 星期四

Week06-04160453

1.主題:打光 Part 1

去網站http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/下載[data][win32]glut32.dll 這三個檔案


解壓縮並打開Light&Matrial

2.茶壺打光

先欻茶壺

#include <GL/glut.h>


void display()
{
    glClear(GL_COLOR_BUFFER_BIT |  GL_DEPTH_BUFFER_BIT);
    glutSolidTeapot(0.3);
    glutSwapBuffers();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week06");
    glutDisplayFunc(display);

    glutMainLoop();
}



#include <GL/glut.h>


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 };

const GLfloat mat_ambient[]    = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[]    = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[]   = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };

void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glutSolidTeapot(0.3);
    glutSwapBuffers();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week06");
    glutDisplayFunc(display);

    glClearColor(1,1,1,1);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

    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);

    glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);

    glutMainLoop();
}



完成

3.模型