到 jsyeh.org/3dcg10 下載 win32、data、source
解壓縮win32跟data資料夾,再把win裡面的Texture.exe打開並理解貼圖座標及頂點的函式
二.
到moodle的上課用軟體下載OpenCV2.1,安裝時請點選第二項[Add OpenCV to the systemPAYH for all user ]
三.
下載後codeblocks重開,建立一個新檔案,命名為week09_opencv.cpp,把以下程式打上去
///
```C++
#include <opencv/highgui.h>//使用opencv外掛
int main ()
{
IplImage * img = cvLoadImage("檔名.jpg"); //讀圖
cvShowImage("week09",ing) //秀圖
cvWaitKey(0); //等待任意鍵繼續
}
///
然後打開Seetings -> Compiler ->Search directories -> Compiler -> Add目錄: c:\OpenCV2.1\include
Seetings -> Compiler ->Search directories -> Linker -> Add目錄: c:\OpenCV2.1\lib
Seetings -> Compiler ->Linker Settings -> Linker -> Add cv210、cxcore210、highgui210
四.(結合OpenCV跟GLUT)
到moodle下載glut檔案且解壓縮到桌面,在lib裡面複製(libfreeglut.a)成libglut32.a
在新增一個glut專案,命名為week09_texrure,
圖檔記得要放在C:\Users\sean\桌面\freeglut\bin
///
#include <GL/glut.h>
#include <opencv/highgui.h>
void myTexture()
{
IplImage * img = cvLoadImage("123.jpg"); //讀圖
cvShowImage("week09",img); //秀圖
///cvWaitKey(0); 可以不用寫因為會有glutMainLoop()卡住
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week09 texture");
glutDisplayFunc(display);
myTexture();
glutMainLoop();
}
///
最後在更改一下程式,就可以把圖片貼到茶壺上
///
#include <opencv/highgui.h> ///使用 OpenCV 2.1 比較簡單, 只要用 High GUI 即可
#include <opencv/cv.h>
#include <GL/glut.h>
int myTexture(char * week09_opencv)
{
IplImage * img = cvLoadImage(week09_opencv); ///OpenCV讀圖
cvCvtColor(img,img, CV_BGR2RGB); ///OpenCV轉色彩 (需要cv.h)
glEnable(GL_TEXTURE_2D); ///1. 開啟貼圖功能
GLuint id; ///準備一個 unsigned int 整數, 叫 貼圖ID
glGenTextures(1, &id); /// 產生Generate 貼圖ID
glBindTexture(GL_TEXTURE_2D, id); ///綁定bind 貼圖ID
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); /// 貼圖參數, 超過包裝的範圖T, 就重覆貼圖
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); /// 貼圖參數, 超過包裝的範圖S, 就重覆貼圖
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); /// 貼圖參數, 放大時的內插, 用最近點
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); /// 貼圖參數, 縮小時的內插, 用最近點
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img->width, img->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img->imageData);
return id;
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week09 texture");
glutDisplayFunc(display);
glutMainLoop();
}
///




沒有留言:
張貼留言