WEEK12
Work01-複習
第一步:輸入jsyeh.org/3dcg10/,找尋data、win32、glut32.dll、source點擊下載
將window資料夾解壓縮到桌面
Work02-OBJ檔案置入
第一步:開啟codeblock新增專案Console application
選用C++作為撰寫環境
第二步:當專案新增後,先於左方的總檔案按右鍵選擇Build Options
選擇Search directories中的Compiler,將freeglut中的include資料夾位置加入
選擇Search directories中的Linker,將freeglut中的lib資料夾位置加入
請選擇相對位置(請選擇NO!)
選擇Link settings,將
freeglut
opengl32
glu32
gdi32
winmm
加入於Link libraries
左方的總檔案中的main.c,按右鍵選擇Remove file from project
將新的程式檔加入專案中,左方的總檔案按右鍵選擇Add file
選擇glm.c與transformation.c放入專案中
接著,將freeglut.dll放入專案下方的資料夾
執行後,就可看到結果(如果左上方看不到,將視窗拉大即可
將程式碼存成新的檔案(myOBI.c)
接著將glm.cpp和myOBI.cpp加入到專案中
執行後就可以看到成果
記住,執行前先Rebuild,否則不能執行
#include <GL/glut.h>
#include "glm.h"//引入glm.h程式應用
GLMmodel* pmodel=NULL;//"p"model新的指標 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("Hello");
glutDisplayFunc(display);
glutMainLoop();
}
#include <GL/glut.h>
#include "glm.h"//引入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);
}
//stack的Push與Pop
//stack的Push與Pop
glPushMatrix();
glRotatef(90, 0,1,0);//旋轉 角度 座標系X Y Z
glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
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("Hello");
glutDisplayFunc(display);
//打光
glLightfv(GL_LIGHT0, GL_POSITION, pos);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
//深度偵測
glEnable(GL_DEPTH_TEST);
glutMainLoop();
}




























沒有留言:
張貼留言