2023年4月27日 星期四

逃離電腦圖學 Week11

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

案ESC鍵會回傳離開

改變上面數字 回傳的數字也會不同



week11-2_keyboard_PlaySound

#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);
    if(key=='4') PlaySound("C:\\Users\\Administrator\\Desktop\\do-re-mi\\fa.wav",NULL,SND_ASYNC);
    if(key=='5') PlaySound("C:\\Users\\Administrator\\Desktop\\do-re-mi\\so.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();
}




week11-3_PlaySound

#include <windows.h>
#include <stdio.h>
int main()
{
    PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\do.wav", NULL, SND_SYNC);//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);
    PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\fa.wav", NULL, SND_SYNC);
    PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\so.wav", NULL, SND_SYNC);
    printf("Hello World");
}


若無法執行Linker Setting加上winmm

week11-4_glut_mp3

新建專檔後 程式碼留下 在137行新增
#include "CMP3_MCI.h"
CMP3_MCI myMP3;

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

更改工作執行目錄
再把音檔跟freeglut.dll丟進去
改這兩行
一樣可以執行









沒有留言:

張貼留言