Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update display in OpenGL during processing?

Tags:

c++

opengl

It's been over a year since I last used OpenGL so I'm rusty on the topic.

I have an image that I'm doing some processing on, colour clustering to be specific, and I want to update the image after every loop iteration so I can see the changes as they happen rather than in the end when processing is complete.

This is what happens currently. The original image is displayed, the colour clustering function is executed from the keyboard callback function, the image is processed and the updated image is displayed when program control has left the colour clustering function.

I've tried calling glutPostRedisplay() after every iteration of the clustering algorithm and I've tried using the glutIdleFunc callback with glutPostRedisplay() in there. In both cases, it does not call the display callback until the image has finished processing.

How can I have it update the image (i.e. call the display callback) while the image is processing?

like image 510
Dennis Avatar asked Dec 08 '25 22:12

Dennis


2 Answers

To solve the issue I explicitly called my display callback function at the end of each iteration rather than letting glut decide when the best time is to call the display callback. In pseudo code, the solution looks something like this.

colourClustering()
{
    loop
    {
        image processing code
    }
    display()  // Previously I tried using glutPostRedisplay() here.
}

...

display()
{
    drawing code
    glutSwapBuffers()
}

...

main()
{
    ....
    glutDisplayFunc(display);
    ....
}

However, this feels like a work around and not a real solution.

like image 50
Dennis Avatar answered Dec 11 '25 12:12

Dennis


You'll want to make sure the latest version of your image has been drawn (using it to texture a full viewport quad seems the easiest way), then add a call to glutSwapBuffers() (or equivalent, if not double-buffered) in your main GLUT loop.

like image 32
ssube Avatar answered Dec 11 '25 12:12

ssube



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!