到這個網址http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
下載4個檔案: source data win32 glut32
進行模組

2.課堂作業二
建立貝殼檔案:
選擇右上的Console application
之後輸入檔名
位置放在桌面上
編譯器 要選freeglut資料夾裡的 Include
linker 要選freeglut資料夾裡的 lib
按下build 即可以展示
如下圖:
有了一台車的模型出來
可以上下選轉移動它!!

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);
}
glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
glutSwapBuffers();
}
nt main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
glutCreateWindow("My GLM!");
glutDisplayFunc(display);
}
會跑出一台平面的車子!!!
4.課堂作業四:
#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(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_DOUBLE |GLUT_DEPTH);
glutCreateWindow("My GLM!");
glutDisplayFunc(display);
glLightfv(GL_LIGHT0,GL_POSITION,pos);//加燈光
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);//深度偵測
glutMainLoop();
}
按下build展示後
圖片如下:
就會跑出一台車


沒有留言:
張貼留言