2023年4月26日 星期三

rita - week11 - 鍵盤、聲音、///先不教 滑鼠、轉動

 

        第一個程式(weel11-1_keyboard)

           1.file => new => project 開啟GLUT project
            2.點選點點點選擇桌面  將檔名改成week11-1_keyboard
            3.下載葉老師上課用軟體freeglut壓縮檔
            將裡面的freeglut檔案複製到桌面
            再將裡頭lib的libfreeglut.a複製並貼上
            將複製的改檔名為libglut32.a
    
             4.再回到上一步選擇位置  選擇桌面/freeglut資料夾

範例圖片

    
            ///week11-1_keyboard
            #include <GL/glut.h>

            void display()
            {
                glutSolidTeapot(0.3);
                glutSwapBuffers();
            }
            void keyboard(unsigned char key,int x,int y)
            {///今天新教的
                if(key==27) exit(0);///學習來自GLUT專案的範例
            }
            int main(int argc,char**argv)
            {
                glutInit(&argc,argv);
                glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
                glutCreateWindow("week11");

                glutDisplayFunc(display);
                glutKeyboardFunc(keyboard);///今天新教的

                glutMainLoop();
            }


    第二個程式(week11-2_keyboard_wav_PlaySound)

        ///week11-2_keyboard_wav_PlaySound
        #include <windows.h>
        #include <GL/glut.h>

        void display()
        {
            glutSolidTeapot(0.3);
            glutSwapBuffers();
        }
        void keyboard(unsigned char key,int x,int y)
        {///今天新教的    音樂檔,先用絕對路徑,要小心因為\\代表1個反斜線
    if(key=='1') PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\do.wav",NULL,SND_ASYNC);
    if(key=='2') PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\re.wav",NULL,SND_ASYNC);
    if(key=='3') PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\mi.wav",NULL,SND_ASYNC);
        }
        int main(int argc,char**argv)
        {
            glutInit(&argc,argv);
            glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
            glutCreateWindow("week11");
        
           glutDisplayFunc(display);
            glutKeyboardFunc(keyboard);///今天新教的

            glutMainLoop();
        }



    小補充:
    1.音樂檔案用notepad++開啟後  可看檔案前3~4個英文單字  代表格式
    2.最前面的include window呼叫PlaySound("檔名,NULL,SND_ASYNC");便能播放
    3.NULL代表空值  播放音樂沒有放在任何物件下
    4.SND_ASYNC 不等待同步 會馬上繼續播放音樂


    第三個程式

    比較:OpenCV:3咒語  GLUT:5咒語  PlaySound:1咒語

    將前面兩個專案關閉  file-new-empty file
    setting compiler / Linker settings / add / winmm


    #include <windows.h>

    int main()
    {
                                                                                                               ///等待同步          PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\do.wav",NULL,SND_SYNC);
                    PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\re.wav",NULL,SND_SYNC);
            PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\mi.wav",NULL,SND_SYNC);
            PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\fa.wav",NULL,SND_SYNC);
            PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\so.wav",NULL,SND_SYNC);
       }


    第四個程式(week11-4_glut_mp3)

    將外掛檔案放入week11-4專案資料夾



    從第136開始更改程式碼
    ///在原先程式碼中 先插入一個外掛
    #include "CMP3_MCI.h"///要使用另一個外掛 將檔案複製到week11-4檔案夾裡
    CMP3_MCI myMP3;///要宣告一個變數

    int main(int argc, char *argv[])
    {                                       ///字串裡\\或是/都可以當作目錄
        char filename[]="C:/Users/Administrator/Desktop/do_re_mi/suzumi.mp3";
        myMP3.Load(filename);
        ///myMP3.Load("檔名.mp3");不用了
        myMP3.Play();///播放


    更改程式碼變成相對路徑的方式較為簡單
        

更改程式碼變成相對路徑
打開notepad++更改11.21行  記得ctrl-s存檔
將音樂檔案和freeglut.dull放入week11專案資料夾內

    補充:因為我們希望將dll檔案可以備份 
    要先進去git bash將我們的2023graphicsa clone下來  點.gitignore進去
    將.dll前加井字號#
    


    





沒有留言:

張貼留言