~texture~
build option裡開始改,載opencv2.1版本。
#include <opencv/highgui.h>
int main()
{
IplImage * img =cvLoadImage("image.jpg");
cvShowImage("opencv Window",img);
cvWaitKey(0);
}
compiler/include///link/lib
#include <GL/glut.h>
#include <opencv/highgui.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);//滑鼠移動
/*glPushMatrix();
glTranslatef((x-150)/150.0,-(y-150)/150.0,0);//以視窗內座標決定移動位置
//glColor3f(0.8,0.6,0);*/
glutSolidTeapot(0.3);
// glPopMatrix();
glutSwapBuffers();
}
/*void motion(int nowx,int nowy)
{
x=nowx; y=nowy;//滑鼠移動
display();
}*/
int main(int argc,char ** argv)
{
IplImage * img =cvLoadImage("earth.jpg");
cvShowImage("another Window",img);
cvWaitKey(0);
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week08 texture 06160095");
glutDisplayFunc(display);
//glutMotionFunc(motion);//執行
glutMainLoop();
}
#include <opencv/highgui.h> ///for cvLoadImage()
#include <opencv/cv.h> ///for cvCvtColor()
#include <GL/glut.h> ///3D glut
#include <stdio.h>
GLUquadric * quad;
GLuint id;
float angle=0;
void display()
{ glEnable(GL_DEPTH_TEST); ///要啟動 Detph Test 深度值的測試,3D顯示才正確
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///自動轉很帥
glRotatef(90, 1,0,0);
glRotatef(angle, 0,0,1);///自動轉很帥
gluQuadricTexture(quad, 1);
gluSphere(quad, 1, 30, 30);///glutSolidTeapot(0.3);
glPopMatrix();///自動轉很帥
glFlush();
}
void timer(int t)
{ glutTimerFunc(20, timer, 0);/// 1000 msec 50fps:20msec
angle+=1;///自動轉很帥
glutPostRedisplay();
}
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 myInit()
{ quad = gluNewQuadric();
id = myTexture("image.png");
}
int main(int argc, char**argv)
{ glutInit(&argc, argv);
glutCreateWindow("3D");
glutDisplayFunc(display); ///顯示
glutTimerFunc(0, timer, 0);
myInit(); ///我的 init 初始化 把貼圖準備好 前面OpenCV 2行, 後面 OpenGL 9行
glutMainLoop();
}
沒有留言:
張貼留言