Step01-1 鍵盤程式
開啟codeblock 開啟一個GLUT專案 檔名week11-1_keyboard在原本茶壺的程式上再加上keyboard相關程式
#include <GL/glut.h>
void display()
{
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void keyboard(unsigned char key, int x,int y)
{
if(key==27)exit(0);
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week11");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
Step01-2 聲音程式
開啟一個新GLUT專案 檔名week11-2_keyboard_wav_PlaySound
複製week11-1_keyboard程式
#include<windows.h>///放最上面
#include <GL/glut.h>
void display()
{
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void keyboard(unsigned char key, int x,int y)
{
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);
}2個斜線=1個斜線
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week11");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
開啟後有聲音即為成功
Step02-1 聲音程式
先把剛剛的GLUT專案save everything重開codeblock
File-New-Empty 存成week11-3_PlaySound.cpp
之後在開頭打上
#include<windows.h>
接著打
int main()
{
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);
}
然後打開Setting-Compiler -> add winmm -ok
OpenCV要3咒語
GLUT要5咒語
PlaySound要1咒語
Step02-1.5筆記對自身的重要性
筆記的好處,使用HackMD作筆記,觀看老師介紹Feetcode程式筆記
Step02-2 MP3音樂程式
開啟的GLUT專案 名稱week11-4_glut_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.Load("檔名.mp3");
myMP3.Play();
執行會播放音樂Step03-1絕對路徑 相對路徑
#include"CMP3_MCI.h"
CMP3_MCI myMP3;
int main(int argc, char *argv[])
{
myMP3.Load("suzumi.mp3");
myMP3.Play();
}
沒有留言:
張貼留言