課堂作業1:
1.下載win32,data,glut32.dll,source(去jsyeh.org/3dcg10載)
2.解壓縮
3.data&dll檔放進去win32裡面
4.在source裡面可以找到各種模型程式碼
3.data&dll檔放進去win32裡面
4.在source裡面可以找到各種模型程式碼
課堂作業2:
2.下載win32,data,glut32.dll,source(去jsyeh.org/3dcg10載)
3.解壓縮
4.data&dll檔放進去win32裡面
5.密語:freeglut opengl32 glu32 gdi32 winmm
6.將source中的glm.c,glm.h&transformation.c放進專案中
7.再選擇glm.c&transformation.c拉進專案,按執行就好

課堂作業3:
1.另開新檔
2.transformation.c改檔名為myOBJ.cpp,glm.c也改為glm.cpp
3.myOBJ程式碼:
#include <GL/glut.h>#include "glm.h"
GLMmodel* pmodel = NULL;
void display()
{
glClearColor(1,0,0,0);///剪貼於transformation.c
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();
}
將作業2的物體加上深度和打光
程式碼:
#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(120,0,1,0);///旋轉角度
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();
}




沒有留言:
張貼留言