步驟1:進到下面的網址
http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
步驟2:下載紅色框框內的東西

步驟3:將解壓縮的windows和data和下載的dll檔案放到剛解壓縮的windows資料夾中

步驟4:開啟Transformation.exe檔

步驟5:解壓縮source檔,便可看到glm.h、glm.c、transformation.c檔案
可以打開來看到裡面的程式碼

課堂作業2:
步驟1:先到Code::Blocks建立Console application檔

步驟2:將咒語設定好

步驟3:把檔案remove掉

步驟4:把檔案匯入(紅色框框中的檔)
記得要先把main,cpp先刪掉


課堂作業3:
步驟1:將transformation.c,並加一個myOBJ.cpp檔,再將 glm.c改成.cpp
步驟2:將新的程式碼打入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("GLM model is great!");
glutDisplayFunc(display);
glutMainLoop();
}
步驟3:執行前要ReBuild,就會出現一台車的圖案
課堂作業4:
步驟1:將課堂作業3中的城市進行修改(加入打光的效果)
程式碼如下(藍色為新加入了)
#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(1, 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();
}



沒有留言:
張貼留言