2016年5月9日 星期一

week12

到http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
下載檔案 source  data  win32  glut32.dll
\
按出模型

再輸入3個咒語



放入檔案

結果如下

把glm.c >glm.cpp
    tranxxxx.c  >     myObj.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("My GLM!");
    glutDisplayFunc(display);

    glutMainLoop();

}

加上幾行程式
 打光 旋轉 讓模型更好玩呢
程式碼:
#include <GL/glut.h>
#include "glm.h"
GLMmodel * pmodel=NULL;

void display()
{
    glClearColor(0,6,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("My GLM!");
    glutDisplayFunc(display);

    glLightfv(GL_LIGHT0, GL_POSITION, pos);  /////////  打光
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHTING);
    glEnable(GL_DEPTH_TEST);  ///深度值

    glutMainLoop();

}









沒有留言:

張貼留言