2. 範例: Texture.exe
1. 點進去小葉的網頁: http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
2. 下載 Example裏的 win32, glut32.dll, data, source
3. 解壓縮到下載 (但先不要把souces .zip解壓縮)
4. 把已解壓的 data 資料夾拉到windows裏
5. 把已解壓的 glut32.dll 資料夾拉到windows裏
6. 打開 Texture.exe
紅色: 角的位置
藍色: 不能變, 會壞掉(改圖的框)
藍色: 不能變, 會壞掉(改圖的框)


3. 實作: OpenCV
1. 下載OpenCV (裝好才能開CodeBlocks)
1. 去 https://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.1/
2. 下載 OpenCV-2.1.0-win32-vs2008.exe
3. 要選 "Add OpenCV to the system PATH for all users"

4. 要放的路徑: C:\OpenCV2.1

2. 先載入freeglut (跟第一週一樣)
1. Google search "freeglut windows"2. 從Transmission Zero 下載 "freeglut 3.0.0 MinGW Package"
3. 解壓縮後放到桌面
4. 在lib複製一個"libfreeglut.a"命名為"libglut32.a"
5. CodeBlocks 開
6. File -> New -> Project -> GLUT Project
7. 把location改成"C:\Users\user\Desktop\freeglut"
3. 先把茶壺的程式碼打到main
#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("06160912");
glutDisplayFunc(display);
glutMainLoop();
}
4. 加貼圖的程式碼
#include <opencv/highgui.h> ///貼圖需要
IplImage * img=cvLoadImage("earth.jpg");///貼圖需要
cvShowImage("opencv Window", img);///貼圖需要
cvWaitKey(0);///貼圖需要
IplImage * img=cvLoadImage("earth.jpg");///貼圖需要
cvShowImage("opencv Window", img);///貼圖需要
cvWaitKey(0);///貼圖需要
5. 結果
#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.jpg");///貼圖需要
cvShowImage("opencv Window", img);///貼圖需要
cvWaitKey(0);///貼圖需要
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("06160912");
glutDisplayFunc(display);
glutMainLoop();
}
#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.jpg");///貼圖需要
cvShowImage("opencv Window", img);///貼圖需要
cvWaitKey(0);///貼圖需要
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("06160912");
glutDisplayFunc(display);
glutMainLoop();
}
6. 找一張Earth的圖
7. 放到freeglut裏的bin
8. 完成以下設定





4. 期中考: 10行OpenGL程式
glPushMatrix(); ///備份距陣
glRotatef(angle,x,y,z);///旋轉
glTranslatef(x,y,z);///移動
glScalef(x,y,z);///縮放
glBegin(GL_POLYGON);///開始畫
glColor3f(r,g,b);///顏色, 色彩
glTexCoord2f(tx,ty);///貼圖座標
glNormal3f(nx,ny,nz);///打光的法向量
glVertex3f(x,y,z);///頂點
glEnd();
glPopMatrix();///還原矩陣
沒有留言:
張貼留言