1.keyboard
#include <GL/glut.h>#include <stdio.h>
void display()
{
glutSolidTeapot(0.3);
glFlush();
}
void keyboard(unsigned char key, int x, int y)
{
if(key=='a')
{
printf("AAA\n");
}else if(key=='b')
{
printf("BBB\n");
}
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutCreateWindow("02160243");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
2.加入聲音檔
#include <GL/glut.h>
#include <mmsystem.h>
#include <stdio.h>
void display()
{
glutSolidTeapot(0.3);
glFlush();
}
void keyboard(unsigned char key, int x, int y)
{
if(key=='a')
{
printf("AAA\n");
}else if(key=='b')
{
printf("BBB\n");
}
}
void mouse(int button, int state, int x, int y)
{
printf("now play sound\n");
PlaySound("bubbs.wav",NULL,SND_ASYNC);
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutCreateWindow("02160243");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
//glutSpecialFunc(special);
glutMouseFunc(mouse);
//glutMotionFunc(motion);
glutMainLoop();
}
3.按鍵盤發出do re mi fa sol
#include <GL/glut.h>
#include <mmsystem.h>
#include <stdio.h>
void display()
{
glutSolidTeapot(0.3);
glFlush();
}
void keyboard(unsigned char key, int x, int y)
{
if(key=='1')PlaySound("Do.wav",NULL,SND_ASYNC);
if(key=='2')PlaySound("Re.wav",NULL,SND_ASYNC);
if(key=='3')PlaySound("Mi.wav",NULL,SND_ASYNC);
if(key=='4')PlaySound("Fa.wav",NULL,SND_ASYNC);
if(key=='5')PlaySound("Sol.wav",NULL,SND_ASYNC);
if(key=='6')PlaySound("La.wav",NULL,SND_ASYNC);
if(key=='7')PlaySound("Si.wav",NULL,SND_ASYNC);
}
void mouse(int button, int state, int x, int y)
{
printf("now play sound\n");
PlaySound("bubbs.wav",NULL,SND_ASYNC);
PlaySound("oceano.wav",NULL,SND_ASYNC);
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutCreateWindow("02160243");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
//glutSpecialFunc(special);
glutMouseFunc(mouse);
//glutMotionFunc(motion);
glutMainLoop();
}
沒有留言:
張貼留言