本人在使用Qcustomplot绘图的数据量比较大,为了减轻CPU压力,就想使用openGl加速缓解一下,使用过程中遇到一些麻烦,还请各位指点迷津。
一、使用Qcustomplot绘制波形,不使用 openGl加速时,程序正常运行。
上面是遇到的问题,qcustom官网和博客查找使用opengl加速的方法,介绍的方法都是配置库、头文件,程序里面添加m_custumplot->setOpenGl(true);其他的这方面资料比较少,没有查找到结果。
程序源码:Qcustomplot使用openGl加速异常问题源码-互联网文档类资源-CSDN下载
工程文件配置如下:
QT += opengl
DEFINES += QCUSTOMPLOT_USE_OPENGL
LIBS += freeglut.lib OpenGL32.Lib
#LIBS += freeglut.lib
#LIBS += -lOpenGL32l
# Default rules for deployment.
渲染模式设置如下:
int main(int argc, char *argv[])
{
#if 1
//下面两种方法都可以,Qt默认采用的是 AA_UseDesktopOpenGL
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
#endif
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
绘图函数中设置开启opengl
void Widget::realFreqInit(void)
{
m_custumplot = new QCustomPlot;
m_custumplot = ui->widget_realFreq;
#ifdef OPENGL
m_custumplot->setOpenGl(true);
qDebug() << "widget_realFreq:" << m_custumplot->openGl();
#endif
m_custumplot->addGraph();//添加图层
m_custumplot->graph()->setPen(QPen(Qt::red)); //线条颜色
m_custumplot->setInteractions(QCP::iRangeZoom);//滚轮缩放
m_custumplot->setSelectionRectMode(QCP::srmZoom);//框选放大
for(int i = 0; i < MAX_SIZE; i++)
{
xRealFreq << i;
}
m_custumplot->rescaleAxes(); //坐标轴自适应大小
m_custumplot->replot();
}
void Widget::realFreqShow(QVector<double> data)
{
ui->widget_realFreq->graph(0)->setData(xRealFreq,data);
ui->widget_realFreq->replot();
ui->widget_realFreq->rescaleAxes(); //坐标轴自适应大小
}
你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答
本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。
因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。