week11 鍵盤、音樂、滑鼠、轉動
第一堂課
開一個新GLUT專案week11-1_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();
}
開新的GLUT專案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();
}

第二堂課
開啟新的空白文件week11-3_PlaySound.cpp加入playSound咒語 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); ///目錄的斜線可以用 兩個反斜線\\ 或是一個斜線/ PlaySound("do-re-mi/do.wav" , NULL, SND_SYNC); ///相對路徑 Relative path printf("Hello World\n");}
開新專案week11-4新增幾行程式#include "CMP3_MCI.h"
CMP3_MCI myMP3;
char filename[] = "C:/Users/Administrator/Desktop/do-re-mi/suzume.mp3";
myMP3.Load(filename); myMP3.Play();
第三堂課
#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);
///目錄的斜線可以用 兩個反斜線\\ 或是一個斜線/
PlaySound("do-re-mi/do.wav" , NULL, SND_SYNC);
///相對路徑 Relative path
printf("Hello World\n");
}
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
char filename[] = "C:/Users/Administrator/Desktop/do-re-mi/suzume.mp3";
myMP3.Load(filename);
myMP3.Play();
第三堂課
改目錄位置
沒有留言:
張貼留言