( 1 ) 作業 Q & A
( 2 ) 複習 : 貼圖
( 3 ) 複習 : 打光
( 4 ) 複習 : 模型
----------------------------------------------------------
貼圖基礎設定:
include 2個
#include <opencv/highgui.h> ///OpenCV High GUI讀圖
#include <opencv/cv.h> ///OpenCV cvCvtColor() to convert color
GLuint id1, id2;///NOW2 幾個圖檔就幾個變數
在模型上面加貼圖
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D, id1);///id1 for background
glBegin(GL_POLYGON);
glTexCoord2f(0, 0); glVertex3f(-1, +1, 0);
glTexCoord2f(0, 1); glVertex3f(-1, -1, 0);
glTexCoord2f(1, 1); glVertex3f(+1, -1, 0);
glTexCoord2f(1, 0); glVertex3f(+1, +1, 0);
glEnd();
glBindTexture(GL_TEXTURE_2D, id2);///id2 for teapot
glutSolidTeapot( 0.3 );
glutSwapBuffers();
}
加背景
GLuint myTexture(char * filename)
{
IplImage * img = cvLoadImage(filename); ///NOW OpenCV
cvCvtColor(img, img, CV_BGR2RGB);///convert color ///NOW OpenCV
GLuint id;
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &id );
glBindTexture(GL_TEXTURE_2D, id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
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;
}
沒有留言:
張貼留言