一,所需文件:
vs2010:http://pan.baidu.com/s/1mgr1Umk
mathGL 2.2.2.1:http://mathgl.sourceforge.net/doc_en/Download.html#Download
Qt5.2.1:http://qt-project.org/downloads
CMake:http://www.cmake.org/cmake/resources/software.html
第三方依赖库,zlib,png:http://pan.baidu.com/s/1jG0txsy
二,利用CMake工具生成vs2010工程
整体步骤为,设置目录->configure->generate,如图:
configure之前需做如下配置
(1),配置第三方库png所在路径,共三个路径,如图:
(2),配置第三方库zlib所在路径,共两个路径,如图:
(3),选择qt5 选项,如图:
三,编译工程mgl以及mgl-qt5,生成mgl.dll 以及mgl-qt5.dll,如图:
四,Qt调用mathGL实例。
工程配置如下:
(1)
(2)
(3)
测试代码:
#include <QtWidgets/QApplication>
#include <QtWidgets/qmainwindow.h>
#include <QtWidgets/QScrollArea>
#include <mgl2/qmathgl.h>
#include <mgl2/mgl.h>
int sample(mglGraph *gr)
{
mglData y;
gr->Title("3d variant");
gr->Rotate(50,60);
gr->Box();
mglData yc(30), xc(30), z(30); z.Modify("2*x-1");
yc.Modify("sin(pi*(2*x-1))"); xc.Modify("cos(pi*2*x-pi)");
gr->Plot(xc,yc,z,"rs");
return 0;
}
int main(int argc,char **argv)
{
QApplication a(argc,argv);
QMainWindow *Wnd = new QMainWindow;
Wnd->resize(810,610); // for fill up the QMGL, menu and toolbars
Wnd->setWindowTitle("QMathGL sample");
// here I allow to scroll QMathGL -- the case
// then user want to prepare huge picture
QScrollArea *scroll = new QScrollArea(Wnd);
// Create and setup QMathGL
QMathGL *QMGL = new QMathGL(Wnd);
//QMGL->setPopup(popup); // if you want to setup popup menu for QMGL
QMGL->setDraw(sample);
// or use QMGL->setDraw(foo); for instance of class Foo:public mglDraw
QMGL->update();
// continue other setup (menu, toolbar and so on)
scroll->setWidget(QMGL);
Wnd->setCentralWidget(scroll);
Wnd->show();
return a.exec();
}
执行效果:
整体工程:http://pan.baidu.com/s/1hqecPt6