2020年5月12日 星期二

week12(2020/5/12)紀錄

聲音、音效、音樂
播放WAV,MP3

#include<stdio.h>
#include<windows.h>
#include<mmsystem.h>///順序不可換
int main()
{
    PlaySoundA("Koro Funk!",NULL,SND_SYNC);
    printf("Koro Funk!\n");
}

改成滑鼠按小黑窗播放聲音(WAV)

#include<stdio.h>
#include<windows.h>
#include<mmsystem.h>
#include<GL/glut.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glutSwapBuffers();
}
void m(int button,int state,int x,int y)
{
    if(state == GLUT_DOWN) PlaySoundA("Scallop.wav",NULL,SND_SYNC);///SYNC改成ASYNC會變成瞬發
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week12");

    glutMouseFunc(m);
    glutDisplayFunc(display);
    glutMainLoop();

}

在背景撥放MP3音檔

#include"CMP3_MCI.h"///雙引號是從目錄找檔案
CMP3_MCI myMP3;///宣告物件變數 myMP3

在main中加入
myMP3.Load("KoroFunk.mp3");///載入黨案
myMP3.Play();///播放
(.Play()比較好)
可是目錄不好指定
所以要改專案內的cbp檔
裡面有2行working_dir=改成"."
然後 freeglut.dll 也要放在專案資料夾內,這樣其他音檔也能放在專案資料夾內了

沒有留言:

張貼留言