1-1
新增一個專案week11-1_keyboard
在程式碼裡找keyboard
找glutKeyBoard(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();
}
再結合播放音樂,新增專案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會出現do的聲音,2是re,3是mi
縮短路徑
PlaySound("C:\\Users\\Administrator\\Desktop\\do-re-mi\\do.wav",NULL,SND_ASYNC);
改成
PlaySound("do-re-mi/do.wav",NULL,SND_SYNC);
註解char filename[]="C:/Users/Administrator/Desktop/do-re-mi/suzume.mp3";
新增myMP3.Load("suzume.mp3");
把下載的音樂跟freeglut-bin-freeglut.dll放到專案4
去project-properties-build target把excution working dir位置縮減成小數點 .
沒有留言:
張貼留言