2015年4月8日 星期三

#include <GL/glut.h>
#include <stdio.h>
void display()
{
    glutSolidTeapot(0.3);
    glFlush();
}
void keyboard(unsigned char key,int x,int y)
{
    if(key=='a'){printf("AAA\n");}
    else if(key=='b'){printf("BBB\n");}
}
int main (int argc,char **argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("vgsdghosdgjlof");
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMainLoop();
}

畫一個簡單的茶壺和寫出一些指令,如果輸入a,就會輸出AAA,如果輸入b,就會輸出BBB。
#include <GL/glut.h>
#include <mmsystem.h>
#include <stdio.h>
void display()
{
    glutSolidTeapot(0.3);
    glFlush();
}
void keyboard(unsigned char key,int x,int y)
{
    if(key=='a'){printf("AAA\n");}
    else if(key=='b'){printf("BBB\n");}
}
void mouse (int button,int state,int x,int y)
{
    printf("now playing sound");
    PlaySound("bubbs.wav",NULL,SND_ASYNC);
}
int main (int argc,char **argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("vgsdghosdgjlof");
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    glutMainLoop();
}

這次多插入個滑鼠指令,案圖片後會撥放我所設定的音效檔。
音效檔要要放在程式資料夾內,bin->Debug裡面,才會有聲音。

#include <GL/glut.h>
#include <mmsystem.h>
#include <stdio.h>
void display()
{
    glutSolidTeapot(0.3);
    glFlush();
}
void keyboard(unsigned char key,int x,int y)
{
    if(key=='1') PlaySound("Do.wav",NULL,SND_ASYNC);
    if(key=='2') PlaySound("RE.wav",NULL,SND_ASYNC);
    if(key=='3') PlaySound("Mi.wav",NULL,SND_ASYNC);
    if(key=='4') PlaySound("Fa.wav",NULL,SND_ASYNC);
    if(key=='5') PlaySound("Sol.wav",NULL,SND_ASYNC);
    if(key=='6') PlaySound("La.wav",NULL,SND_ASYNC);
    if(key=='7') PlaySound("Si.wav",NULL,SND_ASYNC);
}
void mouse (int button,int state,int x,int y)
{
    printf("now playing sound");
    PlaySound("bubbs.wav",NULL,SND_ASYNC);
}
int main (int argc,char **argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("vgsdghosdgjlof");
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    glutMainLoop();

用鍵盤控制想發啥聲音!!~

沒有留言:

張貼留言