2020年5月12日 星期二

week12

裝好把wav檔放到freeglut-bin裡

滑鼠按發出聲音程式碼
#include <GL/glut.h>
#include <windows.h>///定義DWORD
#include <mmsystem.h>///為了PlaySoundA()
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glutSwapBuffers();
}
void mouse(int button,int state,int x,int y)
{///todo2:mouse要發出聲音
    if(state==GLUT_DOWN)PlaySound("rocket.wav",NULL,SND_SYNC);
}
int main(int argc,char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week12");
    glutMouseFunc(mouse);///todo2:mouse要發出聲音
    glutDisplayFunc(display);
    glutMainLoop();
}
moodle下載cmp3檔放到專案目錄
放背景音MP3的程式碼
#include <GL/glut.h>
#include <windows.h>///定義DWORD
#include <mmsystem.h>///為了PlaySoundA()
#include "CMP3_MCI.h"///todo3:宣告一個物件的變數 mymp3
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)
{///todo2:mouse要發出聲音
    if(state==GLUT_DOWN)PlaySound("rocket.wav",NULL,SND_SYNC);
}
int main(int argc,char**argv)
{
    myMP3.Load("123.mp3");///todo3:讀入檔案
    myMP3.Play();///todo3: 播放
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week12");
    glutMouseFunc(mouse);///todo2:mouse要發出聲音
    glutDisplayFunc(display);
    glutMainLoop();
}
用五個案件打音符

#include <GL/glut.h>
#include <windows.h>///定義DWORD
#include <mmsystem.h>///為了PlaySoundA()
#include "CMP3_MCI.h"///todo3:宣告一個物件的變數 mymp3
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)
{///todo5
    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)
{///todo2:mouse要發出聲音
    if(state==GLUT_DOWN)PlaySound("rocket.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");///todo5
    myMP3.Load("12.mp3");///todo3:讀入檔案
    myMP3.Play();///todo3: 播放
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week12");
    glutMouseFunc(mouse);///todo2:mouse要發出聲音
    glutKeyboardFunc(keyboard);///todo5
    glutDisplayFunc(display);
    glutMainLoop();
}


沒有留言:

張貼留言