Week11_鍵盤、滑鼠、音樂
開啟CodeBlock GLUT專案命名week11-1_KeyBoard (鍵盤
#include <GL/glut.h>
void display()
{
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{
if(key==27) exit(594088);
}
int main(int argc,char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week11");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);///今天新教的
glutMainLoop();
}
按下Esc結束就會回傳值開新專案命名week11-2_keyboard_wav_PlaySound (音樂
#include <windows.h>
#include <GL/glut.h>
void display()
{
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{///step01-1今天教的 step01-2音樂檔,先用絕對路徑,要小心\\代表1個反斜線
if(key=='1') PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\do.wav",NULL,SND_ASYNC);
if(key=='2') PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\re.wav",NULL,SND_ASYNC);
if(key=='3') PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\mi.wav",NULL,SND_ASYNC);
}
int main(int argc,char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week11");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
執行按鍵盤1,2,3可以發出聲音
重開codeblock->File->New->Empty File 命名為week11-3_PlaySound.cpp
#include <windows.h>
int main()
{ ///要等待同步 SND_ASYNC
PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\do.wav", NULL,SND_SYNC);
PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\re.wav", NULL,SND_SYNC);
PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\mi.wav", NULL,SND_SYNC);
}
沒有留言:
張貼留言