2020年5月12日 星期二

week11 聲音

有聲音

一樣打開code 新增GLUT5專案
把原本程式全部刪除 打上老師給的程式碼
去網路下載 聲音WAV檔 存到bin裡

程式碼:
#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("chaha.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();
}

加入MP3檔

#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
#include <GL/glut.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("chaha.wav",NULL,SND_SYNC);
}
int main(int argc,char**argv)
{
    myMP3.Load("muic.mp3");
    myMP3.Play();
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week12 sound");

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

將檔案丟入week資料夾內


彈奏音樂了

#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
#include <GL/glut.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
CMP3_MCI Do Re Mi Fa So;
void display()
{
void keybord(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();
}
    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("chaha.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("muic.mp3");
    ///myMP3.Play();
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week12 sound");

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

沒有留言:

張貼留言