【问题标题】:Drawing with glutDisplayFunc (opengl)用 glutDisplayFunc (opengl) 绘图
【发布时间】:2015-01-19 21:49:02
【问题描述】:

我有一个显示功能,显示由两点定义的各种线段:

void display(long total_points, vector<vector<long>> adjmat){
    //stuff here
    glVertex2f(n1,n2);
    glVertex2f(n3,n4);
}

我想在一个窗口中显示这些片段,我正在使用 glut 来做到这一点:

int main(int argc, char *argv[]){
    //stuff here
    glutDisplayFunc(display(total_points, adjmat));
    glutMainLoop();
    return EXIT_SUCCESS;
}

我在glutDisplayFunc()、invalid use of void expression 遇到错误 我需要将一些参数传递给display() 以获得我想要的输出。

我该如何解决这个问题?

【问题讨论】:

    标签: c++ function opengl glut


    【解决方案1】:

    不要将它们作为参数传递,而是作为全局变量传递,函数没有参数是过剩的缺点。

    long total_points;
    vector<vector<long>> adjmat;
    
    void display(){
        //stuff here
        glVertex2f(n1,n2);
        glVertex2f(n3,n4);
    }
    
    int main(int argc, char *argv[]){
        //stuff here
        //fill and assign total_points, adjmat
        glutDisplayFunc(display);
        glutMainLoop();
        return EXIT_SUCCESS;
    }
    

    【讨论】:

    • 我明白了,有点不方便。你能推荐另一个用于 c++ 创建图形的库吗?
    猜你喜欢
    • 2011-04-05
    • 2011-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多