🚽🛁🍦第12週🍧🍨🎀
1😈打開codeblocks->將main函式清空
輸入以下程式碼:
int main()
{
PlaySoundA("Queen.wav",NULL,)
printf("Hello World\n");
}
2😈 複製以前的程式碼,刪除部必要的部分
3😈 設定點擊滑鼠後發出聲音
glutMouseFunc(mouse);
4😈 CMP3_MCI 拉入codeblocks檔案資料夾內
5😈 把音樂拉 freeglut->bin資料夾內
(wav、mp3)
6😈 只要執行就會"同步"播出背景音樂
程式碼:
#include <stdio.h>
#include <windows.h>///為了定義dword
///不能放下面,要在前面
#include <mmsystem.h>///playsoundA
#include <GL/glut.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;///宣告一個物件變數
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
void mouse(int button,int state,int x,int y)
{
if(state==GLUT_DOWN) PlaySoundA("abc.wav",NULL,SND_SYNC);
}
int main(int argc, char **argv)
{
myMP3.Load("abc.mp3");///讀入檔案
myMP3.Play();///播放背景音樂
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week12");
glutMouseFunc(mouse);///點擊後會發出聲音
glutDisplayFunc(display);
glutMainLoop();
}
7😈 不同步播放背景音樂(不等待直接播)
if(state==GLUT_DOWN) PlaySoundA("abc.wav",NULL,SND_ASYNC);///加A=不同步
}
😳 播放音樂+彈鋼琴ᐇ 😳
8😈 滑鼠要放在小黑窗上才能彈出美妙的音樂
以下為程式碼:
#include <stdio.h>
#include <windows.h>///為了定義dword
///不能放下面,要在前面
#include <mmsystem.h>///playsoundA
#include <GL/glut.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;///宣告一個物件變數
CMP3_MCI Do ,Re ,Mi ,Fa ,Sol;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y)
{
if(key=='1') Do.Play();
if(key=='2') Re.Play();
if(key=='3') Mi.Play();
if(key=='4') Fa.Play();
if(key=='5') Sol.Play();
}
void mouse(int button,int state,int x,int y)
{
if(state==GLUT_DOWN) PlaySoundA("abc.wav",NULL,SND_ASYNC);///加A=不同步
}
int main(int argc, char **argv)
{
Do.Load("do.wav");Re.Load("re.wav");Mi.Load("mi.wav");
Fa.Load("fa.wav");Sol.Load("sol.wav");
myMP3.Load("abc.mp3");///讀入檔案
myMP3.Play();///播放背景音樂
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week12");
glutMouseFunc(mouse);///點擊後會發出聲音
glutKeyboardFunc(keyboard);
glutDisplayFunc(display);
glutMainLoop();
}
end








沒有留言:
張貼留言