#include <windows.h>
#include <stdio.h>
int main()
{
while(1)
{
char c = getchar();
if(c=='1')PlaySound("do.wav",NULL,SND_ASYNC);
if(c=='2')PlaySound("re.wav",NULL,SND_ASYNC);
if(c=='3')PlaySound("mi.wav",NULL,SND_ASYNC);
if(c=='4')PlaySound("fa.wav",NULL,SND_ASYNC);
if(c=='5')PlaySound("so.wav",NULL,SND_ASYNC);
}
}
這樣不用按ENTER就可以發出聲音
#include <windows.h>
#include <GL/glut.h>
#include "CMP3_MCI.h"///檔案放在week10_sound
CMP3_MCI mp3;
static void display(void)
{
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");///檔案放執行目錄freeglut/bin
mp3.Play();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);///(2)Init初始化 Display 的功能
glutCreateWindow("Week10 Sound");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
加上射擊音
滑鼠按鍵及滾輪發出聲音
#include <windows.h>
#include <GL/glut.h>
#include "CMP3_MCI.h"///檔案放在week10_sound
CMP3_MCI mp3;
static void display(void)
{
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");///檔案放執行目錄freeglut/bin
mp3.Play();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week10 Sound");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
}



沒有留言:
張貼留言