评论

收藏

[C++] 【三】QCustomPlot开启OpenGL绘图上下文异常问题

编程语言 编程语言 发布于:2021-07-05 10:28 | 阅读数:539 | 评论:0

  当在同一个界面中绘制多个QCustomPlot图形时,此时如果开启了OpenGL功能,则会提示QOpenGLFramebufferObject::bind() called from incompatible context的警告,界面图形渲染时会出现错乱,可以通过在qcustomplot.cpp的QCPPaintBufferGlFbo::draw()函数中添加以下红色的代码即可。
  /* inherits documentation from base class */
void QCPPaintBufferGlFbo::draw(QCPPainter *painter) const
{
  if (!painter || !painter->isActive())
  {
    qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed";
    return;
  }
  if (!mGlFrameBuffer)
  {
    qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?";
    return;
  }
  if (QOpenGLContext::currentContext() != mGlContext.data()) {
      mGlContext.data()->makeCurrent(mGlContext.data()->surface());
  }
  painter->drawImage(0, 0, mGlFrameBuffer->toImage());
}

  
关注下面的标签,发现更多相似文章