(1) 貼圖
GOAL: 玩遊戲的小貼圖
怎麼玩?
1. Google 搜尋 "nehe lesson"
找32課
2.Download C++程式碼
3.解壓縮檔案打開" Lesson32.cpp"
(2)聲音
GOAL 1:把聲音加到OpenGL的專案裡
怎麼加?
1.打開Lesson32-->Data找到shot.wav聲音檔
在OpenGL加入程式碼:
|
|
|
|
\ | /
void mouse(int button, int state, int x, int y)
{
PlaySound("C:\\Users\\user\\Downloads\\Lesson32\\Data/shot.wav",NULL,SND_ASYNC);
///將 "\" 改成(a) "\\" or (b) "/"
}
&&
glutMouseFunc(mouse);
--------------------------------------------------------------------------------------------------------------------------
GOAL 2:點擊鍵盤可播放音檔
1.在網路上找音檔 DO-RE-ME
加入程式碼:
|
|
|
|
|
|
|
|
\ | /
void keyboard(unsigned char key, int x, int y)
{
if(key=='1')PlaySound("C:\\Users\\user\\Desktop\\music/do.wav",NULL,SND_ASYNC);
if(key=='2')PlaySound("C:\\Users\\user\\Desktop\\music/re.wav",NULL,SND_ASYNC);
if(key=='3')PlaySound("C:\\Users\\user\\Desktop\\music/mi.wav",NULL,SND_ASYNC);
if(key=='4')PlaySound("C:\\Users\\user\\Desktop\\music/fa.wav",NULL,SND_ASYNC);
if(key=='5')PlaySound("C:\\Users\\user\\Desktop\\music/so.wav",NULL,SND_ASYNC);
}
2.鍵入1,2,3,4,5 便可撥放聲音
--------------------------------------------------------------------------------------------------------------------------
GOAL 3:播放MP3音樂
1.將CMP3_MCI檔案放入自己建立的專案資料夾
2.播音樂
加入程式碼:
|
|
|
|
|
|
|
|
\ | /
#include "CMP3_MCI.h"///(1)放在同一個程式碼專案的目錄中
CMP3_MCI myMP3;
&&
int main(int argc,char *argc[])
///(3) Load mp3 file
myMP3.Load("C:\\Users\\user\\Desktop\\music/yukai.mp3");
myMP3.Play();///(4) Play the file
(3)小遊戲
沒有留言:
張貼留言