рендеринг и выбор цвета в QGLWidget: как справиться с обоими

Мне интересно, есть ли лучшее решение, чем это: у меня есть код рендеринга и код выбора цвета, я уже поделился всем, что можно было разделить между этими двумя кодами (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 в моем коде, откровенно говоря, кажется мне плохим решением.

У вас есть другая идея получше?


person Johnny Pauling    schedule 21.07.2012    source источник


Ответы (2)


Используйте setAutoBufferSwap(false) и вызовите QGLWidget::swapBuffers самостоятельно. Вы также можете отобразить выбор цвета в буфере/текстуре, который не отображается.

person torbjoernwh    schedule 21.07.2012

Поскольку вы все равно выполняете видимый рендеринг, почему бы не реализовать его следующим образом:

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 */
}
person datenwolf    schedule 21.07.2012