QGLWidget中的渲染和颜色拾取:如何处理这两者

rendering and color picking in QGLWidget : how to cope with both

本文关键字:何处理 处理 颜色 QGLWidget      更新时间:2023-10-16

我想知道是否有比这更好的解决方案:我有一个渲染代码和一个颜色选择代码,我已经共享了这两个代码(VBO等)之间可以共享的所有内容,我的代码看起来像:

void paintGL()
{
label1:
  if(picking_running)
  {
     ... code to draw the colors for the picking
  }
  else
  {
     ... normal code to draw the scene the user should see
  }

  if(picking_running)
  {
      ... do the colorpick and identify the clicked element...
     picking_running = FALSE;
     goto label1; // this prevent the paintGL function to end and get swapBuffers called, I don't want the "flickering" to be visible to the user between the color picking mode and the normal mode
  }
} // end of the paintGL, here swapBuffers is called automatically

代码是有效的,用户不会看到闪烁,但坦率地说,在我的代码中使用goto的想法似乎是一个糟糕的解决方案。

你还有其他更好的主意吗?

使用setAutoBufferSwap(false)并自己调用QGLWidget::swapBuffers。也可以将颜色拾取渲染到未渲染的缓冲区/纹理。

既然你无论如何都执行可见渲染,为什么不这样实现呢:

void paintGL()
{
  if(picking_running)
  {
     /* ... code to draw the colors for the picking */
     /* ... do the colorpick and identify the clicked element... */
  }
  /* ... normal code to draw the scene the user should see */
}