2019年4月11日 星期四

幽羊山之土-Week08_貼圖

1.主題:貼圖Texture

Texture 貼圖
glTexCoord2f( tx, ty );

2.範例:Texture.exe

到 http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/ 
       --> 下載: windows.zip, data.zip, glut32.dll (week03

執行 Texture.exe 檔案
glTexCoord2f( tx, ty );
點的順序是右手定則
0,1    <    1,1
  ˇ              ^
0,0    >    1,0


-

3.實作:OpenCV

到 https://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.1/
    -->下載 OpenCV-2.1.0-win32-vs2008.exe
安裝 openCV 2.1 後才可以開CodeBlocks ,才能讀到檔
之後,開啟GLUT程式 (week01
 進入transmission zero 網站,下載 freeglut 3.0.0 MinGW Package 
 在 CodeBlocks 開啟GLUTproject
貼圖程式:
#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.jpg");///貼圖需要 cvShowImage("opencv Window", img); ///貼圖需要 cvWaitKey(0); ///貼圖需要 glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH); glutCreateWindow("Week08"); glutDisplayFunc(display); glutMainLoop(); }
要設定檔:










.

4.實作:OpenCV + OpenGL 貼圖


5.期中考: 十行OpenGL程式

glPushMatrix(); //備份矩陣 10% glTranslatef( x, y, z); //移動 30% glRotatef( angle, x, y, z); //旋轉 40% glScalef( x, y, z); //縮放 50% glBegin(GL_POLYGON); //開始畫 60% glColor3f( R, G, B); //顏色 70% glTexCoord2f( tx, ty); //貼圖座標 80% glNormal3f( nx, ny, nz); //打光法向量 90% glVertex3f( x, y, z); //頂點 100% glEnd(); //結束畫 60% glPopMatrix(); //還原矩陣 20%

沒有留言:

張貼留言