課堂1
下載課堂要用的東西!
網址關鍵字: jsyeh.org/3dcg10

秀出很COOL的模型

新增空專案
輸入咒語

咒語

咒語

放進必要檔案

成功!!!

課堂2,課堂3
把glm.c >glm.cpp
tranxxxx.c > myObj.cpp 以上都加到專案中
開始自己寫程式 做出模型外框!!

#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);
}
glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
glutCreateWindow("My GLM!");
glutDisplayFunc(display);
glutMainLoop();
}
課堂4
加上幾行程式 打光 旋轉 讓模型更酷

#include <GL/glut.h>
#include "glm.h"
GLMmodel * pmodel=NULL;
void display()
{
glClearColor(0,6,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("My GLM!");
glutDisplayFunc(display);
glLightfv(GL_LIGHT0, GL_POSITION, pos); ///////// 打光
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST); ///深度值
glutMainLoop();
}
沒有留言:
張貼留言