Week 11
Class Work_01
1. Download "Do, re, mi.wav" files on website.
2. Add #include <windows.h> , #include <mmsystem.h> and use PlaySoundA function to play sound.
3. Add one link (winmm) to linker setting.
Class Work_02
Source Code:
#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);
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);
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("3D and Sound");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
Class Work_03
Source code:
#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("ButterFly.mp3"); ///Need to download mp3 on youtube
player.Play();
glutMainLoop();
return 0;
}




沒有留言:
張貼留言