2020年6月29日 星期一

Note By Jack Week12

放音檔

把音檔放到freeglut/bin


#include <stdio.h>
#include <windows.h>//定義DWORD windows.h要在前面
#include <mmsystem.h>//PlaySoundA()
int main()
{
    PlaySoundA("test.wav", NULL , SND_SYNC );
    printf("week12");

}

按視窗播放



#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 mouse(int button,int state, int x, int y)
{
    ///點擊滑鼠發出聲音
    if(state==GLUT_DOWN) PlaySoundA("test.wav", NULL , SND_SYNC );
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week12");

    glutDisplayFunc(display);
    glutMouseFunc(mouse);

    glutMainLoop();
}
播出.mp3檔案

把CMP3_MCI.h放到專案檔資料夾內
音樂檔放到freeglut/bin


#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
#include <GL/glut.h>
#include "CMP3_MCI.h"//雙引號:要在同一個專案目錄
CMP3_MCI myMP3;//宣告物件變數myMP3

void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glutSwapBuffers();
}
void mouse(int button,int state, int x, int y)
{
    //點擊滑鼠發出聲音
    //if(state==GLUT_DOWN) PlaySoundA("gun.wav", NULL , SND_SYNC );//同步,等他播完
    if(state==GLUT_DOWN) PlaySoundA("test.wav", NULL , SND_ASYNC );//不同步,不等他播完
}
int main(int argc, char *argv[])
{
    myMP3.Load("test.mp3");//讀入檔案
    myMP3.Play();//播放
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week12");

    glutDisplayFunc(display);
    glutMouseFunc(mouse);

    glutMainLoop();
}

音檔放專案資料夾

調整成因檔不用放在freeglult/bin裏頭,放在專案資料夾即可






沒有留言:

張貼留言