2016年5月9日 星期一

野比大雄的翻花繩教室week12

課堂作業1:

複習打開程式
下載data/win32/source/glut32.dll
把data/glut32.dll放入win32
直接展示


課堂作業2:

開新貝殼專案
照舊設定
把各資料備齊放入專案資料夾



按bulid就可展示


課堂作業3:

將glm.c改成cpp檔
將建一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();
}

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

記得rebulid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
才能成功展示


課堂作業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();
}

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

加好了就可以展示

沒有留言:

張貼留言