WEEK11
Step01-1
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y)
{
if(key==27) exit(1234);
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week11");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
會出現茶壺然後按下ESC鍵可以把視窗關掉
*key==27 就是ESC
Step01-2
按按鍵播出聲音
修改一下程式碼:
#include <windows.h>
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
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=='3') PlaySound("C:\\Users\\Administrator\\Desktop\\do-re-mi\\re.wav",NULL,SND_ASYNC);
if(key=='2') 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);
glutMainLoop();
}
按1、2、3會出現音效DO、RE、MI
Step02-1 WAV
把播放音效改成cpp播放
#include <windows.h>
#include <stdio.h>
int main()
{
PlaySound("C:\\Users\\Administrator\\Desktop\\do-re-mi\\do.wav",NULL,ASND_SYNC);
PlaySound("C:\\Users\\Administrator\\Desktop\\do-re-mi\\re.wav",NULL,ASND_SYNC);
PlaySound("C:\\Users\\Administrator\\Desktop\\do-re-mi\\mi.wav",NULL,ASND_SYNC);
printf("Hello World\n");
}
會慢慢地依序播放聲音 最後出現Hello World
#include <windows.h>
#include <stdio.h>
int main()
{
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);
///絕對路徑
PlaySound("do-re-mi/do.wav",NULL,SND_SYNC);///相對路徑
printf("Hello World\n");
}
Step02-2 MP3
重開一個GLUT專案檔
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
int main(int argc, char *argv[])
{
char filename[]="C:/Users/Administrator/Desktop/do-re-mi/音樂名稱.mp3";
myMP3.Load(filename);
myMP3.Play();
這樣就可以播放mp3音樂
Step03-1 MP3相對路徑
Project>Properties
Build targets> Execution working dir:[.] 把裡面路徑改成.
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
int main(int argc, char *argv[])
{
myMP3.Load(filename.mp3);
myMP3.Play();
要把音樂檔案放進去專案檔裡面
把freeglut >bin >freeglut.dll的檔案也放進去專案檔裡面
Step03-2
安裝git 開啟GIT bash
cd desktop 進入桌面
git clone 複製你的檔案
*用Notepad++開啟
把*.dll註解掉
cd 進入你的檔案
git add . 加入你的檔案
git status 確認你的檔案
git config --global user.email 你的Gmail
git config --global user.name 你的GitHubID
git commit -m "你的周次"
git push 上傳
結束
沒有留言:
張貼留言