GLUT 窗口变黑“(无响应)”当CPU繁忙时

发布于 2024-09-30 05:04:36 字数 752 浏览 6 评论 0原文

我正在编写光线追踪器并使用 GLUT 来显示结果。我在子块中渲染图像,渲染每个子块后我更新视图。

发生的情况是,我看到渲染进度,但几秒钟后,渲染窗口变黑,窗口标题显示“(未响应)”。然而,渲染进程继续运行(CPU 使用率为 100%)并在控制台输出上输出进度信息。渲染完成后,GLUT 窗口将恢复正常并显示图像。

我该怎么做才能让窗口在渲染过程中保持响应而不变黑?

谢谢!

//编辑:我显然在等待渲染线程时阻塞了我的主线程:

while(true){
    if(m_activeRenderThreads==0)
        break;
    ::WaitForSingleObject(updateEvent->m_hObject, 200);
    notifyObservers(); //inherited from IFunctionObservable
}

notifyObservers()调用:

update(){
    glClear(GL_COLOR_BUFFER_BIT);
    glViewport(0,0,resX,resY);
    glRasterPos2i(-1,-1);
    glDrawPixels(resX, resY, GL_RGB, GL_FLOAT, renderBuffer);
    glutSwapBuffers();
}

最后一个函数仅在我从主线程调用它时才起作用。通过渲染线程调用它不会更新我的窗口

I'm programming a raytracer and use GLUT to display the result. I render the the image in subblocks and after rendering each subblock i update the view.

What happens is that i see the render progress, but after some seconds, the render window turns black and the window caption reads "(not responding)". the renderprocess however continues to run (at 100% cpu usage) and outputs progressinfo on the console output. once the rendering is finished, the GLUT window turns back to normal and displays the image.

What can I do in order to keep the window responding during the rendering process so that it doesn't turn black?

Thanks!

//edit: I aparently block my mainthread while waiting for the render threads:

while(true){
    if(m_activeRenderThreads==0)
        break;
    ::WaitForSingleObject(updateEvent->m_hObject, 200);
    notifyObservers(); //inherited from IFunctionObservable
}

notifyObservers() calls:

update(){
    glClear(GL_COLOR_BUFFER_BIT);
    glViewport(0,0,resX,resY);
    glRasterPos2i(-1,-1);
    glDrawPixels(resX, resY, GL_RGB, GL_FLOAT, renderBuffer);
    glutSwapBuffers();
}

this last function works only if I call it from the mainthread. calling it through the renderthreads doesn't update my window

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

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

发布评论

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

评论(1

征棹 2024-10-07 05:04:36

你需要做的就是把所有的处理放在一个单独的线程中;主 GUI 线程应该只用于响应 GUI 事件和绘制窗口,而不应该进行任何密集的计算。所以...在一个单独的线程中,绘制到缓冲区,然后每隔一段时间您应该在主 GUI 线程上安排该缓冲区复制到 UI 中。

What you need to do is put all your processing in a separate thread; the main GUI thread should only be used for responding to GUI events and painting the window, but should not do any intensive computations. So... in a separate thread, paint to a buffer, and then every so often you should schedule on the main GUI thread for this buffer to be copied into the UI.

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