Week11
1.先開一個glut專案,照著以下程式碼打,執行後,按esc跑出1234。
#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();
}
2.建立第二個專案,複製專案一的程式碼,第一步設定因檔路徑(注意每個\要改成\\)
#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();
}
3.連播三個音,最後跑出Hello World
#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");
}
4.
5.建立一個glut專案新增
137#include "CMP3_MCI.h"
139CMP3_MCI myMP3;
143char filename[] = "C:/Users/Administrator/Desktop/do-re-mi/suzume.mp3";
144myMP3.Load(filename);
145myMP3.Play();
執行結果如下圖
6.把myMP3.Load(filename);改成myMP3.Load("suzume.mp3");
把freeglut.dll和mp3音檔拉到同一個資料夾
就可以播放了。
137#include "CMP3_MCI.h"
139CMP3_MCI myMP3;
144myMP3.Load("suzume.mp3");
145myMP3.Play();
7.
8.
9.
沒有留言:
張貼留言