Week10
1.播放聲音
2.自彈音樂
程式碼:
#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);
}
void mouse(int botton,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("week10 sound");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
}





沒有留言:
張貼留言