#Week11
- week11-1_TRT
- 安裝freeglut,把lib\libfreeglut.a複製成libglut32.a
- File-New-Project, GLUT專案 week10-1_TRT
- 貼上上周的week10-1_glutWireCube_mybody_myArm
- 的程式碼
程式碼: - #include <GL/glut.h>
- void myBody()
- {
- glPushMatrix();
- glColor3f(1,0,0);
- glutWireCube(0.6);///myBody()
- glPopMatrix();
- }
- void myArm()
- {
- glPushMatrix();
- glColor3f(0,1,0);
- glScalef(1,0.4,0.4);
- glutWireCube(0.3);///myBody()
- glPopMatrix();
- }
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- myBody();
- myArm();
- glutSwapBuffers();
- }
- int main(int argc, char*argv[])
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
- glutCreateWindow("week09 Microsoft Visual Studio");
- glutDisplayFunc(display);
- glutMainLoop();
- }
- 再去做更改增加glPushMatrix(); glTranslatef(); glRotatef(angle++,0,0,1); glTranslatef(0.15,0,0); myArm(); glPopMatrix();
程式碼 - #include <GL/glut.h>
- void myBody()
- {
- glPushMatrix();
- glColor3f(1,0,0);
- glutWireCube(0.6);///myBody()
- glPopMatrix();
- }
- void myArm()
- {
- glPushMatrix();
- glColor3f(0,1,0);
- glScalef(1,0.4,0.4);
- glutWireCube(0.3);///myBody()
- glPopMatrix();
- }
- float angle=0;
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- myBody();
- glPushMatrix();
- //glTranslatef();
- glRotatef(angle++,0,0,1);
- glTranslatef(0.15,0,0);
- myArm();
- glPopMatrix();
- glutSwapBuffers();
- }
- int main(int argc, char*argv[])
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
- glutCreateWindow("week11");
- glutDisplayFunc(display);
- glutIdleFunc(display);
- glutMainLoop();
- }
- week11-1_obj_gundam__opencv_texture_lighting
- Setting-Compiler要加入OpenCV相關的 3個設定
- -compiler的include要加入 C:\OpenCV2.1\include
-linker的lib要加入C:\OpenCV\lib
-linker設定 ,要加入cv210 cxcore210 highgui210 # week11-2_glm_gundam_opencv_texture_lighting
不要急,這個用 GitHub 下載下來、複製整個目錄、改檔名、改Title
安裝 OpenCV 2.1 小心! Add PATH,用預設目錄
重開 CodeBlocks, Setting-Compiler 裡要改3個地方
接下來,再把 GitHub 的程式倉庫下載下來, week09-1_glm_gundam_opencv_texture_lighting 拿來用,複製成 week11-2_glm_gundam_opencv_texture lighting
有兩種下載法。第1種是用 Git Bash 下指令
cd desktop
git clone https://github.com/jsyeh/2024graphicsa
cd 2024graphica
start. 開檔案總管,把 week09-1目錄 複製到桌面,再改目錄名
第二種作法,在GitHub 網站
https://github.com/jsyeh/2024graphicsa 點綠色的 Code 的
Download ZIP 再解壓縮,也能把 week09-1目錄,拉到桌面, 再改目錄名哦!
File-Open 開桌面 week11-2_glm_gundam_opencv_texture_lighting 裡面的再改 week11-2 glm gundam opencv texture_lighting.cbp
開起來後,再改專案的 Title 變成
week11-2_glm_gundam_opencv_texture_lighting
# Maya 切割、匯出OBJ
要有 Autodesk 的帳號,註冊 Maya教育版, 寄學生證認證,就可以用了
- handA.obj + handA.mtl
- handB.obj + handB.mtl
# 繼續修改 week11-2_glm_gundam_opencv_texture_lighting
把剛剛的 handA.obj handA.mtl handB.obj handB.mtl放到 data目錄
- 改程式 GLMmodel pmodel = NULL;改成 cpp
GLMmodel * pmodel= NULL;
GLMmodel * handA = NULL;
GLMmodel * handB = NULL;
- 再做修改 void drawmodel(){...} 複製 2段程式 drawHandA() drawHandB() 裡面的pmodel 也換成對應的 handA 和 handB 一中月
- 1
- 1 程式碼:
- ///先把 week08-1_glm_gundam 的程式貼上來
- ///等一下, 要再加貼圖的 18行程式
- #include <opencv/highgui.h> ///使用 OpenCV 2.1 比較簡單, 只要用 High GUI 即可
- #include <opencv/cv.h>
- #include <GL/glut.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;
- }
- #include <GL/glut.h>
- #include "glm.h"
- GLMmodel * pmodel = NULL;
- GLMmodel * handA = NULL;
- GLMmodel * handB = NULL;
- void drawhandA(void)
- {
- if (!handA) {
- handA = glmReadOBJ("data/handA.obj");
- if (!handA) exit(0);
- glmUnitize(handA);
- glmFacetNormals(handA);
- glmVertexNormals(handA, 90.0);
- }
- glmDraw(handA, GLM_SMOOTH | GLM_TEXTURE);
- }
- void drawhandB(void)
- {
- if (!handB) {
- handB= glmReadOBJ("data/handB.obj");
- if (!handB) exit(0);
- glmUnitize(handB);
- glmFacetNormals(handB);
- glmVertexNormals(handB, 90.0);
- }
- glmDraw(handB, GLM_SMOOTH | GLM_TEXTURE);
- }
- float angle = 0; ///加這行, 讓它轉動
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
- glPushMatrix(); ///加這行, 讓它轉動
- glRotatef(angle++, 0, 1, 0); ///加這行, 讓它轉動
- drawhandA(); //glutSolidTeapot( 0.3 );
- glPopMatrix(); ///加這行, 讓它轉動
- glutSwapBuffers();
- }
- const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
- const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
- const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
- const GLfloat light_position[] = { 2.0f, 5.0f, -5.0f, 0.0f };///加這行, 讓它轉動
- const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
- const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
- const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
- const GLfloat high_shininess[] = { 100.0f };
- int main(int argc, char*argv[])
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
- glutCreateWindow("week08 Gundam");
- glutDisplayFunc(display);
- glutIdleFunc(display); ///加這行, 讓它轉動
- myTexture("data/Diffuse.jpg");
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_LESS);
- glEnable(GL_LIGHT0);
- glEnable(GL_NORMALIZE);
- glEnable(GL_COLOR_MATERIAL);
- glEnable(GL_LIGHTING);
- glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
- glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
- glLightfv(GL_LIGHT0, GL_POSITION, light_position);
- glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
- glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
- glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
- glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
- glutMainLoop();
- }
.png)
沒有留言:
張貼留言