2016年5月9日 星期一

week12

一、到 http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
下載source、data、windows、glut32


解壓到自己的資料夾


二、
開Console application專案

選擇Search drectiones Compiler Add增加freeglut裡include資料夾路徑



Search drectionesLinkerr Add增加freeglut裡lib資料夾路徑



Linker settings Linker libraries Add
新增freeglut
新增opengl32
新增glu32
新增gdi32
新增winmm



Remove file from project



Add file



main.cpp刪除



把glm.c、glm.h、transformation.c加入



data也加入



freeglut裡的freeglut.dll也加入



開啟glm.c、transformation.c兩個檔





Run


三、

transformation.c另存新檔成myOBJ.cpp


Remove file from project

刪除transformation.c


glm.c改成glm.cpp


開啟glm.cpp及myOBJ.cpp


Rubuild


四、
修改myOBJ的程式

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

沒有留言:

張貼留言