使用 Qt 和 OpenGL 重复渲染循环

发布于 2024-08-12 20:33:45 字数 331 浏览 3 评论 0原文

我用 Qt 和 OpenGL 做了一个项目。

我相信,在 Qt 中,paintGL() 被重复调用,因此我能够更改该函数之外的值并调用 update() ,以便它绘制新图像。 我还相信,一旦启动程序,它就会调用initializeGL()。

现在我的问题是:

我希望在不同的程序中具有相同的功能。我不需要绘制任何图像等。我只是想知道是否有一种方法可以使像paintGL() 这样的函数不断被调用,以便应用程序永远不会关闭。我尝试仅使用 while(true) 循环来保持程序运行,但由于 while 循环,GUI 处于非活动状态。

最好是除螺纹之外的任何尖端。

谢谢。

I've made a project with Qt and OpenGL.

In Qt paintGL() was repeatedly call I beleive, so I was able to change values outside of that function and call update() so that it would paint a new image.
I also believe that it called initializeGL() as soon as you start up the program.

Now my question is:

I want that same functionality in a different program. I do not need to draw any images, etc. I just was wondering if there was a way to make a function like paintGL() that keeps being called so the application never closes. I tried just using a while(true) loop that kept my program running, but the GUI was inactive because of the while loop.

Any tips, other than threading preferably.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不打扰别人 2024-08-19 20:33:45

确切的机制取决于您使用的 GUI 工具包。一般来说,您的应用程序需要不断地为运行循环提供服务才能调度事件。这就是为什么当您的应用程序在 while 循环中运行时它没有响应。

如果您需要不断地重新绘制某些内容,最简单的方法是在创建窗口时创建一个计时器,然后在计时器事件处理程序或回调中,使窗口无效,从而强制重新绘制。然后可以按照计时器的频率调用您的油漆处理程序,例如每秒 25 次。

The exact mechanism will depend on which GUI toolkit you are using. In general, your app needs to service the run loop constantly for events to be dispatched. That is why your app was unresponsive when you had it running in a while loop.

If you need something repainted constantly, the easiest way is to create a timer when your window is created, and then in the timer even handler or callback, you invalidate your window which forces a repaint. Your paint handler can then be called at the frequency of your timer, such as 25 times per second.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文