【发布时间】:2017-12-22 07:59:31
【问题描述】:
我有以下函数,其目的是显示一个显示 3D 对象的 GLUT 窗口和一个显示绘图的 Gnuplot 窗口。
为此,我使用Gnuplot-Iostream Interface。绘图代码位于函数内部,因为它会在用户在键盘上键入时更新。
以下代码只会在我关闭 GLUT 窗口后显示 Gnuplot 窗口:
#include "gnuplot-iostream.h"
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
void displayGraph();
void displayGnuplot();
Gnuplot gp;
int main(int argc, char** argv) {
displayGnuplot();
glutInit(&argc,argv);
glutInitWindowSize(1024, 1024);
glutInitWindowPosition(1080,10);
glutCreateWindow("Continuum Data");
glutDisplayFunc(displayGraph);
glutMainLoop();
}
void displayGraph(){
/*
Code to display in Glut window that will be updated
*/
}
void displayGnuplot(){
bool displayGnuplot = true;
gp << "set xrange [-2:2]\nset yrange [-2:2]\n";
gp << "plot '-' with vectors title 'pts_A', '-' with vectors title 'pts_B'\n";
}
有效的方法是在 displayGraph 函数中声明 Gnuplot 实例。不幸的是,这不适用于我的情况,因为每次调用 displayGraph 函数时都会创建一个新的 Gnuplot 窗口,而我只想更新 Gnuplot 窗口。
我也尝试在 Gnuplot 窗口的创建周围设置一个条件,但无济于事:
#include "gnuplot-iostream.h"
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
void displayGraph();
void displayGnuplot();
Gnuplot gp;
int main(int argc, char** argv) {
displayGnuplot();
glutInit(&argc,argv);
glutInitWindowSize(1024, 1024);
glutInitWindowPosition(1080,10);
glutCreateWindow("Continuum Data");
glutDisplayFunc(displayGraph);
glutMainLoop();
}
void displayGraph(){
/*
Code to display in Glut window that will be updated
*/
}
void displayGnuplot(){
if(!gnuplotExists){
Gnuplot gp;
gnuplotExists = true;
}
gp << "set xrange [-2:2]\nset yrange [-2:2]\n";
gp << "plot '-' with vectors title 'pts_A', '-' with vectors title 'pts_B'\n";
}
【问题讨论】:
-
为什么你认为
gnuplot可以使用OpenGL? -
我可以看到我的代码有点混乱,我已经对其进行了更新以将 GLUT 和 Gnuplot 的使用分开。我想要的是让 Gnuplot 和 GLUT 窗口同时出现。他们并没有真正相互交流。
标签: c++ opengl glut gnuplot-iostream