Hi I am pretty much new to the OpenGL, I have a trouble in animating the background color. I want the program to display an output window with different colors changing with respect to time, but my program displays an output window but with single color and color changes at the times of click on a window.
I've been unable to find the mistake in my code. I have checked many other sites and tried to debug, but I am not yet sure of how to clear it up.
The code I have so far is below:
static int timeFor = 0;
void reshape(int width, int height)
{
glViewport(0, 0, width, height);
}
void display()
{
timeFor = glutGet(GLUT_ELAPSED_TIME);
//std::cout<<"hello"<<timeFor;
glClearColor((float)sin(timeFor) * 0.5f + 0.5f,(float)cos(timeFor) * 0.5f + 0.5f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
}
void main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutCreateWindow(argv[0]);
glewInit();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
}