WEEK11
week11-1 keyboard
新增一個glut專案,打上程式後,會顯示茶壺
#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
老師先傳一個聲音檔給我們,桌面上會有do-re-mi的檔案,再來複製貼上第一個程式後修改程式,按1 2 3 就會有do-re-mi的聲音
#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();
}
week11-3 PlaySound.cpp
開啟一個CPP檔,用Hello World播放do-re-mi,到Settings-Compiler裡設定Linker settings打上winmm
#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");
}
week11-4_CMP3_MCI_Load_Play
老師先傳MP3檔給我們,開一個的glut檔,裡面程式不用刪,然後丟進week11-4目錄裡,更改137行的程式,如下。
include "CMP3_MCI.h"///雙引號表示是同個目錄裡的
CMP3_MCI myMP3;
int main(int argc, char *argv[])
{
char filename[]="C:/Users/Administrator/Desktop/do-re-mi/suzume.mp3";
myMP3.Load(filename);
myMP3.Play();
glutInit(&argc, argv);
glutInitWindowSize(640,480);
glutInitWindowPosition(10,10);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
執行後就會有suzume的音樂。
更改程式讓程式變簡單,再到codeblocks裡的project-Properties打開然後照圖片更改成"."。
#include "CMP3_MCI.h"///雙引號表示是同個目錄裡的
CMP3_MCI myMP3;
int main(int argc, char *argv[])
{
///char filename[]="C:/Users/Administrator/Desktop/do-re-mi/suzume.mp3";
///myMP3.Load(filename);
myMP3.Load("suzume.mp3");
myMP3.Play();
glutInit(&argc, argv);
glutInitWindowSize(640,480);
glutInitWindowPosition(10,10);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
執行後一樣可以聽到音樂。這修改是讓東西都放在同個工作目錄下,比較好找。






沒有留言:
張貼留言