2023年4月26日 星期三

Deverra//week11鍵盤

 

WEEK11
-----------------------------------------------------------------------------------------------------------------------------
▧第一個程式


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


---------------------------------------------------------------------------------------------------------------------------
▧第二個程式--用wav加入音樂

#include <windows.h>
#include <GL/glut.h>
void display()
{
    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();
}

得到了可以用鍵盤123彈出Do Re Mi的程式

---------------------------------------------------------------------------------------------------------------------------
▧第三個程式--不加鍵盤也能讓他自己播音樂

在Setting-Compiler中的Linker Settings裡加上winmm咒語

#include <windows.h>
int main()
{                                                                                          //與ASYNC不同,A會在音樂出來前就結束
    PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\do.wav",NULL,SND_SYNC);
    PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\mi.wav",NULL,SND_SYNC);
    PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\re.wav",NULL,SND_SYNC);
}                                                                                                               //SND_SYNC要等待同步


---------------------------------------------------------------------------------------------------------------------------
▧第四個程式---MP3

新增一個GLUT專案,直接在專案裡新增程式碼
在128行前main函式前加入
把檔案拖入專案目錄

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





加入新的外掛程式碼

得到會播放SUZUME的程式

用相對路徑來做,不會這麼混亂
到檔案總管中找到suzume音檔,用notepad++打開
把地址改成小貓點點"."

1--用Notepad++打開
2--在11行格21行中改地址為"."


先把音檔加入到工作執行目錄裡面

再加入一個freeglut.dll檔


/* Program entry point */
#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.Load("suzumi.mp3");///相對路徑
    myMP3.Play();

    glutInit(&argc, argv);
    glutInitWindowSize(640,480);
    glutInitWindowPosition(10,10);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("GLUT Shapes");






沒有留言:

張貼留言