課堂作業1
1.照之前步驟
2.source.zip拉進
3.glm.h\glm.c案右鍵(用Notepad++開)
課堂作業2
開新貝殼專案
照舊設定
把各資料備齊放入專案資料夾
照舊設定
把各資料備齊放入專案資料夾
按bulid就可展示
課堂作業3
將glm.c改成cpp檔
將建一cpp檔名為myOBJ.cpp
打入以下程式
----------------------------------------------------------------------------------------------
#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();
}
-----------------------------------------------------------------------------------------------
課堂作業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);
}
glPushMatrix();
glRotatef(90,0,1,0); ///轉90度
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("GLM model is great!");
glutDisplayFunc(display);
glLightfv(GL_LIGHT0,GL_POSITION,pos); ///加燈光
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST); ///加深度測試
glutMainLoop();
}
#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();
glRotatef(90,0,1,0); ///轉90度
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("GLM model is great!");
glutDisplayFunc(display);
glLightfv(GL_LIGHT0,GL_POSITION,pos); ///加燈光
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST); ///加深度測試
glutMainLoop();
}








沒有留言:
張貼留言