我應該是第11周吧
一開始一樣freeglut載下來打開codeblocks再把程式碼全部刪掉
再從網路上再wav檔就有聲音檔了,再把wav檔放到freeglut裡的bin就好了
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
int main()
{
PlaySoundA("UZI.wav",NULL, SND_SYNC);
printf("Hello World\n");
}
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
int main()
{
PlaySoundA("UZI.wav",NULL, SND_SYNC);
printf("Hello World\n");
}
接下來案黑視窗會有聲音
再來再來就是把bgm也放到裡面去
要先把CMP3_MCI.h放到專案檔裡再把bgm放到freeglut的bin裡面就可以播放了
ps:bgm要自己載
#include <GL/glut.h>
#include <windows.h>
#include <mmsystem.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("UZI.wav",NULL, SND_SYNC);
}
int main(int argc, char**argv)
{
myMP3.Load("bgm.mp3");
myMP3.Play();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week12 sound");
glutMouseFunc(mouse);
glutDisplayFunc(display);
glutMainLoop();
}
背景音樂可選擇同步
#include <GL/glut.h>
#include <windows.h>
#include <mmsystem.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("UZI.wav",NULL, SND_ASYNC);//等他播完,同步
if(state==GLUT_DOWN) PlaySoundA("UZI.wav",NULL, SND_ASYNC);//不等他,不同步
}
int main(int argc, char**argv)
{
myMP3.Load("bgm.mp3");
myMP3.Play();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week12 sound");
glutMouseFunc(mouse);
glutDisplayFunc(display);
glutMainLoop();
}
檔案可以存在自己的專案檔
首先用notepad++開啟07160564.cbp檔再把儲存路徑改成.
再把freeglut裡bin的
這個複製放到自己的檔案就可以了
最後電子琴
#include <stdio.h>
#include <GL/glut.h>
#include <windows.h>///定義DWORD
#include <mmsystem.h>///為了PlaySoundA
#include "CMP3_MCI.h" ///TODO3 : 雙引號,要在同一個專案目錄找
CMP3_MCI myMP3; ///TODO3:宣告一個物件變數myMP3
CMP3_MCI Do, Re, Mi, Fa, So; ///TODO5
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
void keyboard(unsigned char key, int x ,int y)
{ ///TODO5
if(key=='1') Do.Play();
if(key=='2') Re.Play();
if(key=='3') Mi.Play();
if(key=='4') Fa.Play();
if(key=='5') So.Play();
}
void mouse(int button , int state, int x, int y)
{
if(state==GLUT_DOWN) PlaySoundA("hi.wav",NULL,SND_ASYNC);
}
int main(int argc , char**argv)
{
Do.Load("do.wav");Re.Load("re.wav");Mi.Load("mi.wav")
Fa.Load("fa.wav");So.Load("so.wav") ///TODO5
myMP3.Load("bgm.mp3");///TODO3:讀入檔案 要放在執行目錄(bin)
myMP3.Play(); ///TODO3:播放
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week11Sound");
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
glutKeyboardFunc(keyboard);
glutDisplayFunc(display);
glutMainLoop();
}








沒有留言:
張貼留言