How update a window in OpenGL

Viewed 101

How is possible to update a window in OpenGL? I mean: if a create a window with a figure and I visualize it, then I want through a transformation to modify the figure. I would like that by pressing a button from keyboard my window could be updated with the transfromed figure. What I do insert between "cin" and glutDisplayFunc(display) (look the followinfg pseudo-code)?

int main(int argc, char** argv){
   
    glutInit(&argc, argv);
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize (500, 500);
    glutInitWindowPosition (100, 100);
    glutCreateWindow (argv[0]);
    init ();
    glutDisplayFunc(display);
    cin>>input_for_transformation;
    glutReshapeFunc(reshape);
    glutKeyboardFunc (keyboard);
    glutMainLoop();
    return 0;
}
1 Answers

You need to invoke glutPostRedisplay:

Mark the normal plane of current window as needing to be redisplayed. The next iteration through glutMainLoop, the window's display callback will be called to redisplay the window's normal plane. [...]

Call glutPostRedisplay () in the keyboard callback (keyboard) when a key is pressed, or call glutPostRedisplay() continuously in the display function for a continuous animation.

Related