2016年5月9日 星期一

【03160135_吳亞芳】Week12

課堂一


下載 glut32.dll[data][win32][source]四個檔案




















windows解壓縮裡面exe檔放到2016CG資料夾




















data壓縮檔裡整個data資料夾(包含obj.mtl檔)放到2016CG資料夾



















glut32.dll也移進





















-
開新空白(貝殼)專案




















source裡的glm.c、transformation.c、glm.h放進專案資料夾





















原本的main.c刪掉


















調換成transformation.c、glm.c























解壓縮freeglut在桌面




加咒語、路徑



專案按右鍵

選Build option...

















Searth directories標籤下的
Compiler標籤加入在freeglut資料夾裡面的include資料夾路徑
Linker標簽下加入在freeglut資料夾裡面的lib資料夾路徑




































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();
}



----



沒有留言:

張貼留言