2016年5月9日 星期一

WeeK12 複習中~~

課堂作業(1)
先去下載範例jsyeh.org/3dcg10:
source、win32.zip、data.zip、glut32.dll
存放在桌面的資料夾裡面



─────────────────────────────────────────────────────────
課堂作業(2)
開啟新專案


對專案上面做更動

找到freeglut的include、lib



再輸入freeglut、opengl32、glu32、gdi32、winmm

然後清除專案裡面的程式碼複製下面3個到專案裡
data、freeglut.dll


然後就執行完成了

─────────────────────────────────────────────────────────
課堂作業(3)
接著把專案裡面的transformation.c當案做更名的動作myOBJ
然後把專案清空

在專案資料夾裡面更改附檔名為cpp
再次把glm.cpp跟myOBJ.cpp加入到專案裡面

然後再myOBJ.cpp做程式碼的輸入

#include <GL/glut.h>
#include "glm.h"

GLMmodel* pmodel = NULL;

void display()
{
    glClearColor(0,1,1,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_DEPTH | GLUT_DOUBLE);
    glutCreateWindow("03161042");
    glutDisplayFunc(display);

    glutMainLoop();
}

然後執行成功為

─────────────────────────────────────────────────────────
然後讓車子有光影的效果
對程式碼做一些增加
#include <GL/glut.h>
#include "glm.h"
GLMmodel* pmodel = NULL;

void display()
{
    glClearColor(0,1,1,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_DEPTH | GLUT_DOUBLE);
    glutCreateWindow("03160012");
    glutDisplayFunc(display);

    glLightfv(GL_LIGHT0, GL_POSITION, pos);
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHTING);
    glEnable(GL_DEPTH_TEST);

    glutMainLoop();
}
然後完成就跑程式碼




沒有留言:

張貼留言