如何在处理过程中更新 OpenGL 中的显示? [英] How to update display in OpenGL during processing?

查看:74
本文介绍了如何在处理过程中更新 OpenGL 中的显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上次使用 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.

我尝试在聚类算法的每次迭代后调用 glutPostRedisplay() 并且尝试在其中使用 glutIdleFunc 回调和 glutPostRedisplay().在这两种情况下,它都不会在图像处理完成之前调用显示回调.

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?

推荐答案

为了解决这个问题,我在每次迭代结束时明确调用我的显示回调函数,而不是让 glut 决定何时调用显示回调的最佳时间.在伪代码中,解决方案看起来像这样.

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.

这篇关于如何在处理过程中更新 OpenGL 中的显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆