主題:keyboard,音效
第一節課
今天先介紹keyboard,開啟一個新的GLUT專案(前幾週有步驟),建完後用ctrl+f搜尋key。
#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("week 11");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
step01-2:音效
把step01-1的程式碼複製過來,加上幾行程式碼,再把音檔的位置複製到程式碼裡。
第二節課:試問能在Hello World放出音檔嗎?
step02-1:把第一節課學到的音檔來用
開一個空白檔另存成week11-3_PlaySound.cpp,開完在Settings>Compiler>Link加上winm。
補充:目錄的斜線可以用兩個反斜線,或者是一個斜線!!
#include <windows.h>
#include <stdio.h>
int main()
{
PlaySound("C:\\Users\\Administrator\\Desktop\\week11\\do-re-mi\\do.wav",NULL,SND_SYNC);
PlaySound("C:\\Users\\Administrator\\Desktop\\week11\\do-re-mi\\re.wav",NULL,SND_SYNC);
PlaySound("C:\\Users\\Administrator\\Desktop\\week11\\do-re-mi\\mi.wav",NULL,SND_SYNC);
printf("Hello World");
}
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
char filename[]="C:/Users/Administrator/Desktop/week11-4_CMP3_MCI_Load_Play/拌.mp3";
myMP3.Load(filename);
myMP3.Play();
沒有留言:
張貼留言