課堂作業一 : Bolg內容複習
將 win32.zip -- 桌面/2016CG/exe檔
將 data.zip --桌面/2016CG/data/obj(或mtl)檔
將 glut32.dll --桌面/2016CG/glut32.dll
source.zip -- glm.h
glm.c
transformation.c
課堂作業二 : GLUT基礎原件
新建貝殼專案
這個記得點 "否" ,不然會有大問題 !!!!!
五咒語 : freeglut、glu32、gdi32、opengl32、winmm
記得設置好路徑
將原有專案刪除
加入專案
將 source.zip 裡面的 glm.c、glm.h、transformation.c 拉進資料夾
刪除原有的main
將 data 拉進資料夾
將 freeglut.dll 拉進資料夾
選取 glm.c、transformation.c 開啟檔案
執行
課堂作業三 : 匯出 OBJ 檔
在程式資料夾(03161060)裡面 Alt+t 工具 - 選資料夾選項 - 檢視 - 隱藏已知檔案類型的附檔名(不要打勾)
就會出現 myOBJ.cpp,把 glm.c 改成 glm.cpp,並將舊的兩個刪掉,加入新的兩個 myOBJ.cpp & glm.cpp
把 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();
}
執行後
進階版本 !!! ~~~~~~~~~
程式改良 :
#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);
}
glPushMatrix();
glPushMatrix();
glRotatef(90, 0,1,0);
glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
glPopMatrix();
glPopMatrix();
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();
}













沒有留言:
張貼留言