2020年5月12日 星期二

week12

今天學習如何加入聲音

先開啟一個GLUT專案,然後全部刪除,接著輸入以下程式碼


--------------------------------------------------------------------------------------------------------------------------

#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
int main()
{
    PlaySoundA("bscream.wav",NULL, SND_SYNC);
    printf("Hello World");
}

--------------------------------------------------------------------------------------------------------------------------

作業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("bscream.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();
}

-------------------------------------------------------------------------------------------------------------------------

加入背景音樂



--------------------------------------------------------------------------------------------------------------------------

#include <stdio.h>
#include <windows.h>///為了定義DWORD ⼀定要放在playsound上⾯
#include <mmsystem.h>///為了PlaySoundA()
#include <GL/glut.h>
#include "CMP3_MCI.h" ///雙引號 表⽰在同⼀個傳案⽬錄裡找
CMP3_MCI myMP3; ///宣告⼀個物件變數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("bscream.wav",NULL,SND_SYNC);
}
int main(int argc, char**argv)
{
 myMP3.Load("07161090.mp3"); ///讀入檔案
 myMP3.Play();///播放
 glutInit(&argc,argv);
 glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
 glutCreateWindow("Week12 Sound");
 glutMouseFunc(mouse);
 glutDisplayFunc(display);
 glutMainLoop();
}

沒有留言:

張貼留言