播放聲音
#include<stdio.h>
#include<windows.h>///定義DWORD#include<mmsystem.h>///playsound
int main()
{
PlaySoundA("kiss.wav",NULL,SND_SYNC);///先放聲音在印字
printf("Week11\n");
}
點擊搭配聲音
#include<stdio.h>
#include<windows.h>///定義DWORD
#include<mmsystem.h>///playsound
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清背景
glutSwapBuffers(); ///交換兩倍buffer s
PlaySoundA("kiss.wav",NULL,SND_SYNC);
}
void mouse(int button,int state,int x,int y)
{
if(state==GLUT_DOWN)PlaySoundA("kiss.wav",NULL,SND_SYNC);
}
int main(int argc, char**argv) ///高手等級的main()
{
glutInit(&argc,argv);///main的參數,於近來
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
///啟動3D的顯示能力,兩倍顯示buffer,有3D深度值
glutCreateWindow("week11");
///建立3D窗子
glutMouseFunc(mouse);///mouse函式
glutDisplayFunc(display);
glutMainLoop();
///主要迴圈卡在這裡,不會結束
}
MP3 PART
#include<windows.h>///定義DWORD
#include<mmsystem.h>///playsound
#include <GL/glut.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清背景
glutSwapBuffers(); ///交換兩倍buffer s
PlaySoundA("kiss.wav",NULL,SND_ASYNC);///不同步
}
void mouse(int button,int state,int x,int y)
{
if(state==GLUT_DOWN)PlaySoundA("kiss.wav",NULL,SND_SYNC);
}
int main(int argc, char**argv) ///高手等級的main()
{
myMP3.Load("on.mp3");
myMP3.Play();
glutInit(&argc,argv);///main的參數,於近來
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
///啟動3D的顯示能力,兩倍顯示buffer,有3D深度值
glutCreateWindow("week11");
///建立3D窗子
glutMouseFunc(mouse);///mouse函式
glutDisplayFunc(display);
glutMainLoop();
///主要迴圈卡在這裡,不會結束
}
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="week11" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/week11" prefix_auto="1" extension_auto="1" />
<Option working_dir="." />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/week11" prefix_auto="1" extension_auto="1" />
<Option working_dir="." />
<Option object_output="obj/Release/" />
<Option type="0" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add directory="C:/Users/Administrator/Desktop/freeglut/include" />
</Compiler>
<Linker>
<Add library="glut32" />
<Add library="opengl32" />
<Add library="glu32" />
<Add library="winmm" />
<Add library="gdi32" />
<Add directory="C:/Users/Administrator/Desktop/freeglut/lib" />
</Linker>
<Unit filename="main.cpp" />
<Extensions>
<code_completion />
<envvars />
<debugger />
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>
wav檔一次只能用一個顯卡mp3則不限制
#include<windows.h>///定義DWORD
#include<mmsystem.h>///playsound
#include <GL/glut.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
CMP3_MCI Do,Re,Mi,Fa,So;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清背景
glutSwapBuffers(); ///交換兩倍buffer s
PlaySoundA("kiss.wav",NULL,SND_SYNC);
}
void mouse(int button,int state,int x,int y)
{
if(state==GLUT_DOWN)PlaySoundA("kiss.wav",NULL,SND_ASYNC);
}
void keyboard(unsigned char key,int x,int y)
{
if(key=='1')Do.Play();//PlaySoundA("do.wav",NULL,SND_ASYNC);
if(key=='2')Re.Play();//PlaySoundA("re.wav",NULL,SND_ASYNC);
if(key=='3')Mi.Play();//PlaySoundA("mi.wav",NULL,SND_ASYNC);
if(key=='4')Fa.Play();//PlaySoundA("fa.wav",NULL,SND_ASYNC);
if(key=='5')So.Play();//PlaySoundA("so.wav",NULL,SND_ASYNC);
}
int main(int argc, char**argv) ///高手等級的main()
{
//myMP3.Load("on.mp3");
//myMP3.Play();
Do.Load("do.wav");
Re.Load("re.wav");
Mi.Load("mi.wav");
Fa.Load("fa.wav");
So.Load("so.wav");
glutInit(&argc,argv);///main的參數,於近來
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
///啟動3D的顯示能力,兩倍顯示buffer,有3D深度值
glutCreateWindow("week11");
///建立3D窗子
glutMouseFunc(mouse);///mouse函式
glutKeyboardFunc(keyboard);///mouse函式
glutDisplayFunc(display);
glutMainLoop();
///主要迴圈卡在這裡,不會結束
}


沒有留言:
張貼留言