2024年4月15日 星期一

H week09

 week09


#week09-0_sample

1.安裝 freeglut, lib\libfreeglut.lib 複製成 libglut32.a

2.新增glut專案  week09-0_sample

1.下載上週程式碼 安裝github

-在小黑裡指令:

-cd desktop

-git clone https://github.com/你的帳號/2024graphicsb

-cd 2024graphicsb

-start



2.確認環境沒問題行

- 安裝openCV 勾add path, 裝載預設目錄

3.專案設定修改(seting-compiler


#week09-1_gundam_texture_lighting_rotate

把上上週week07的程式專案拿來用,但是步驟有點不一樣

剛前一個目錄week07-2_obj_gundam_opencv_texture整個copy到新的目錄

week09-1_obj_gundam_opencv_texture_lighting

1.再用Notepad++開啟week09-1...目錄裡的 .cbp檔,改內容

2.把打光的8行陣列貼在 int main()之前

3.把打光的12+2行函式貼在 glutMainLoop();之前

4.glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH); 要刪掉中間的 GLM_MATERIAL


為了讓畫面好看一點,打光漂亮,模型旋轉,要做幾個修改

1.改變光的位子

const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };

改成

const GLfloat light_position[] = { 2.0f, 5.0f, -5.0f, 0.0f };


2.void display() 加入旋轉

int main(int argc, char* argv[])

{

    glutInit(&argc, argv);

    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);

    glutCreateWindow("week07-2 obj gundam opencv texture");

    glutDisplayFunc(display);

    glutIdleFunc(display);

    myTexture("Diffuse.jpg");

 glEnable(GL_DEPTH_TEST);

    glDepthFunc(GL_LESS);


    glEnable(GL_LIGHT0);

    glEnable(GL_NORMALIZE);

    glEnable(GL_COLOR_MATERIAL);

    glEnable(GL_LIGHTING);


    glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);

    glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_diffuse);

    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);

    glLightfv(GL_LIGHT0, GL_POSITION, light_position);


    glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient);

    glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse);

    glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular);

    glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);

    glutMainLoop();

}

#week09-2_glutSolidCube_glutSolidTeapot_glutSolidSphere
1.新增glut專案 week09-2_glutSolidCube_glutSoildTeapot_flutSoildSphere
2.貼入11行程式

#include <GL/glut.h>
 void display()
 {
     glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
     glPushMatrix();
        glTranslatef(-0.6,+0.3,0);
        glutSolidTeapot(0.3);
     glPopMatrix();

     glPushMatrix();
        glTranslatef(+0.0,+0.3,0);
        glutSolidCube(0.3);
     glPopMatrix();
     glPushMatrix();
        glTranslatef(+0.6,+0.3,0);
        glutSolidSphere(0.3,30,30);
     glPopMatrix();
     glutSwapBuffers();
 }
 int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow(" week09-2_glutSolidCube_glutSoildTeapot_flutSoildSphere");
    glutDisplayFunc(display);
    glutMainLoop();
}

                                            


#week09-3_glutWireCube_glutWireTeapot_glutWireSphere
1.新增glut專案   week09-3_glutWireCube_glutWireTeapot_glutWireSphere
2.貼上上一個程式 新增Wire程式


#include <GL/glut.h>
 void display()
 {
     glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
     glPushMatrix();
        glTranslatef(-0.6,+0.3,0);
        glutSolidTeapot(0.3);
     glPopMatrix();

     glPushMatrix();
        glTranslatef(+0.0,+0.3,0);
        glutSolidCube(0.3);
     glPopMatrix();
     glPushMatrix();
        glTranslatef(+0.6,+0.3,0);
        glutSolidSphere(0.3,30,30);
     glPopMatrix();

     glPushMatrix();
        glTranslatef(-0.6,-0.3,0);
        glutWireTeapot(0.3);
     glPopMatrix();

     glPushMatrix();
        glTranslatef(+0.0,-0.3,0);
        glutWireCube(0.3);
     glPopMatrix();
     glPushMatrix();
        glTranslatef(+0.6,-0.3,0);
        glutWireSphere(0.3,30,30);
     glPopMatrix();
     glutSwapBuffers();
 }
 int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week09-3_glutWireCube_glutWireTeapot_glutWireSphere");
    glutDisplayFunc(display);
    glutMainLoop();
}









沒有留言:

張貼留言