2016年5月9日 星期一

Week12

1.載模型

在jsyeh/3dcg10中
下載 windows.zip、data.zip、sourse.zip、glut32.dll
可直接執行模型

2. 用程式碼執行模型


建貝殼專案 Build Options 設定


(1) Search Directories 中
1.Compiler Add  C:\freeglut\include 
2.Linker Add C:\freeglut\lib

(2) Linker Settings 中加入
              1.freeglut
              2.opengl32
              3.glu32
              4.gdi32
              5.winmm

右鍵 Add files
source中的glm.c、glm.h、transformation.c 加入資料夾



刪除原本的 main.cpp


將 data 加到資料夾


將 freeglut 資料夾bin 中 freeglut.dll 加到資料夾


選取 glm.c、transformation.c 開啟檔案

成功執行


3. 跑車圖型

另存一個myOBJ.cpp 先將之前的 glm.c 檔名改為 .cpp


程式碼:

#include <GL/glut.h>
#include "glm.h"

GLMmodel* pmodel = NULL;

void display()
{
    glClearColor(0,0,1,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_DEPTH | GLUT_DOUBLE);
    glutCreateWindow("03161042");
    glutDisplayFunc(display);

    glutMainLoop();
}

執行


4. 應用上面程式碼再加些程式 可跑出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);
     }
     glRotatef(90,0,1,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("GLM model is great!");
    glutDisplayFunc(display);

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

    glutMainLoop();

}

沒有留言:

張貼留言