2015年5月14日 星期四

02160820_林政華 Week12

要將3D模組匯入程式中
先將glm.c和glm.h放同目錄,把.c改成cpp,接著都放進執行處

然後把cpp打開,找出glm的程式碼,複製貼上到程式中
#include "glm.h"
GLMmodel* pmodel=NULL;
int main (){
pmodel = glmReadOBJ("data/porsche.obj");
glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);
glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
}



把windows裡的porsche丟入freeglut資料夾
打上些3D程式碼
最後加上光源(光源座標要注意)
最終的程式碼
#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_LIGHTING);
    glEnable(GL_LIGHT0);

    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("02160820");
glutDisplayFunc(display);

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

glutMainLoop();
}




沒有留言:

張貼留言