2023年4月26日 星期三

:/ week11

使用按鍵結束程式

開新的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);///27=Esc

}

int main(int argc,char**argv)

{

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);

    glutCreateWindow("week11");


    glutDisplayFunc(display);

    glutKeyboardFunc(keyboard);


    glutMainLoop();


用按鍵發出聲音

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

}


開新的空白檔案
把 setting-compiler 的 linker setting 加上 winmm 
#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);
}

glut_mp3播放音樂
把CMP3_MCI.h檔案放到GLUT專案目錄裡
在137行左右加入
絕對路徑版 一定可運作但很長且不能換電腦
#include "CMP3_MCI.h"
CMP3_MCI myMP3;

char filename[]="C:/Users/Administrator/Desktop/do_re_mi/suzumi.mp3";
    myMP3.Load(filename);
    myMP3.Play();
相對路徑版 
///char filename[]="C:/Users/Administrator/Desktop/do_re_mi/suzumi.mp3";
    myMP3.Load("suzumi.mp3");
    myMP3.Play();
把suzumi.mp3跟freeglut.dll放入資料夾
開啟notepad++把<Option working_dir="C:/Users/Administrator/Desktop/freeglut/bin" />改成<Option working_dir="." />





沒有留言:

張貼留言