2016年5月29日 星期日

㍿ ✘✘✘✘DOPE✘✘✘✘ Week12

打開 translation.exe 看可不可以使用

下載範例: jsyeh.org/3dcg10

win32.zip    放到 桌面
data.zip      放到 windows裡面
glut32.dll   放到 windows裡面


在 codeblocks 打開 檔案

1.開啟空專案




選擇C++



設定路徑



環境變數不用更動



將原本的 main 刪掉 重新製作



將 glm.c /glm.h/translation.c 放進去



設定環境變數 加入freeglut/opengl32/glu32/gdi32/winmm



放置路徑 C:\Users\USER\Desktop\freeglut\include
   
//跳出視窗選擇 NO 






 把 freeglut.dll和 data 資料夾 補充進去



讀3D模型並且打開

依照作業二做完的專案繼續作業, 將glm.c 和 tranlation.c 刪掉
將 glm.c 的附檔名 改成 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();
}




 執行結果 2D模式 有問題就rebuild 在看看錯誤



打光增加亮度 深度 變為3D圖形





#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();
        glRotated(30,0,1,0); ///用滑鼠移動一次的角度
        glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
    ///glPopMatrix();   //加了PUSH /POP 就會固定模型

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




沒有留言:

張貼留言