今天是聲音喔喔喔喔
一開始要做的是播出聲音
先把freeglut的檔案開起來
然後把main.cpp的程式都刪掉
打上這個
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
int main()
{
PlaySoundA("bubbs.wav",NULL, SND_SYNC);
printf("hello world\n");
}
再來 去網路上搜尋wav download
你就會找到很多音檔喔
下載一個你喜歡的
記得丟到freeglut的bin裡面
取一個你喜歡的名字
然後呢!!!
執行之後就會有聲音了喔~
接下來 我們改改程式碼
讓他變成滑鼠點一下就發出聲音
#include <stdio.h>
#include <GL/glut.h>
#include <windows.h>///定義DWORD
#include <mmsystem.h>///為了PlaySoundA
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
void mouse(int button , int state, int x, int y) ///todo2 用滑鼠發出聲音
{
if(state==GLUT_DOWN) PlaySoundA("hi.wav",NULL,SND_SYNC);
}
int main(int argc , char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week11Sound");
glutMouseFunc(mouse); ///todo2 用滑鼠發出聲音
glutDisplayFunc(display);
glutMainLoop();
}
點擊就會有啵啵啵喔(我的啵啵啵啦看你的是什麼)
再來

沒有留言:
張貼留言