2016年5月14日 星期六

WEEK12陳心瑜

Week12
1.複習Blog
2.GLUT基礎元件
3.Maya匯出3D模型使用glm讀OBJ(Read,Draw)
4.回家作業

TODO:
下載jsyeh.org/3dcg10
-windows->桌面/2016CG/EXE檔
-data.zip->桌面/2016CG/data/*.obj *.mtl
-glut32.dll->桌面/2016CG/glut32.dll
-source┌glm,h
            ├glm.c
            └ transformation.c
              ------>用Notepad++看

課堂作業一:

下載jsyeh.org/3dcg10


















-windows->桌面/2016CG/EXE檔
-data.zip->桌面/2016CG/data/*.obj *.mtl
-glut32.dll->桌面/2016CG/glut32.dll
    -source┌glm,h
                ├glm.c
                └ transformation.c
















用Notepad++看


















把freeglut 解壓縮拉到桌面

















課堂作業二:

開啟一個新的專案檔


















還原project

















刪除main檔

















加入glm&transformation->開起舊檔

















點開程式碼看看

















右鍵開啟Build options
















加目錄
C:\Users\USER\Desktop\freeglut\include

















加目錄
C:\Users\USER\Desktop\freeglut\lib

















加咒語
     freeglut
     opengl32
     glu32
     gdi32
     winmm

















因為有東西沒放所以不能執行

















把freeglut.dll放進去專案檔

















這樣就可以執行了

















課堂作業三:

用課堂(2)專案(有咒語有目錄)
Remove刪除transformation.cpp
在File-New-Empty File:存myModel.cpp(加入專案)

#include "glm.h"
  GLMmodel *pmodel=NULL;
void display()
{
  //剪貼範例的
  glutSwapBuffers();
}
int main(int argc,

打開檢視工具(ALT+V)
然後將"隱藏已知檔案類型的副檔名"取消勾勾
















將glm和transformation的附檔名改成.cpp
















將原本main的執行檔刪掉



















將三個檔案拉道專案資料夾裡面










增加兩個檔案





























將freeglut.dll移到專案資料夾
















將data資料夾移到專案資料夾




新增目錄

















新增咒語 freeglut、opengl32、glu32、gdi32、winmm













刪掉transformation.cpp













新增專案myModel.cpp














打出以下程式碼,完成

#include "glm.h"
GLMmodel * pmodel=NULL;
void display()
{
    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("3D Model ready YA!");

    glutDisplayFunc(display);

    glutMainLoop();
}












將程式碼增加紅字部分

#include "glm.h"
GLMmodel * pmodel=NULL;
void display()
{
    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();
}
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("3D Model ready YA!");

    glutDisplayFunc(display);

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

    glutMainLoop();
}

沒有留言:

張貼留言