1.主題:聲音/音效/音樂
2.實作:PlaySound(),CMP3_MCI.h
3.鍵盤鋼琴 射擊遊戲
4.複習貼圖+TRT 下周小考


>>
打上#include <mmsystem.h>//多媒體系統
>>
下載聲音檔放在ferrglut\bin裡面
>>
在main函式裡面加上
 PlaySound("聲音.wav",NULL,SND_ASYNC);


常見錯誤:
wav檔名重複: 聲音.wav.wav
音響設定錯誤
 
 
 
 
 
 
 
 
 
自己打出程式
#include <windows.h>///windows在mmsystem之前
#include <mmsystem.h>
#include <stdio.h>

int main()
{
    PlaySound("ccheer.wav",NULL , SND_SYNC);
    ///SYNC < 等這行做完再寫hello
    ///ASYNC < 邊播邊寫
    printf("hello plz input: ");
    int n;
    scanf("%d\n",&n);
}



圖 3


常見錯誤:
聲音檔要放在檔案目錄裡
忘記加上winmm



鍵盤鋼琴:
在main裡面加上(原本裡面就有glutKeyboardFunc(key);)
glutKeyboardFunc(key);///鍵盤鋼琴

並把
static void key函式
改成
static void key(unsigned char key, int x, int y)
{
    switch (key)
    {
        case '1' : PlaySound("Do.wav",NULL,SND_ASYNC);
            break;

        case '2': PlaySound("Re.wav",NULL,SND_ASYNC);
            break;

        case '3': PlaySound("Mi.wav",NULL,SND_ASYNC);
            break;
    }

    glutPostRedisplay();
}


記得把聲音檔案放到bin裡面



滑鼠射擊:
加上
void mouse(int butt,int state,int x,int y)
{
    if(state==GLUT_DOWN) PlaySound("Shot.wav",NULL,SND_ASYNC);
}
在main裡面加上
glutMouseFunc(mouse);///滑鼠射擊