1.把windows和data的壓縮檔解壓縮放桌面,將壓縮好的data放進壓縮好的windows檔,點transformation.c,可以開啟檔案
2.File-New-Project GLUT專案 (把freeglut準備好)
3. source.zip 裡 將glm.h 放進我們剛剛開的GLUT專案檔裡面
4.source.zip 裡 將glm.c改成glm.cpp 放進我們剛剛開的GLUT專案檔裡面
5.transformation.c用記事本打開,複製裡面內容,再去將專案main.cpp裡的程式刪掉,貼上剛剛複製的transformation.c內容
6.在CodeBlocks裡,左邊Add File,將glm.cpp加入
7.把壓縮好的data,丟進freeglut裡的bin,回到GLUT專案看main程式的707行,可以把專案檔改名,在執行專案,就會發現這個變成自己的專案檔
8.我們開始寫自己的glm程式
9.#include "glm.h" //使用glm.cpp外掛
10.GLMmodel*pmodel = NULL;//pmodel指標
11.void drawmodel()這個函式讀入OBJ,調大小,畫出
12.display()裡,呼叫 drawmodel()
#include "glm.h"
GLMmodel*pmodel = NULL;
void drawmodel(void)
{
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);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
drawmodel();
glutSwapBuffers();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
glutCreateWindow("week11");
glutDisplayFunc(display);
glutMainLoop();
}
#include "glm.h"
GLMmodel*pmodel = NULL;
void drawmodel(void)
{
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);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotated(180,0,1,0);
drawmodel();
drawmodel();
glutSwapBuffers();
}
///打光陣列
const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, -5.0f, 0.0f };
const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
glutCreateWindow("week11");
///打光設定
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
glutDisplayFunc(display);
glutMainLoop();
}




沒有留言:
張貼留言