当光标位于 GLUT UI 时进行 OpenGL 渲染

发布于 2024-11-27 08:38:46 字数 413 浏览 1 评论 0原文

我有一个主窗口,它在屏幕的顶部 10% 处有一个过剩的 UI,在屏幕底部的 90% 处有 openGL 世界。每次我的光标开始悬停在 GLUT 部分上时,openGL 渲染都会冻结。仅当光标退出 GLUT 区域时才恢复。

这是因为只要光标悬停在 GLUT 区域上,就可能永远不会调用 glutIdleFunc,因为 glut 不是“空闲”,因此不会渲染 openGL 内容。

我已经尝试创建一个新的不相关线程,仅调用显示代码和/或 glutPostRedisplay,但我得到了高达 20 fps 的帧速率,而不是正常方式的 100+ fps。我不知道到底为什么。 (在这个测试中,我还禁用了 glutIdleFunc,因此没有空闲函数,只有调用显示的单独线程)

解决这个问题的方法(除了“停止使用 glut”,我将来可能会这样做,但现在我想要一个临时解决方案)?

I have a main window which has both a glut UI in the top 10% of the screen, and the openGL world in the bottom 90% of the screen. Every time my cursor starts hovering over the GLUT portion, openGL rendering will freeze. It resumes only when the cursor exits the GLUT area.

This is because as long as the cursor is hovering over the GLUT area, presumably glutIdleFunc is never called because glut is not "idle", so openGL stuff is not rendered.

I already tried making a new unrelated thread that just calls the display code and/or glutPostRedisplay but I got a framerate of whopping 20 fps as opposed to the 100+ fps the normal way. I don't know exactly why. (In this test I also disabled glutIdleFunc so there is no idle func, just the separate thread calling the display)

Ways to get around this (other than "stop using glut" which I might do in the future but for now I would like a temporary solution)?

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

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

发布评论

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

评论(2

诗化ㄋ丶相逢 2024-12-04 08:38:46

我知道这是一个老问题,但我遇到了类似的问题,想分享我是如何解决它的。

基本上,在空闲函数中,您应该手动将窗口设置为正常的窗口 ID。感谢 Joel Davis 的 HexPlanet 代码 ( https://github.com/joeld42/hexplanet/ )证明这一点:

void glut_Idle( void )
{
  // According to the GLUT specification, the current window is 
  // undefined during an idle callback.  So we need to explicitly change
  // it if necessary
  if ( glutGetWindow() != g_glutMainWin ) 
  {
    glutSetWindow(g_glutMainWin);  
  }

  ...
}

I know this is an old question, but I was having a similar issue and wanted to share how I solved it.

Basically, in your idle function, you should manually set the window to your normal window ID. Thanks to Joel Davis' HexPlanet code ( https://github.com/joeld42/hexplanet/ ) for demonstrating this:

void glut_Idle( void )
{
  // According to the GLUT specification, the current window is 
  // undefined during an idle callback.  So we need to explicitly change
  // it if necessary
  if ( glutGetWindow() != g_glutMainWin ) 
  {
    glutSetWindow(g_glutMainWin);  
  }

  ...
}
瞳孔里扚悲伤 2024-12-04 08:38:46

为被动运动函数创建回调:

void passiveMouseFunc(int,int){
    glutPostRedisplay();
}

并使用以下方法注册它:

glutPassiveMotionFunc(passiveMouseFunc);

Create a callback for passive motion func:

void passiveMouseFunc(int,int){
    glutPostRedisplay();
}

And register it using:

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