Per te realizuar ngjarje te ndryshme si zhvendosja, shformimi ose rrotullimi I objekteve ne njesine e kohes duhet te perdorim funksionin glutTimerFunc(t,update,0)
I cili mer si
parameter kohen ne milisekonda, funksionin update
ne te cilin ai vepron dhe koeficientin e ketij funksioni I cili merr vleren 0 ose 1. Ne funksionin update
realzizohen ndryshimet e deshiruara.
Ushtrim: Ndertoni nje program I cili vizaton nje katror dhe e zhvendos ate me 20 njesi djathtas per cdo sekonde
#include<gl/glut.h>
int
here=0;
void
Display()
{
glClear(GL_COLOR_BUFFER_BIT);
glTranslatef(20.0*here,0.0,0.0);
glRectf(-5.0,-5.0,5.0,5.0);
glFlush();
}
void
init()
{
glClearColor(0.2,0.3,0.4,1.0);
glViewport(-200,-200,300,300);
gluOrtho2D(-200.0,300.0,-200.0,300.0);
glMatrixMode(GL_MODELVIEW);
}
void
update(int value)
{
here++;
glutPostRedisplay();
glutTimerFunc(1000,update,0);
}
int main(int argc, char*
argv[])
{
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(300,300);
glutCreateWindow("test");
init();
glutDisplayFunc(Display);
glutTimerFunc(1000,update,0);
glutMainLoop();
}
0 comments:
Post a Comment