(1)開啟貝殼專案
(2)輸入程式碼--
#include <iostream>
#include <windows.h>
#include <mmsystem.h>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
PlaySoundA("Do.wav",NULL,SND_SYNC);
PlaySoundA("Re.wav",NULL,SND_SYNC);
PlaySoundA("Mi.wav",NULL,SND_SYNC);
return 0;
}
(3)Build options->Linker settings->add "winmm"
(4)下載Do Re Mi.wav檔
網址:http://www.openprocessing.org/sketch/132652
將音檔複製到路徑資料夾
課堂作業二:
(1)開啟貝殼專案:
(2)輸入程式碼--
#include<GL/glut.h>
#include<windows.h>
#include<mmsystem.h>
void display()
{
}
void keyboard(unsigned char key, int x,int y)
{
if(key=='1')PlaySoundA("Do.wav",NULL,SND_ASYNC);
if(key=='2')PlaySoundA("Re.wav",NULL,SND_ASYNC);
if(key=='3')PlaySoundA("Mi.wav",NULL,SND_ASYNC);
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("hi 3d");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
(3)放入freeglut.dll
(4)Build options->Linker settings
freeglut
opengl32
glu32
gdi32
winmm
(5)Build options->Search directions->Compiler
->C:\Users\USER\Desktop\freeglut\include
(6)Build options->Search directions->Linker
->C:\Users\USER\Desktop\freeglut\lib
課堂作業三:
(1)將程式碼改成--
#include <GL/glut.h>
#include <windows.h>
#include <mmsystem.h>
#include "CMP3_MCI.h"
CMP3_MCI player;
float potx=-1, poty=0;
void display()
{
glClearColor(0.5, 0.5, 1, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(potx, poty, 0);
glutSolidTeapot(0.1);
glPopMatrix();
glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{
if(key == '1') PlaySoundA("DO.Wav", NULL, SND_ASYNC);
if(key == '2') PlaySoundA("Re.Wav", NULL, SND_ASYNC);
if(key == '3') PlaySoundA("Mi.Wav", NULL, SND_ASYNC);
if(key == '4') PlaySoundA("Fa.Wav", NULL, SND_ASYNC);
if(key == '5') PlaySoundA("Sol.Wav", NULL, SND_ASYNC);
if(key == '6') PlaySoundA("La.Wav", NULL, SND_ASYNC);
if(key == '7') PlaySoundA("Si.Wav", NULL, SND_ASYNC);
}
void mouse (int button, int state, int x, int y)
{
if(state == GLUT_DOWN)
{
PlaySoundA("Si.wav", NULL, SND_ASYNC);
}
}
void timer(int t)
{
glutTimerFunc(30, timer, t+1);
potx+=0.03;
if(potx > 1)potx=-1;
glutPostRedisplay();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("3D and Sound");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutTimerFunc(30, timer, 0);
glutMouseFunc(mouse);
player.Load("eight.mp3"); ///Need to download mp3 on youtube
player.Play();
glutMainLoop();
return 0;
}














沒有留言:
張貼留言