2019年3月22日 星期五

幫我稱10秒!_week05

1.學習控制光的改變


pos(光的位置)
Ka:Amblient light (無處不在的光)

Kd:Diffuse light (散射光,打在物品上的)

Ks:Specular light (拋光)

Ke:emission(自體發光)


2.自己動手改程式讓茶壺看起來是3D的

#include <GL/glut.h> //以下程式控制顏色 const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.1f, 1.0f }; const GLfloat light_diffuse[] = { 0.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, 2.0f, 2.0f, 1.0f }; const GLfloat mat_ambient[] = { 0.17f, 0.01f, 0.01f, 0.55f }; const GLfloat mat_diffuse[] = { 0.61f, 0.04f, 0.04f, 0.55f }; const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f }; const GLfloat high_shininess[] = { 77.0f }; //以上 float angle=0; void display() { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix();//備份矩陣,保護程式 glRotatef(angle,0,1,0);//控制旋轉 glutSolidTeapot(0.3); angle=angle+3;//旋轉速度 glutSwapBuffers(); glPopMatrix();//還原矩陣 } int main(int argc,char ** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH); glutCreateWindow("第N個程式"); glutDisplayFunc(display); glutIdleFunc(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(); }
結果如下



沒有留言:

張貼留言