week11
step01-1
新增GLUT專案 week11-1_keyboard
修改feeglut
找到keyboard函式
程式碼全刪
改為
#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();
}
step01-2
新增專案 week11-2_keyboard_PlaySound
把week11-1_keyboard的程式複製到 week11-2_keyboard_PlaySound
程式碼改成
#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();
}
按1,2,3會有do,re,mi的聲音
step02-1
開新的程式 week11-3_PlaySound
不用開GLUT專案
#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);
printf("Hello World\n");
}
修改
Setting
compiler
在linker settings 加入 winmm
可以修改成
#include <windows.h>
#include <stdio.h>
int main()
{
///絕對路徑 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);
///相對路徑 Relative Path
printf("Hello World\n");
}
step02-2
新增GLUT專案
播出mp3
week11-4_CMP3_Load_Play
把CMP3_MCI.h 丟進 week11-4_CMP3_Load_Play 專案
修改程式碼
在137行加入
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
在143行加入
char filename[] = "C:/Users/Administrator/Desktop/do-re-mi/suzume.mp3";
myMP3.Load(filename);
myMP3.Play();
step03-1
更改工作執行目錄
打開Project
選擇properties
選擇Build targets
把Execution working dir: 改成 .
把freeglut的bin裡的freeglut.dll 丟到專案裡
並寫把mp3檔丟到專案裡
修改程式碼
第141行
///char filename[] = "C:/Users/Administrator/Desktop/do-re-mi/suzume.mp3";
///myMP3.Load(filename);
myMP3.Load("suzume.mp3");
step03-2
專案裡有 mp3檔和.dll檔
但Git會忽略.dll
導致無法備份
先用git指令叫出2023graphicsb
打開2023graphicsb裡的gitignore
用Notepad++打開
在.dll前面加#把它註解掉
然後用git上傳github























沒有留言:
張貼留言