Step01-1 鍵盤
建GLUT專案 命名為week11-1_keyboard
#include <GL/glut.h>
void display()
{
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y)
{///step01-1今天新教的
if(key==27); exit(594088);
}
int main(int argc,char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week11");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);///step01-1今天新教的
glutMainLoop();
}
Step01-2 聲音
再建一個GLUT專案 命名為week11-2_keyboard_wav_PlaySound
#include <windows.h>
#include <GL/glut.h>
void display()
{
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y)
{///step01-1今天新教的
if(key=='1') PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\do.wav", NULL, SND_ASYNC);
if(key=='2') PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\re.wav", NULL, SND_ASYNC);
if(key=='3') PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\mi.wav", NULL, SND_ASYNC);
}
int main(int argc,char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week11");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);///step01-1今天新教的
glutMainLoop();
}
Step02-1
程式碼完成後PLAY 等待就會自動播放聲音
///week11-1_PlaySound.cpp不能執行因為找不到PlaySoundA
///OpenCV需3咒語 GLUT需5咒語 PlaySound需1咒語
///Setting-Compiler....的Linker Setting要加上winmm
#include <windows.h>
int main()
{ ///要等待同步 SND_SYNC 不然會瞬間結束
PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\do.wav", NULL, SND_SYNC);
PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\do.wav", NULL, SND_SYNC);
PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\do.wav", NULL, SND_SYNC);
PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\re.wav", NULL, SND_SYNC);
PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\mi.wav", NULL, SND_SYNC);
}
Step02-2
再創一個GLUT專案 命名為week11-4_GLUT_mp3 可播放MP3音樂
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
int main(int argc, char *argv[])
{
char filename[] = "C:/Users/Administrator/Desktop/do_re_mi/suzumi.mp3";
myMP3.Load(filename);
myMP3.Play();///step02-2播放
glutInit(&argc, argv);
glutInitWindowSize(640,480);
glutInitWindowPosition(10,10);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
Step03-1
用notepad修改week11-4_GLUT_mp3.cbp
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
int main(int argc, char *argv[])
{
///char filename[] = "C:/Users/Administrator/Desktop/do_re_mi/suzumi.mp3";
///myMP3.Load(filename);//絕對路徑 absolute path一定可運作但很長 且不能換電腦
myMP3.Load("suzumi.mp3");
myMP3.Play();///step02-2播放
glutInit(&argc, argv);
glutInitWindowSize(640,480);
glutInitWindowPosition(10,10);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
Step03-2
老師講解.gitignore的功用
在.gitignore裡面 要備份.dll檔案 所以要加上 # 不要擋它







沒有留言:
張貼留言