2021年4月28日 星期三

電腦圖學week10

 先匯入音檔 丟到freeglut的bin



撥放音樂


輸入數字 撥放音樂





播放背景音樂


加入滑鼠點擊音效





#include <windows.h>
#include <GL/glut.h>
#include "CMP3_MCI.h"
CMP3_MCI mp3;
CMP3_MCI shot1,shot2,shot3;

void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glutSolidTeapot(0.3);
    glutSwapBuffers();
}

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("so.wav",NULL,SND_ASYNC);
}

void mouse(int button, int state, int x, int y)
{
    if(state==GLUT_DOWN&&button==GLUT_LEFT_BUTTON)shot1.Play();
    if(state==GLUT_DOWN&&button==GLUT_MIDDLE_BUTTON)shot2.Play();
    if(state==GLUT_DOWN&&button==GLUT_RIGHT_BUTTON)shot3.Play();

}

int main(int argc,char** argv)
{
    shot1.Load("1.wav"); shot2.Load("2.wav"); shot3.Load("3.wav");
    mp3.Load("music.mp3");
    mp3.Play();
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week10 Sound");
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    glutMainLoop();
}

沒有留言:

張貼留言

距地表面160 Week11

 #include "glm.h" GLMmodel* pmodel = NULL; void drawmodel(void) {     if (!pmodel) { pmodel = glmReadOBJ("data/porsche.obj...