2020年5月12日 星期二

Week12_LSD's HW

http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/?fbclid=IwAR1bAdfPT6Q5nJQXk1XZ9IFGFHoRPs8cCZyFqYKliBXu4SnuSIjz_siYPPg
1.先有聲音後有HelloWorld

2.按滑鼠就有聲音
#include <GL/glut.h>
#include <windows.h>
#include <mmsystem.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glutSwapBuffers();
}
void mouse(int button,int state,int x,int y)
{
    if(state==GLUT_DOWN) PlaySoundA("bb.wav",NULL,SND_SYNC);
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
    glutCreateWindow("Week12 sound");

    glutMouseFunc(mouse);
    glutDisplayFunc(display);
    glutMainLoop();

}
3.播放背景音樂

#include <GL/glut.h>
#include <windows.h>
#include <mmsystem.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glutSwapBuffers();
}
void mouse(int button,int state,int x,int y)
{
    if(state==GLUT_DOWN) PlaySoundA("bb.wav",NULL,SND_SYNC);
}
int main(int argc, char**argv)
{
    myMP3.Load("bgm_01.mp3");
    myMP3.Play();
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
    glutCreateWindow("Week12 sound");

    glutMouseFunc(mouse);
    glutDisplayFunc(display);
    glutMainLoop();

}
*void mouse(int button,int state,int x,int y)

{
    ///if(state==GLUT_DOWN) PlaySoundA("bb.wav",NULL,SND_SYNC);同步
    if(state==GLUT_DOWN) PlaySoundA("bb.wav",NULL,SND_ASYNC);///不同步
}
4.鍵盤鋼琴

#include <GL/glut.h>
#include <windows.h>
#include <mmsystem.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
CMP3_MCI Do, Re, Mi, Fa, So;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glutSwapBuffers();
}
void keyboard(unsigned char key,  int x, int y)
{
    if(key=='1') Do.Play();///PlaySoundA("do.wav", NULL, SNC_ASYNC);
    if(key=='2') Re.Play();///PlaySoundA("re.wav", NULL, SNC_ASYNC);
    if(key=='3') Mi.Play();///PlaySoundA("mi.wav", NULL, SNC_ASYNC);
    if(key=='4') Fa.Play();///PlaySoundA("fa.wav", NULL, SNC_ASYNC);
    if(key=='5') So.Play();///PlaySoundA("so.wav", NULL, SNC_ASYNC);
}
void mouse(int button,int state,int x,int y)
{
    ///if(state==GLUT_DOWN) PlaySoundA("bb.wav",NULL,SND_SYNC);同步
    if(state==GLUT_DOWN) PlaySoundA("bb.wav",NULL,SND_ASYNC);///不同步
}

int main(int argc, char**argv)
{
    Do.Load("do.wav");Re.Load("re.wav");Mi.Load("mi.wav");Fa.Load("fa.wav");So.Load("so.wav");
    myMP3.Load("bgm_01.mp3");
    ///myMP3.Play();
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
    glutCreateWindow("Week12 sound");
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    glutDisplayFunc(display);
    glutMainLoop();

}

沒有留言:

張貼留言