2023年5月30日 星期二

week11 鍵盤滑鼠

 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();

}



再開一個新專案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);

}





Linker Settings->Add->新增winmm 後重開CodeBlock
由絕對路徑變成相對路徑

再開一個新專案 week11-4_glut_mp3
執行後會播放音樂
#include "CMP3_MCI.h"
CMP3_MCI myMP3;

int main(int argc, char *argv[])
{
    char filename [] ="C:/Users/Administrator/Desktop/do_re_mi/suzumi.mp3";
    myMP3.Load(filename);

    myMP3.Play();

將week11-4_glut_mp3資料夾中的week11-4_glut_mp3.cbp檔案用nopad++打開

11&21行改為"."

將freeglut->bin->freeglut.dll拉到week11-4_glut_mp3內
do_re_mi->suzumi.mp3拉到week11-4_glut_mp3內

1.在.gitignore 裡面,要備份 .dll 檔案,所以要加上 # 不要擋他
2.因為我們希望也備份 libfreeglut.dll 以及 opencv的 .dll 才能讓程式執行

步驟:
1.先clone 再編輯 .gitigonre
2.整理今天程式碼的4個程式
3.git add .
4.git commit -m week11 (之前要git config --global 設定2個東西)
5.git push

沒有留言:

張貼留言