2016年5月9日 星期一

Week 12

1. Blog 內容複習
    下載範例  http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
    下載win32.zip => exe檔,  data.zip => obj檔,  glut32.dll
    source.zip => glm.h, glm.c
    win32資料夾有data資料夾和glut32.dll
    開啟transformation.exe
    

2.GLUT 基礎元件
   開啟貝殼空專案
   設定bulid option
     
   remove main.cpp檔
   project 加上files
   
   可以開啟車
   

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


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

沒有留言:

張貼留言