OpenGL C ++ Argument of type void is incompatible with the type parameter void (*) ()

advertisements

I am trying to draw several triangles in 3d and can't execute glutDisplayFunc() function. Here is my code:

Array of triangles and size.

int const trsize = (size-1)*(size-1)*2;
Triangle *trarr = new Triangle[trsize];

Code, where I try to call the function.

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(400,400);
glutInitWindowPosition(100,100);
glutCreateWindow("Height Map");
Initialize();
glutDisplayFunc(Draw1(trarr, trsize));
glutMainLoop();

Draw1() function.

void Draw1(Triangle arr[], int size){
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 1.0, 1.0);
    glBegin(GL_LINES);
    for(int i=0; i<size; ++i){
        glVertex3d((GLdouble)arr[i].p1().x(), (GLdouble)arr[i].p1().y(), (GLdouble)arr[i].p1().z());
        glVertex3d((GLdouble)arr[i].p2().x(), (GLdouble)arr[i].p2().y(), (GLdouble)arr[i].p2().z());
        glVertex3d((GLdouble)arr[i].p3().x(), (GLdouble)arr[i].p3().y(), (GLdouble)arr[i].p3().z());
    }
    glEnd();
    glFlush();
}

I use VS2012 and IntelliSense writes: argument of type "void" is incompatible with parameter of type "void (*)()"

I don't know why DisplayFunc needs another type. With Draw() function without arguments it works fine.


glutDisplayFunc only allow function with that signature: void func(void).

so in you code, your drawing routine should be:

void Draw1(void){...}

and you should find another way (global variable for example) to pass parameters to it. And your glut statement would be:

glutDisplayFunc(Draw1);