1.開啟範例Transformation.exe
下載 windows.zip、data.zip、sourse.zip、glut32.dll
by http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
2.實作開啟Transformation.exe
專案(左鍵) - Build Options 設定
(a)Search Directories 目錄
1.Compiler Add C:\freeglut\include
2.Linker Add C:\freeglut\lib
(b)Linker Settings
Add 1.freeglut
2.opengl32
3.glu32
4.gdi32
5.winmm
刪除原本的 main.cpp
加入data資料夾
加入freeglut.dll
從source中加入glm.c、glm.h、transformation.c
成功執行!
(a)Search Directories 目錄
1.Compiler Add C:\freeglut\include
2.Linker Add C:\freeglut\lib
(b)Linker Settings
Add 1.freeglut
2.opengl32
3.glu32
3.Glut程式讀入3D模型
將glm.c、transformation.c 副檔名改為 cpp
#include <GL/glut.h>
#include "glm.h"
GLMmodel* pmodel = NULL;
void display()
{
glClearColor(0,0,1,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_DEPTH | GLUT_DOUBLE);
glutCreateWindow("03161042");
glutDisplayFunc(display);
glutMainLoop();
}

4.使3D模型有實體材質及旋轉
#include <GL/glut.h>
#include "glm.h"
GLMmodel* pmodel = NULL;
void display()
{
glClearColor(0,0,1,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_DEPTH | GLUT_DOUBLE);
glutCreateWindow("03161042");
glutDisplayFunc(display);
glLightfv(GL_LIGHT0,GL_POSITION,pos);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glutMainLoop();
}








沒有留言:
張貼留言