2016年5月9日 星期一

Week12

1.
jsyeh.org/3dcg10
下載
win32.zip---解壓縮到資料夾
data.zip-----點開 拖裡面的data資料夾到資料夾
glut32.dll---移到資料夾
source.zip裡面都是原始很長的程式碼  --看   glm.h   &  glm.c  &  transformation.c

2.打開貝殼專案兩個路徑&咒語










要把這幾個加到資料夾


把main.cpp刪掉




如果歪掉移一下視窗會修正

3.



把transformation.c另存新檔save.as改成myOBJ.cpp
去專案資料夾把glm.c改成glm.cpp




編輯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("GLM model is great!");
    glutDisplayFunc(display);
    glutMainLoop();

}








4.調光
#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(90,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);///要記得宣告pos的陣列
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHTING);
    glEnable(GL_DEPTH_TEST);///深度

    glutMainLoop();
}


沒有留言:

張貼留言