➤ Week11-1_keyboard
1. 開啟CodeBlocks ,新增OpenGL專案,File ➝ New ➝ Project
3. 點選三個點,點選目錄在桌面,加上專案名字 week11-1_keyboard,Next ➝ Finish
4. 點選 week11-1_keyboard ➝ Sources ➝ main.c,刪除所有程式碼,並輸入
#include <GL/glut.h>
void display()
{
glutSolidTeapot( 0.3 );
glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{
if(key==27) exit(594088);
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week11");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
➤ Week11-2_keyboard_wav_PlaySound
1. 開啟CodeBlocks ,新增OpenGL專案,File ➝ New ➝ Project
3. 點選三個點,點選目錄在桌面,加上專案名字 week11-2_keyboard_wav_PlaySound,Next ➝ Finish
4. 點選 week11-2_keyboard_wav_PlaySound ➝ Sources ➝ main.c,刪除所有程式碼,並輸入
#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();
}
5.播放,按數字1,發出do的聲音 按數字2,發出re的聲音 按數字3,發出mi的聲音
➤ Week11-3_PlaySound.cpp
1. 開啟CodeBlocks ,新增File ➝ New ➝ Empty file
#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);
}
3. Settings ➝ Compiler ➝ Linker settings➝ Add ➝ 輸入winmm
➤ Week11-4_glut_mp3
1. 開啟CodeBlocks ,新增File ➝ New ➝ Empty file
2. 選取GLUT Project ➝ Go ➝ Next
3. 點選三個點,點選目錄在桌面,加上專案名字 week11-4_glut_mp3,Next ➝ Finish
5. 點選 week11-4_glut_mp3 ➝ Sources ➝ main.c,並輸入
7. 將freeglut.dll、suzumi.mp3複製到week11-4_glut_mp3資料夾
沒有留言:
張貼留言