2023年4月27日 星期四

jason week11

1-1

新增一個專案week11-1_keyboard
在程式碼裡找keyboard
找glutKeyBoard(keyboard)


#include<GL/glut.h>
 void display()
 {
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glutSolidTeapot(0.3);
    glutSwapBuffers();
 }
 void keyboard(unsigned char key ,int x,int y)
 {
    if(key==27)exit(1234);
 }
 int main(int argc,char**argv)
 {
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week11");

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);

    glutMainLoop();
 }



1-2

再結合播放音樂,新增專案week11-2_keyboard_PlaySound
#include<windows.h>
#include<GL/glut.h>
 void display()
 {
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    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();
 }
按下數字1會出現do的聲音,2是re,3是mi



2-1

縮短路徑
PlaySound("C:\\Users\\Administrator\\Desktop\\do-re-mi\\do.wav",NULL,SND_ASYNC);
改成
PlaySound("do-re-mi/do.wav",NULL,SND_SYNC);



2-2

新增專案week11-4_CMP3_MCI_LOAD_PLAY
不改變原本的程式碼,新增圖2框起來的程式碼




3-1

註解char filename[]="C:/Users/Administrator/Desktop/do-re-mi/suzume.mp3";
新增myMP3.Load("suzume.mp3");
把下載的音樂跟freeglut-bin-freeglut.dll放到專案4
去project-properties-build target把excution working dir位置縮減成小數點   .

3-2

第4個專案裡, .dll檔因為gitignore會把它忽略,所以去2023graphicsb裡的gitignore用notepad++修改,把.dll註解調(打#)



沒有留言:

張貼留言