2016年5月9日 星期一

出木杉英才的學霸之路 Week12

(1)blog內容複習
(2)GLUT基礎原件
(3)Maya會出OBJ檔,並將OBJ檔Load/Draw
(4)回家作業

      到http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/網站下載"windows","data","glut32.dll"
      解壓縮到windows壓縮後的檔案內





























打開Code::Blocks開啟新的貝殼專案














設定咒語
















刪除原先建立的程式檔,把"source"檔案內的"glm.c","glm.h","transformation.c"拉入資料夾中





把freeglut>bin內的freeglut.dll和下載的"data"一並放入資料夾



執行程式


把原先transformation.c檔案改名成myOBJ.cpp,把glm.c改成glm.cpp














重新開啟兩個檔案,把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);

    glutSwapBuffers();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("GLM model is great!");
    glutDisplayFunc(display);

    glutMainLoop();
}

記得一定要Rebuild















執行結果
















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


執行結果















沒有留言:

張貼留言