(1)作業Q&A
(2)複習:貼圖
(3)複習:打光
(4)複習:模型
一定要下載第二個或第三個
之後要去網站下載Download freeglut 3.0.0 for MinGW
#include <GL/glut.h>
#include <opencv/highgui.h> ///OpenCV High GUI讀圖
///程式碼是對的, 但是沒有設定好include, lib, bin
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidTeapot( 0.3 );
glutSwapBuffers();
}
GLuint id;
void myInit()
{
glEnable(GL_TEXTURE_2D);
IplImage * img = cvLoadImage("pig.jpg");
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);
}
int main(int argc, char **argv)
{
///IplImage * img = cvLoadImage("pig.jpg");
///cvShowImage("opencv", img);
///cvWaitKey(0);///等你按按鍵
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
glutCreateWindow("GLUT");///之後
///建好GLUT視窗,可以開始準備 3D 貼圖 (要在create...MainLoop才能建貼圖)
myInit();///我們的貼圖在這裡
glutDisplayFunc(display);
glutMainLoop();///之前
}
修正紅綠問題
#include <GL/glut.h>
#include <opencv/highgui.h> ///OpenCV High GUI讀圖
///程式碼是對的, 但是沒有設定好include, lib, bin
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidTeapot( 0.3 );
glutSwapBuffers();
}
GLuint id;
void myInit()
{
glEnable(GL_TEXTURE_2D);
IplImage * img = cvLoadImage("pig.jpg");
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);
}
int main(int argc, char **argv)
{
///IplImage * img = cvLoadImage("pig.jpg");
///cvShowImage("opencv", img);
///cvWaitKey(0);///等你按按鍵
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
glutCreateWindow("GLUT");///之後
///建好GLUT視窗,可以開始準備 3D 貼圖 (要在create...MainLoop才能建貼圖)
myInit();///我們的貼圖在這裡
glutDisplayFunc(display);
glutMainLoop();///之前
}
讓貼圖轉動
#include <GL/glut.h>
#include <opencv/highgui.h> ///OpenCV High GUI讀圖 ///貼圖需要它
#include <opencv/cv.h> ///OpenCV cvCvtColor() to convert color///貼圖需要它
///程式碼是對的, 但是沒有設定好include, lib, bin
GLuint id1, id2, id3;///NOW2 ///貼圖需要它
float a=0;
void display()
{
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, id3);///id3 for rotating square
glPushMatrix();
glTranslatef(0.5, 0.5, 0);
glRotatef(a++, 0, 0, 1);
glScalef(0.3, 0.3, 0.3);
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();
glPopMatrix();
glBindTexture(GL_TEXTURE_2D, id2);///id2 for teapot
glutSolidTeapot( 0.3 );
glutSwapBuffers();
}
///void myInit()
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;///貼圖需要它
}
int main(int argc, char **argv)
{
///IplImage * img = cvLoadImage("marvel.jpg");
///cvShowImage("opencv", img);
///cvWaitKey(0);///等你按按鍵
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
glutCreateWindow("GLUT");///之後
///建好GLUT視窗,可以開始準備 3D 貼圖 (要在create...MainLoop才能建貼圖)
id1 = myTexture("pig.jpg"); ///myInit();///我們的貼圖在這裡 ///貼圖需要它
id2 = myTexture("tea.jpg");
id3 = myTexture("cow.jpg");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();///之前
}
#include <opencv/highgui.h> ///OpenCV High GUI讀圖 ///貼圖需要它
#include <opencv/cv.h> ///OpenCV cvCvtColor() to convert color///貼圖需要它
///程式碼是對的, 但是沒有設定好include, lib, bin
GLuint id1, id2, id3;///NOW2 ///貼圖需要它
float a=0;
void display()
{
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, id3);///id3 for rotating square
glPushMatrix();
glTranslatef(0.5, 0.5, 0);
glRotatef(a++, 0, 0, 1);
glScalef(0.3, 0.3, 0.3);
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();
glPopMatrix();
glBindTexture(GL_TEXTURE_2D, id2);///id2 for teapot
glutSolidTeapot( 0.3 );
glutSwapBuffers();
}
///void myInit()
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;///貼圖需要它
}
int main(int argc, char **argv)
{
///IplImage * img = cvLoadImage("marvel.jpg");
///cvShowImage("opencv", img);
///cvWaitKey(0);///等你按按鍵
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
glutCreateWindow("GLUT");///之後
///建好GLUT視窗,可以開始準備 3D 貼圖 (要在create...MainLoop才能建貼圖)
id1 = myTexture("pig.jpg"); ///myInit();///我們的貼圖在這裡 ///貼圖需要它
id2 = myTexture("tea.jpg");
id3 = myTexture("cow.jpg");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();///之前
}
沒有留言:
張貼留言