先到https://jsyeh.org/3dcg10/ 下載 data 與 win32 檔案 解壓縮後
把data資料夾解壓縮在windows資料夾裡
並開啟今天的程式Texture.exe
練習調整裡面的座標數值
重要
練習OpenGL圖學期中考的程式
glPushMatrix ( );
glTranslatef (x , y ,z );
glRotatef (angle ,x ,y, z );
glScalef (x ,y ,z);
glBegin (GL_POLYGON);
glColor3f ( r , g , b );
glNormal3f ( nx , ny , nz);
glTexCoord2f ( tx , ty );
glVertex3f ( x , y , z );
glEnd ( );
glPopMatrix ( );
全都搞懂就不用死背了!!!
打開小葉老師資料夾中的老師建議使用的 OpenCV2.1 安裝
勾選 ADD PATH 裝在預設的資料夾
接著重開codeblocks
到 settings - compiler - Search directories
Compiler C:\OpenCV2.1\include 和 LinkerC:\OpenCV2.1\lib
Linker settings
新增
cv210
excore210
highgui210
使用老師的GITHUB https://gist.github.com/jsyeh/ 找my texture
複製下面的程式碼
#include <opencv/highgui.h> ///使用 OpenCV 2.1 比較簡單, 只要用 High GUI 即可
#include <opencv/cv.h>
#include <GL/glut.h>
int myTexture(char * filename)
{
IplImage * img = cvLoadImage(filename); ///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()
{
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("week09 texture");
glutDisplayFunc(display);
myTexture("earth.jpg");
glutMainLoop();
}
沒有留言:
張貼留言