(1)3D模型
#include "glm.h" //我們要用glm.h 和 glm.c (要先copy到同目錄)
GLMmodel* pmodel = NULL; //宣告 有個pointer指到model
void display()
{
glmDraw(pmodel,GLM_SMOOTH | GLM_MATERIAL);
glFlush();
}
int main(int argc,char**argv)
{
pmodel = glmReadOBJ("porsche.obj"); //如果沒檔案/找不到 就會當機
glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);
glutInit(&argc,argv);
glutCreateWindow("02160615");
glutDisplayFunc(display);
glutMainLoop();
}
(2)打光
#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)
{
pmodel = glmReadOBJ("porsche.obj");
glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);
glutInit(&argc,argv);
glutCreateWindow("02160615");
glutDisplayFunc(display);
glutMainLoop();
}
沒有留言:
張貼留言