2020年5月12日 星期二

weeeeeeeeeeek11

目標 : 播放 WAV 音檔

#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
int main()
{
    PlaySound("檔案.wav",NULL,SND_SYNC);
    printf("Hello World\n");
}

目標 : 點擊發出聲音

#include <stdio.h>
#include <windows.h>  //為了一些定義DWORD
#include <mmsystem.h>  //為了 PlaySoundA()
#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("Bomb.wav",NULL,SND_SYNC);
}

int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week11 sound");

    glutMouseFunc(mouse);  //mouse要發出聲音
    glutDisplayFunc(display);
    glutMainLoop();
}

目標 : 邊播放MP3邊點擊出聲音 (MP3)

1.在moodle下載CMP3_MCI.h直接放在專案檔
2.將mp3檔放在freeglut的lib裡面

程式碼 : 

#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("Bomb.wav",NULL,SND_SYNC);
}

int main(int argc,char**argv)
{
    myMP3.Load("Colorful.mp3");
    myMP3.Play();
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week11 sound");

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


沒有留言:

張貼留言