2022年4月26日 星期二

獻祭肝臟的電腦圖學課堂筆記_week10

window、freeglut、data、source.....

1.1 opencv(like last week)

1.2 copy last week code


#include <GL/glut.h>
#include <opencv/highgui.h> ///使用 OpenCV 2.1 比較簡單, 只要用 High GUI 即可
#include <opencv/cv.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.6);
    glutSwapBuffers();
}

int main(int argc ,char** argv)
{
    glutInit( &argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week09 texture");


    glutDisplayFunc(display);
    myTexture("724425.png");

    glutMainLoop();
}

2.修改opencv設定

Settings->Compiler
在Search directions->Compiler加入C:\OpenCV2.1\Include
再到Search directions->Linker加入C:\OpenCV2.1\lib
到LinkerSettins加入cv210,cxcore210,highgui210
3.修改圖片位置(查看Build log裡面的workplace)
4.執行結果


Step02:
1.display()加入以下程式:
Begin(GL_POLYGON);
            glTexCoord2f(0,1);glVertex2f(-1,-1);
            glTexCoord2f(1,1);glVertex2f(+1,-1);
            glTexCoord2f(1,0);glVertex2f(+1,+1);
            glTexCoord2f(0,0);glVertex2f(-1,+1);
glEnd();

2.加入GLUquadric *sphere=NULL;///指標,只到二次曲面
3.在display()加入
gluQuadricTexture(sphere,1);
gluSphere(sphere,1,30,30);
4.在main()加入
sphere=gluNewQuadric();
5.執行結果


Step03:
1.寫入float angle=0;
2.在display()寫入
glPushMatrix();
    glRotatef(angle,0,0,1);
    gluSphere(sphere,1,30,30);
glPopMatrix();
angle+=0.1;
3.在main()加入
glutIdleFunc(display);
4.執行結果


5.在display()加入
glRotatef(90,1,0,0);
6.在main()加入
glEnable(GL_DEPTH_TEST);///
7.執行

沒有留言:

張貼留言

VERY BEAUTIFUL, VERY POWERFUL

一.     一樣先安裝且設定好freeglut,OpecCV, 開啟CodeBlocks建立新專案 week11_gundam,                 把 MyGundam.zip下載解壓縮後的data資料夾放到freeglut/bin裡面 把week09_openc...