Homework-1:玩遊戲
至Google搜尋「nehe lesson 32」
點進去並下載檔案
壓縮檔案
開啟檔案→Yes:全螢幕 / No:視窗
執行(用滑鼠)跑出聲音
新增:
#include <mmsystem.h> ///Multimedia System
void mouse(int button, int state, int x, int y) ///Add a mouse Function
{
PlaySound("C:\\Users\\user\\Desktop\\Lesson32\\Data/shot.wav",NULL,SND_ASYNC); ///Copy this line
///要把檔名裡面的目錄裡面的斜線,從 \ 變成 (A) \\ 或 (B) /
}
glutMouseFunc(mouse); ///Add a mouse Function
下載音檔並執行(用鍵盤)跑出聲音
新增:
void keyboard(unsigned char key, int x, int y)
{
if (key=='1') PlaySound("C:\\Users\\user\\Desktop\\Lesson32\\Data/shot.wav",NULL,SND_ASYNC);
if (key=='2') PlaySound("C:\\Users\\user\\Downloads\\music/do.wav",NULL,SND_ASYNC);
if (key=='3') PlaySound("C:\\Users\\user\\Downloads\\music/re.wav",NULL,SND_ASYNC);
if (key=='4') PlaySound("C:\\Users\\user\\Downloads\\music/mi.wav",NULL,SND_ASYNC);
if (key=='5') PlaySound("C:\\Users\\user\\Downloads\\music/fa.wav",NULL,SND_ASYNC);
if (key=='6') PlaySound("C:\\Users\\user\\Downloads\\music/so.wav",NULL,SND_ASYNC);
}
glutKeyboardFunc(keyboard);
執行(MP3檔)跑出聲音
新增:
#include "CMP3_MCI.h" ///(1)放在同一個程式碼專案的目錄中
CMP3_MCI myMP3; ///(2)宣告一個變數,叫myMP3
myMP3.Load("C:\\Users\\user\\Desktop\\2017/yukai.mp3"); ///(3)Load mp3 file
myMP3.Play(); ///(4)Play the file
沒有留言:
張貼留言