- 用基本的 printf 顯示出按下鍵盤確定有效果
- 加入標頭檔 使音效可以使用
- 在按下keyboard 觸發音效 及印出字串
#include <GL/glut.h>
#include <stdio.h>
#include <mmsystem.h>
void display()
{
glutSolidTeapot(0.3);
glFinish();
}
void keyboard(unsigned char key,int x,int y)
{
if(key=='a')
{
PlaySound("rocket.wav",NULL,SND_ASYNC);
printf("小心!!! 火箭來囉~~~\n");
}
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutCreateWindow("hello");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
- 利用音效檔做出 piano 的模擬器
#include <GL/glut.h>
#include <stdio.h>
#include <mmsystem.h>
void display()
{
glutSolidTeapot(0.3);
glFinish();
}
void keyboard(unsigned char key,int x,int y)
{
if(key=='a')
{
PlaySound("rocket.wav",NULL,SND_ASYNC);
printf("小心!!! 火箭來囉~~~\n");
}
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);
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutCreateWindow("hello");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
#include <GL/glut.h>
#include <stdio.h>
#include <mmsystem.h>
float teaY=0, rotX=0,rotY=0,oldX=0,oldY=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(0,teaY,0);
glRotated(rotX,1,0,0);
glRotated(rotY,0,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glFinish();
}
void special (int key,int x,int y)
{
if(key==GLUT_KEY_DOWN)
{
teaY-=0.1; printf("down\n");
} else if(key==GLUT_KEY_UP)
{
teaY+=0.1; printf("up\n");
}
glutPostRedisplay();
}
void mouse (int button,int state,int x,int y)
{
oldX=x; oldY=y;
if(GLUT_LEFT_BUTTON==button && GLUT_DOWN==state) printf("left down\n");
if(GLUT_RIGHT_BUTTON==button && GLUT_DOWN==state) printf("right down\n");
}
void motion(int x,int y)
{
rotX += y-oldY;
rotY += x-oldX;
oldX=x ; oldY=y;
glutPostRedisplay();
}
void keyboard(unsigned char key,int x,int y)
{
if(key=='a')
{
PlaySound("rocket.wav",NULL,SND_ASYNC);
printf("小心!!! 火箭來囉~~~\n");
}
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);
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutCreateWindow("hello");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutSpecialFunc(special);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
沒有留言:
張貼留言