2017年4月24日 星期一

Week10_魚筆記

作業一

玩遊戲、射擊體驗看看
1.google搜尋NeHe Lesson 32


2.下載Visual C++ (在Lesson 32網頁的最下面)


3.解壓縮



4.開聲音的設定(設成預設)



5.試玩看看(要開聲音),並截圖上傳



作業二

1.開啟CodeBlocks的GLUT專案


2.搜尋sound程式碼



3.開始撰寫程式碼,讓他有聲音
#include <mmsystem.h> ///多媒體系統
void mouse(int button,int state,int x,int y)
{
    PlaySound("C:\\Users\\user\\Desktop\\Lesson32\\Data/shot.wav",NULL,SND_ASYNC);
    ///把檔名裡面的斜線,從\變成\\ or /
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitWindowSize(640,480);
    glutInitWindowPosition(10,10);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("GLUT Shapes");

    glutReshapeFunc(resize);
    glutDisplayFunc(display);
    glutKeyboardFunc(key);
    glutIdleFunc(idle);
    glutMouseFunc(mouse); ///加入mouse function

    glClearColor(1,1,1,1);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);

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

    return EXIT_SUCCESS;
}

執行後點擊,即可聽到聲音


4.撰寫KEYBOARD的程式碼,使我們按1 2 3 4 5會有DO RE MI FA SO的聲音
void mouse(int button,int state,int x,int y)
{
    PlaySound("C:\\Users\\user\\Desktop\\Lesson32\\Data/shot.wav",NULL,SND_ASYNC);
    ///把檔名裡面的斜線,從\變成\\ or /
}
void keyboard(unsigned char key,int x,int y)
{
    if(key=='1') PlaySound("do.wav",NULL,SND_ASYNC);
    if(key=='2') PlaySound("re.wav",NULL,SND_ASYNC);
    if(key=='3') PlaySound("mi.wav",NULL,SND_ASYNC);
    if(key=='4') PlaySound("fa.wav",NULL,SND_ASYNC);
    if(key=='5') PlaySound("so.wav",NULL,SND_ASYNC);
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitWindowSize(640,480);
    glutInitWindowPosition(10,10);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("GLUT Shapes");

    glutReshapeFunc(resize);
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard); ///加入keyboard function
    glutIdleFunc(idle);
    glutMouseFunc(mouse); ///加入mouse function


    glClearColor(1,1,1,1);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);

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

    return EXIT_SUCCESS;
}




5.把CMP3_MCI.h檔放到程式碼專案中,要播放的MP3檔業可以放進去



6.開始撰寫程式碼(加入MP3檔播放)
#include <mmsystem.h> ///多媒體系統
#include "CMP3_MCI.h" ///放在同一個程式碼專案的目錄中
CMP3_MCI myMP3; ///宣告一個變數叫myMP3
void mouse(int button,int state,int x,int y)
{
    PlaySound("C:\\Users\\user\\Desktop\\Lesson32\\Data/shot.wav",NULL,SND_ASYNC);
    ///把檔名裡面的斜線,從\變成\\ or /
}
void keyboard(unsigned char key,int x,int y)
{
    if(key=='1') PlaySound("do.wav",NULL,SND_ASYNC);
    if(key=='2') PlaySound("re.wav",NULL,SND_ASYNC);
    if(key=='3') PlaySound("mi.wav",NULL,SND_ASYNC);
    if(key=='4') PlaySound("fa.wav",NULL,SND_ASYNC);
    if(key=='5') PlaySound("so.wav",NULL,SND_ASYNC);
}

int main(int argc, char *argv[])
{
    myMP3.Load("C:\\Users\\user\\Desktop\\04160116/yukai.mp3");  ///找到資料夾中要播放的MP3檔並撥放
    myMP3.Play();  ///play the file
    glutInit(&argc, argv);
    glutInitWindowSize(640,480);
    glutInitWindowPosition(10,10);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    /** \brief
     *
     * \param
     * \param
     * \return
     *
     */
    /** \brief
     *
     * \param Shapes" "GLUT
     *
     */
    glutCreateWindow("GLUT Shapes");

    glutReshapeFunc(resize);
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutIdleFunc(idle);
    glutMouseFunc(mouse); ///加入mouse function


    glClearColor(1,1,1,1);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);

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

    return EXIT_SUCCESS;
}

















沒有留言:

張貼留言