2020年5月12日 星期二

week 12 音效


音效


可以讀入mp3和wav檔案
滑鼠按下之後可以連續發出音效


#include <stdio.h>
#include <windows.h>  //執行sound必要函式
#include <mmsystem.h>  //執行sound必要函式
#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){
    PlaySoundA("bong.wav",NULL,SND_SYNC);  //讀入自訂聲音檔,記得放入同個專案裡面
}

int main(int argc,char**argv){
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week12 sound");

    glutMouseFunc(mouse);  //mouse會發聲
    glutDisplayFunc(display);
    glutMainLoop();
}


沒有留言:

張貼留言