Social Icons

Friday, 4 July 2014

Working of Timer in Open GL

#include<GL/gl.h>
#include<GL/glu.h>
#include<GL/glut.h>
float f=0.0;
void display()
{
     glClearColor(0.0,1.0,1.0,0.0);
     glClear(GL_COLOR_BUFFER_BIT);
     glBegin(GL_TRIANGLES);
     glColor3f(1.0,0.0,0.0);
     glVertex2f(f/10,0.0);
     glColor3f(0.0,1.0,0.0);
     glVertex2f(-f/10,0.0);
     glColor3f(0.0,0.0,1.0);
     glVertex2f(0.0,f/10);
     glEnd();
     glFlush();
 }

void Timer()
{
     f+=1;
     if (f==9.0)
     f-=8;
     glutPostRedisplay();
     glutTimerFunc(100,Timer,0);
}

 int main(int argc, char ** argv)
 {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE);
    glutInitWindowPosition(100,100);
    glutInitWindowSize(500,600);
    glutCreateWindow("Triangle");
    glutDisplayFunc(display);
    glutTimerFunc(0,Timer,0);
    glutMainLoop();
    return 0;
}

No comments:

Post a Comment