==========================================================================
今天第一個教的是讓程式播出聲音
- 檔案一定要放對位置 也一定要是WAV檔
- 後來把do re mi fa so 也放進資料夾
- 因為上面的要按ENTER鍵才能發出聲音,所以現在改個寫法
- 上面都是WAV檔的 接下來下面是用MP3檔來播放 比較麻煩
#include<windows.h>
#include <GL/glut.h>
#include "CMP3_MCI.h"
CMP3_MCI mp3;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y)
{
if(key=='1') PlaySound("do.wav",NULL,SND_ASYNC);
if(key=='2') PlaySound("re.wav",NULL,SND_ASYNC);
if(key=='3') PlaySound("mi.wav",NULL,SND_ASYNC);
if(key=='4') PlaySound("fa.wav",NULL,SND_ASYNC);
if(key=='5') PlaySound("so.wav",NULL,SND_ASYNC);
}
int main(int argc,char**argv)
{
mp3.Load("music.mp3");
mp3.Play();
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Wee10 sound");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
- 加入 SHOT 聲
#include <GL/glut.h>
#include "CMP3_MCI.h"
CMP3_MCI mp3;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y)
{
if(key=='1') PlaySound("do.wav",NULL,SND_ASYNC);
if(key=='2') PlaySound("re.wav",NULL,SND_ASYNC);
if(key=='3') PlaySound("mi.wav",NULL,SND_ASYNC);
if(key=='4') PlaySound("fa.wav",NULL,SND_ASYNC);
if(key=='5') PlaySound("so.wav",NULL,SND_ASYNC);
}
void mouse(int button ,int state,int x ,int y)
{
if(state==GLUT_DOWN) PlaySound("shot.wav",NULL,SND_ASYNC);
}
int main(int argc,char**argv)
{
mp3.Load("music.mp3");
mp3.Play();
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Wee10 sound");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
}







沒有留言:
張貼留言