0

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();
}
code_dredd
  • 5,915
  • 1
  • 25
  • 53
spod
  • 463
  • 1
  • 5
  • 11
  • 2
    Be sure to post a [MCVE](http://stackoverflow.com/help/mcve). The header files needed by the code are missing. Also note that it should be `int main`, not `void main`. – code_dredd Dec 18 '15 at 21:58
  • Sorry, i did put header files in my original code. forgot to put here. Anyways thank you for the reply i did solve the problem by using glutPostRedisplay(); – spod Dec 18 '15 at 23:18

0 Answers0