-
開新空白(貝殼)專案
source裡的glm.c、transformation.c、glm.h放進專案資料夾
原本的main.c刪掉
調換成transformation.c、glm.c
解壓縮freeglut在桌面
專案按右鍵
選Build option...
在Searth directories標籤下的
Compiler標籤加入在freeglut資料夾裡面的include資料夾路徑
Compiler標籤加入在freeglut資料夾裡面的include資料夾路徑

Linker Setting裡加入咒語(有順序)
freeglut
opengl32
gul32
gdi32
winmm
專案資料夾需要freeglut/bin裡的freeglut.dll
專案資料夾裡需要data資料夾
執行
*-
transformation.c改名->myOBJ.cpp
glm.c改名->glm.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);
}
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();
}
--
rebuild後執行
/*課堂四
main裡加
glLightfv(GL_LIGHT0, GL_POSITION, pos);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
打光的程式碼
glRotatef(90, 0,1,0); //看車頭
GLfloat pos[] = {0.0, 0.0, -1.0, 0.0};// 打光從前面打
----
#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("GLM model is great!");
glutDisplayFunc(display);
glLightfv(GL_LIGHT0, GL_POSITION, pos);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glutMainLoop();
}
----





























沒有留言:
張貼留言