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

当在同一个界面中绘制多个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());
}

上一篇:openGL中用Assimp库加载骨骼动画


下一篇:Modern OpenGL绘制圆柱体