鍵盤控制
- 新增glut專案
- 輸入程式碼
- 新增glut專案
- 複製week11_keyboard程式碼
- 修改keyboard程式碼void keyboard(unsigned char key,int x,int y){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);if (key=='4') PlaySound("C:\\Users\\Administrator\\Desktop\\do-re-mi\\fa.wav",NULL,SND_ASYNC);if (key=='5') PlaySound("C:\\Users\\Administrator\\Desktop\\do-re-mi\\so.wav",NULL,SND_ASYNC);}
- 執行結果:按下鍵盤對應的數字1~5會發出對應聲音
CPP播放聲音
- 新增一個empty file
- 檔案格式cpp
- setting-compiler-linker setting-add-winmm
- 將PlaySound以相對路徑寫
PlaySound("do-re-mi/re.wav",NULL,SND_SYNC);
播放MP3格式(好處可以同時播很多檔)
- 新增glut 專案,不刪程式碼
- 將CMP3_MCI.h 放入程式碼位置
- 新增 #include "CMP3_MCI.h" ///印號引進外掛,檔案要放在跟程式檔同目錄
- 在int main()附近新增程式碼
#include "CMP3_MCI.h" ///印號引進外掛,檔案要放在跟程式檔同目錄
...
}
- save everything
- 將freeglut-bin-freeglut.dll複製貼上到程式碼目錄
- 將音檔移到程式碼目錄
- project-properties-build target-execution working dir 改成小數點 .
- 回到程式碼,將
改成myMP3.Load("suzume.mp3");
解決dll檔會被github刪掉的問題


沒有留言:
張貼留言