2016年5月10日 星期二

Week 12 張瑋展

作業一:
                                        1.安裝 source data glut.dll windows

                                        2.開啟貝殼專案,刪除main 把 transform glu.h glu.c  freeglut.dll 和data 放進去




                                         3.build option加入位置和咒語 



                                         4.執行
作業二

1.開一個貝殼專案


2.顯示附檔名,並將c改成cpp



3.把原本main.cpp刪除,並且把glm.cpp、transformation.cpp拉進資料夾


4.新增files(glm.cpp、transformation.cpp)



5.compiler(include)、Linker(lib)、咒語(5個)




6.確認資料夾裡面必須有glut32.dll、data資料夾、
glm.cpp、transformation.cpp、glm.h


7.成功執行(若失敗,將視窗拉大即可)

作業3


將glm.c改成cpp檔
將建一cpp檔名為myOBJ.cpp
打入以下程式

----------------------------------------------------------------------------------------------

#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);   ///轉90度
        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); ///加燈光
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHTING);
    glEnable(GL_DEPTH_TEST);  ///加深度測試


    glutMainLoop();
}

----------------------------------------------------------------------------------




沒有留言:

張貼留言