2016年5月9日 星期一

week12 和鋼鐵人一起拯救世界a柏廷

TODO(一): 打開 translation.exe 看可不可以使用

下載範例: jsyeh.org/3dcg10

(1.) win32.zip   放到 桌面
(2.) data.zip      放到 windows裡面
(3.) glut32.dll   放到 windows裡面


TODO(二): 在 codeblocks 打開 檔案

1.開啟空專案


2.過程


3.選擇C++


4.設定路徑


5.環境變數不用更動


6.將原本的 main 刪掉 重新製作


7. 將 glm.c /glm.h/translation.c 放進去


8. 設定環境變數 加入freeglut/opengl32/glu32/gdi32/winmm


9. 放置路徑 C:\Users\USER\Desktop\freeglut\include
   
//跳出視窗選擇 NO 不要讓路徑變成...


10. 放置路徑 C:\Users\USER\Desktop\freeglut\lib

//跳出視窗選擇 NO 不要讓路徑變成...


11.  把 freeglut.dll和 data 資料夾 補充進去


TODO(三) 讀3D模型並且打開

1.依照 作業二做完的專案繼續作業, 將glm.c 和 tranlation.c 刪掉
將 glm.c 的附檔名 改成 cpp  ,加上新的檔案名為myOBJ
加上程式碼


2. 執行結果 2D模式 有問題就rebuild 在看看錯誤


程式碼:

#include <GL/glut.h>
#include "glm.h"
GLMmodel * pmodel=NULL;

void display()
{
    glClearColor(1,0,0,0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    if(!pmodel)
    {
        pmodel=glmReadOBJ("data/porsche.obj");
        if(!pmodel) exit(0);
        glmUnitize(pmodel);
        glmFacetNormals(pmodel);
        glmVertexNormals(pmodel,90.0);
    }
    glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);

    glutSwapBuffers();
}
int main(int argc,char **argv)
{
 glutInit(&argc,argv);
 glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
 glutCreateWindow("GLM model is great");
 glutDisplayFunc(display);
 glutMainLoop();
}

TODO4:打光增加亮度 深度 變為3D圖形


#include <GL/glut.h>
#include "glm.h"
GLMmodel * pmodel=NULL;

void display()
{
    glClearColor(1,0,0,0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    if(!pmodel)
    {
        pmodel=glmReadOBJ("data/porsche.obj");
        if(!pmodel) exit(0);
        glmUnitize(pmodel);
        glmFacetNormals(pmodel);
        glmVertexNormals(pmodel,90.0);
    }
    /// glPushMatrix();
        glRotated(30,0,1,0); ///用滑鼠移動一次的角度
        glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
    ///glPopMatrix();   //加了PUSH /POP 就會固定模型

    glutSwapBuffers();
}
GLfloat pos[]={0.0,0.0,-1.0,0.0};
int main(int argc,char **argv)
{
 glutInit(&argc,argv);
 glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
 glutCreateWindow("GLM model is great");
 glutDisplayFunc(display);

 glLightfv(GL_LIGHT0, GL_POSITION,pos);
 glEnable(GL_LIGHT0);
 glEnable(GL_LIGHTING);
 glEnable(GL_DEPTH_TEST);

 glutMainLoop();
}




沒有留言:

張貼留言