#include <GL/glut.h>
void display()
{
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y)
{
if(key==27) exit(12345); ///按esc就會結束
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week11");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
123鋼琴
#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);
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week11");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
#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);
}
///改用SND_SYNC要等待同步,以免程式瞬間結束
撥放音樂
#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.Play();
打開week11-4_glut_mp3.cbp的Notepad++將路徑改成"."
int main(int argc, char *argv[])
{
///char filename[]="C:/Users/Administrator/Desktop/do_re_mi/suzumi.mp3"; ///註解掉,絕對路徑可以運作,很長,不能換電腦
myMP3.Load("suzumi.mp3"); ///相對路徑
myMP3.Play();



沒有留言:
張貼留言