0

我想知道是否有比这更好的解决方案:我有一个渲染代码和一个颜色选择代码,我已经共享了可以在这两个代码(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 的想法在我看来是一个糟糕的解决方案。

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

4

2 回答 2

1

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

于 2012-07-21T12:33:42.657 回答
1

既然您仍然执行可见渲染,为什么不这样实现它:

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 */
}
于 2012-07-21T13:41:42.170 回答