下載Do Re Mi.wav
解壓縮

打開貝殼專案

打以下程式碼
#include <iostream>
#include <windows.h>
#include <mmsystem.h>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
PlaySoundA("Do.wav",NULL,SND_SYNC);
PlaySoundA("Re.wav",NULL,SND_SYNC);
PlaySoundA("Mi.wav",NULL,SND_SYNC);
return 0;
}

新增右鍵winmm

將壓縮完的音樂檔放到Code Blocks資料夾裡

執行會播出音樂Do Re Mi

課堂作業二
一樣點開貝殼專案
在Build Options加入咒語

把freeglut移到桌面 新增以下


打上程式碼
#include <GL/glut.h>
#include <windows.h>
#include <mmsystem.h>
void display()
{
}
void keyboard(unsigned char key, int x, int y)
{
if(key=='1')PlaySoundA("Do.wav", NULL, SND_ASYNC);
if(key=='2')PlaySoundA("Re.wav", NULL, SND_ASYNC);
if(key=='3')PlaySoundA("Mi.wav", NULL, SND_ASYNC);
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("3D and Sound");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

把freeglut.dll移到專案資料夾裡

執行結果

沒有留言:
張貼留言