2015年5月14日 星期四

week12_3D Model匯入OpenGL_呂登祐

1.匯入模型
2.6行程式碼

01
測試windows.7zip
開啟Transformation.exe測試轉動和移動


02做設定
1.新new project-GLUT
2.#include "glm.h"
3.把glm.c改副檔名改成glm.cpp
4.把transformation.c裡面6行code複製到專案程式裡面(搜尋glm)
程式碼入下圖
#include "glm.h"

GLMmodel* pmodel = NULL;
int main()
{
    pmodel = glmReadOBJ("data/porsche.obj");
    glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);
}
5.執行出現小視窗
6.增加頭尾設定

#include "glm.h"

GLMmodel* pmodel = NULL;
void display()
{
    glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
    glFlush();
}

int main(int argc,char**argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("GLUT");
    glutDisplayFunc(display);

    pmodel = glmReadOBJ("porsche.obj");
    glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);

glutMainLoop();
}


06.讓模型打光
#include "glm.h"

GLMmodel* pmodel = NULL;
void display()
{
    GLfloat pos[] = { 0.0, 0.0, -1.0, 0.0 };
    glLightfv(GL_LIGHT0, GL_POSITION, pos);
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHTING);

    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
    glFlush();
}

int main(int argc,char**argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("GLUT");
    glutDisplayFunc(display);

    pmodel = glmReadOBJ("porsche.obj");
    glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);

glutMainLoop();
}


沒有留言:

張貼留言