2017-12-21 3 views
0

다음과 같은 기능을 가지고 있습니다. 그 목적은 3D 개체를 표시하는 GLUT 창과 플롯을 표시하는 Gnuplot 창을 표시하는 것입니다.GLUT와 gnuplot 창이 동시에 나타나지 않음

나는 Gnuplot-Iostream Interface을 사용합니다. 플롯 팅 코드는 사용자가 키보드를 입력 할 때 업데이트되므로 함수 안에 있습니다. displayGraph 기능 내부의 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"; 
} 

: 나는 GLUT 창을 닫은 후

다음 코드 만의 gnuplot 창을 표시합니다. 불행히도 내 사건에 대해서는 displayGraph 함수가 호출 될 때마다 새로운 Gnuplot 윈도우가 생성 될 때마다 작동하지 않을뿐입니다. 반면 Gnuplot 윈도우는 업데이트됩니다. 내가 GNUPLOT에 다른 C++ 인터페이스를 사용하여 솔루션을 발견했습니다

#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"; 
} 
+0

왜'gnuplot'이 OpenGL을 사용할 수 있다고 생각하십니까? – Ripi2

+0

내 코드가 다소 혼란 스러웠다. GLUT와 Gnuplot의 사용을 분리하기 위해 코드를 업데이트했다. 내가 원하는 것은 Gnuplot과 GLUT 윈도우가 동시에 나타나기 위해서입니다. 그들은 서로 상호 작용하지 않습니다. –

답변

0

, 즉 gnuplot-cpp

#include "gnuplot_i.hpp" //Gnuplot class handles POSIX-Pipe-communikation with Gnuplot 
#include <GL/glut.h> 

void displayGraph(); 
void displayGnuplot(); 
Gnuplot g1("lines"); 

int main(int argc, char** argv) { 

    displayGnuplot(); 

    glutInit(&argc,argv); 
    glutInitWindowSize(1024, 1024); 
    glutInitWindowPosition(1080,10); 
    glutCreateWindow("Continuum Data"); 
    glutDisplayFunc(displayGraph); 

    glutMainLoop(); 
} 

void displayGraph(){ 

} 

void displayGnuplot(){ 

    g1.set_title("Slopes\\nNew Line"); 
    g1.plot_slope(1.0,0.0,"y=x"); 
    g1.plot_slope(2.0,0.0,"y=2x"); 
    g1.plot_slope(-1.0,0.0,"y=-x"); 
    g1.unset_title(); 
    g1.showonscreen(); 
} 
:

는 또한 아무 소용에의 gnuplot 윈도우의 작성과 조건을 넣어 시도했습니다

이 솔루션은 GLUT 및 gnuplot 창을 동시에 표시하므로 사용자가 명령을 내릴 때 둘 다 업데이트 될 수 있습니다.

관련 문제