WEEK11
STEP01-1 新開GLUT專案 week11-1_keyboard 27是ESC的特殊鍵
if ( key == 27 ) exit(0); 離開
程式碼
#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);///step01-1
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week11");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
STEP01-2 新開專案 week11-1_keyboard_PlaySound
下載三種音樂程式 mp3 wav(較簡單可以撥放)
按數字鍵可以播聲音
程式碼
#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 == '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);
glutMainLoop();
}
STEP02-1 利用絕對路徑 不用GLUT 加入PRINTF發出聲音
兩條反斜線
程式碼
#include<windows.h>
#include<stdio.h>
int main()
{///Setting-Complier Linker 咒語 需要winmm
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);
printf("Hello World\n");
}
STEP02-1 利用相對路徑 搭配一個斜線 播音樂
#include<windows.h>
#include<stdio.h>
int main()
{///Setting-Complier Linker 咒語 需要winmm
///絕對路徑 Absolute Path
///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檔
step03-1 要解決歷史餘毒 就是working_dir 工作執行目錄
把freeglut bin裡面的freeglut.dll複製到 專案同一個目錄 再把聲音檔suzume.mp3也放在同一個目錄裡 最後把project-properties 裡面的bulid targets 的工作執行目錄 working dir 改成小數點
代表同一個目錄
step03-2 現在專案目錄裡 有mp3 dll檔 GIT無法上傳
因為gitignore會把 .dll檔忽略
要把 .dll 備份 才不會錯 # *.dll
github上傳
0. 安裝Git 開啟 Git Bash
- 1. cd desktop 進入桌面 git clone https://網址 再 cd 2023graphicsb
- 2. start . 開檔案總管,把今天的2個程式加進去
- 3. git add . 加入帳冊
- 4.0. git config --global user.email jsyeh@mail.mcu.edu.tw
- 4.0. git config --global user.name jsyeh
- 4.1. git commit -m week08
- 5. git push









沒有留言:
張貼留言