2023年4月26日 星期三

電腦圖學week11

 week11keyboard

用鍵盤關閉小黑視窗

#include <GL/glut.h>

void display()

{

    glutSolidTeapot(0.3);

    glutSwapBuffers();

}

void keyboard(unsigned char key,int x, int y)

{

    if(key==27) exit(0);

}

int main(int argc,char**argv)

{

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH)

    glutCreateWindow("week11")

    glutDisplayFunc(display);

    glutKeyboardFunc(keyboard);

    glutMainLoop();

}

撥放音樂do rre mi

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

直接撥放音樂
#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);
}
要在setting-compiler的linker-setting加上winmm
SYNC與ASYNC的差別在於撥放後的等待
絕對路徑與相對路徑皆可撥放

#include <windows.h>

int main()

{

    PlaySound("do_re_mi\\do.wav", NULL, SND_SYNC);

    PlaySound("do_re_mi\\do.wav", NULL, SND_SYNC);

    PlaySound("do_re_mi\\do.wav", NULL, SND_SYNC);

    PlaySound("do_re_mi\\re.wav", NULL, SND_SYNC);

}

MP3撥放
把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();



/或\\都可以撥放




沒有留言:

張貼留言