Nathan
Nathan

Reputation: 1

OpenGL:no matching function for call to 'glutDisplayFunc'

My operating system is mac. However, when I put this code into the Xcode compiler and run it. The console says "no matching function for call to 'glutDisplayFunc'".

#include "GLUT/glut.h"

void init(void)
{
    glClearColor(1.0, 1.0, 1.0, 0.0);
    glMatrixMode(GL_PROJECTION);
    gluOrtho2D(0.0, 200.0, 0.0, 150.0);

}

void lineSegement(void)
{
    glClear(GL_COLOR_BUFFER_BIT);

    glColor3f(1.0, 0.0, 0.0);
    glBegin(GL_LINE);
        glVertex2i(180, 15);
        glVertex2i(10, 145);
    glEnd();

    glFlush();
}

int main (int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
    glutInitWindowPosition(50, 100);
    glutInitWindowSize(400, 300);
    glutCreateWindow("An Example OpenGL program");

    init();
    glutDisplayFunc(lineSegement());
    glutMainLoop();
    return 1;
}

Upvotes: 0

Views: 1495

Answers (1)

Reto Koradi
Reto Koradi

Reputation: 54652

glutDisplayFunc takes a function pointer as its argument. The syntax you are trying to use does not match that:

glutDisplayFunc(lineSegement());

In this statement, lineSegment() is a call to the lineSegment function, with the return value (which is void) being passed to glutDisplayFunc.

To pass the function pointer, you simply write the name of the function for glutDisplayFunc argument:

glutDisplayFunc(lineSegement);

Upvotes: 4

Related Questions