1.先下載老師給的data,win32,glut32.dll
http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
2..將window.zip解壓縮到window資料夾,複製glut32.dll到window資料夾裡
並打開Light Material.exe執行檔
(可以按右鍵改變圖案)
3.先開啟freeglut windows網站然後下載
Download freeglut 3.0.0 for MinGW
然後解壓縮然後打開lib資料夾,複
製貼上libfreeglut.a,把複製的改名為libglut32.a
製貼上libfreeglut.a,把複製的改名為libglut32.a
4.打開codeblack先建一個glut然後開啟執行
5.按 - 可以讓它變尖 , 按 + 可以讓它變圓
→把茶壺打光←
7.先把本來的程式碼複製到記事本(等等需要用到)
然後刪掉程式碼
8.把之前水壺的程式碼複製貼上
9.然後把本來的程式碼的其中兩段複製貼上
#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 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(); ///交換buffer顯示
}
int main(int argc, char**argv)
{
glutInit(&argc, argv); ///初始化GLUT功能Init是初始化
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
///開機有深度不會閃爍GLUT_DEPTH ->可以用出3D
glutCreateWindow("我是蘇珺心的第一個程式"); ///顯示一個視窗
glutDisplayFunc(display); ///呼叫上面的display
glClearColor(1,1,1,1);(改背景顏色)
/* (如果把glClearColor(1,1,1,1);改成glClearColor(1,0,0,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(); ///迴圈
}
10.讓水壺自動旋轉
#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 };
float angle=0; ///新加的
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );///清畫面
glPushMatrix(); ///新加的
glRotated(angle,0,1,0); ///新加的
glutSolidTeapot(0.3); ///新加的
glPopMatrix(); ///新加的
angle++; ///新加的
glutSwapBuffers(); ///交換buffer顯示
}
int main(int argc, char**argv)
{
glutInit(&argc, argv); ///初始化GLUT功能Init是初始化
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
///開機有深度不會閃爍GLUT_DEPTH ->可以用出3D
glutCreateWindow("我是蘇珺心的第一個程式"); ///顯示一個視窗
glutDisplayFunc(display); ///呼叫上面的display
glutIdleFunc(display); ///新加的
glClearColor(1,0,0,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(); ///迴圈
}
(會一直自動旋轉)
沒有留言:
張貼留言