2019年4月11日 星期四

電腦圖學

任務一:
(主題:貼圖Texture)














實作老師給的檔案.

任務二:
(範例:Texture.exe)

#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

#include <stdlib.h>
glPushMatrix();
    glRoatatef(angle,x,y,z);
    glTranslated(x,y,z);
    glScalef(x,y,z);
    glBegin(GL_POLYGON);
    glColor3f(r,g,b);
    glTexCoord2f(tx,ty);
    glNormal3f(nx,ny,nz);
    glVertex3f(x,y,z);
    glEnd();
glPopMatrix();

任務三:
(實作:OpenCV)
下載OpenCV

程式碼:
+#include <GL/glut.h>
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("06160451 week08");
    glutDisplayFunc(display);
    glutMainLoop();
}


完成圖
:










任務四:
(實作:OpenCV+OpenGL貼圖)

使用openCV讓小畫家的圖顯示出來.

下載freeglut,將自己畫的圖片放到bin底下.

寫下程式碼:
#include <GL/glut.h>
#include<opencv/highgui.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glutSolidTeapot(0.3);
    glutSwapBuffers();
}
int main(int argc,char**argv)
{
    IplImage*img=cvLoadImage("earth.png");
    cvShowImage("opencv Window",img);
    cvWaitKey(0);
    glutInit( &argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("06160451 week08");
    glutDisplayFunc(display);
    glutMainLoop();
}

右鍵點按左側檔名 ->build options->設定資料










































最終得到結果:











任務五:
(期中考:10行OpenGL程式)

沒有留言:

張貼留言