電腦圖學 2023-04-26 Week11
1. 主題: 鍵盤2. 主題: 聲音
3. 主題: 滑鼠、轉動
4. 補充: 工作執行目錄
Week11-1 鍵盤
1.開GLUT專案
#include <GL/glut.h>
void display()
{
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{
if(key==27) exit(0);//關掉
}//按ESC鍵關掉
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week11");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
用 void keyboard(), 呼叫 exit(0) 程式就結束,並return 0
2.出現茶壺圖片後按下ESC,測試是否關閉
Week11-2 音樂
1.想要播放音樂,建立一個新的專案11-2
2.程式碼:
#include <windows.h>
#include <GL/glut.h>
{
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y)
{
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();
}
3. 執行結果(出現茶壺圖案,按數字鍵1、2、3,會出現Do,Re,Mi的聲音)
Week11-3 音樂自動撥放
1. 建立新的File並取名為week11-3_PlaySound.cpp
2. 加入程式碼
#include <windows.h>
int main()
{
PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\do.wav",NULL,SND_SYNC);
PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\do.wav",NULL,SND_SYNC);
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);
}無法成功執行3. 在Setting--Compiler的Linker Setting加上winmm,因為實際上PlaySound是在winmm的函式庫裡4. 執行結果(會依序撥放音檔,結束並停止)
1. 建立新的File並取名為week11-4_glut_mp3
2. 加入幾行程式碼,修改成以下樣子
沒有留言:
張貼留言