先利用Timer讓聲音在幾秒鐘出來
去wav網站上下載聲音
要記得把聲音檔放在 in C:\Users\user\Desktop\freeglut\bin 裡
程式碼
#include <GL/glut.h>
#include <mmsystem.h>///NOW (0)發聲音
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
void timer(int t)///NOW (2)
{
glutTimerFunc(1000, timer, 0);///NOW2間隔一秒持續撥放
PlaySoundA("Femaleha.wav", NULL, SND_ASYNC);///NOW (2)
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(500,500);///大一點
glutCreateWindow("week14 timer");
glutDisplayFunc(display);
glutTimerFunc(1000, timer, 0);///NOW (1)
1000代表一秒鐘
glutMainLoop();
}
#include <GL/glut.h>
#include <mmsystem.h>///NOW (0)發聲音
#include <stdio.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angle,0,0,1);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void timer(int t)///NOW (2)
{
glutTimerFunc(30, timer, t+1);///NOW2間隔一秒持續撥放
printf("現在的 timer的T是:%d\n",t);
///PlaySoundA("Femaleha.wav", NULL, SND_ASYNC);///NOW (2)
angle=t;
glutPostRedisplay();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(500,500);///大一點
glutCreateWindow("week14 timer");
glutDisplayFunc(display);
glutTimerFunc(1000, timer, 0);///NOW (1)
///1000代表一秒鐘
glutMainLoop();
}
2.內插公式
程式碼
#include <GL/glut.h>
#include <mmsystem.h>///NOW (0)發聲音
#include <stdio.h>
float angle=0;
float nowX=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
/// glRotatef(angle,0,0,1);
glTranslated(nowX,0,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void timer(int t)///NOW (2)
{
glutTimerFunc(30, timer, t+1);///NOW2間隔一秒持續撥放
printf("現在的 timer的T是:%d\n",t);
///PlaySoundA("Femaleha.wav", NULL, SND_ASYNC);///NOW (2)
/// angle=t;
float alpha=(t%30)/30.0;
nowX = alpha*1.0+(1-alpha)*-1.0;
glutPostRedisplay();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(500,500);///大一點
glutCreateWindow("week14 timer");
glutDisplayFunc(display);
glutTimerFunc(1000, timer, 0);///NOW (1)
///1000代表一秒鐘
glutMainLoop();
}
沒有留言:
張貼留言