今天上的東西是利用程式碼給物件上反光材質及打光
上圖程式中 ka、kd、ks分別代表的是三種光源
分別是
ambient light 無處不在的光
diffuse light 散射光
specular light 拋光
今天有另外教學打光的程式碼以及其定義如何打
{定義}
const GLfloat light_ambient[] = { 1.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 2.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 2.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[] = { 0.73f, 0.63f, 0.63f, 0.55f };
const GLfloat high_shininess[] = { 77.0f };
{背景}
glClearColor(1,1,1,1);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
{呼叫光源及材質應用到物件上}
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( );
{控制選轉}
glRotatef(x,0,1,0);
{旋轉函式}
glutIdleFunc(display);
下課了...應該吧
想吃丹丹漢堡
好 好餓
小葉老師的英文教室
Material/Lighting 打光
position 位置
ambient light 無處不在的光
diffuse light 散射光
specular light 拋光
沒有留言:
張貼留言