2020年5月12日 星期二

week11

今天交了可以把音樂放出來,用了wav
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
int main()
{
    PlaySound("bong.wav",NULL, SND_SYNC);這邊的bong.wav要把它放在freeglut-bin裡
    printf("Hello World\n");
}
用完以上的步驟就可以發出聲音
接下來是點著黑色的小一木會發出聲音
程式碼
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
#include <GL/glut.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("bong.wav",NULL,SND_SYNC);
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
    glutCreateWindow("week11 sound");
    glutMouseFunc(mouse);
    glutDisplayFunc(display);
    glutMainLoop();
    ///PlaySound("bong.wav",NULL, SND_SYNC);
    ///printf("Hello World\n");
}
接下來交可以把mp3黨也放進去一起撥放
#include "CMP3_MCI.h"
#include <windows.h>
#include <mmsystem.h>
#include <GL/glut.h>///todo3
CMP3_MCI myMP3;///todo3
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("bong.wav",NULL,SND_SYNC);
}
int main(int argc, char**argv)
{
    myMP3.Load("bgm_01.mp3");///todo3///mp3黨也要放在bin裡
    myMP3.Play();///todo3
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
    glutCreateWindow("week11 sound");
    glutMouseFunc(mouse);
    glutDisplayFunc(display);
    glutMainLoop();
    ///PlaySound("bong.wav",NULL, SND_SYNC);
    ///printf("Hello World\n");
}
最後一個不錯玩,他可以用出鋼琴的聲音
#include "CMP3_MCI.h"
#include <windows.h>
#include <mmsystem.h>
#include <GL/glut.h>///todo3
CMP3_MCI myMP3;///todo3
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();
    if(key=='2') Re.Play();
    if(key=='3') Mi.Play();
    if(key=='4') Fa.Play();
    if(key=='5') So.Play();
}
void mouse(int button, int state, int x, int y)///
{
    if(state==GLUT_DOWN)PlaySoundA("bong.wav",NULL,SND_SYNC);
}
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");///todo3
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
    glutCreateWindow("week11 sound");
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    glutDisplayFunc(display);
    glutMainLoop();
    ///PlaySound("bong.wav",NULL, SND_SYNC);
    ///printf("Hello World\n");
}

沒有留言:

張貼留言