A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
The problem is the semicolon after the function declaration.
In C++, this:
void display(void);
{
...
}
means:
-
void display(void);is only a declaration. - The following
{ ... }is just a separate block, not the body ofdisplay.
That explains the linker error: display was declared, but never actually defined.
The same issue exists for the other function. A function definition must not have a semicolon before its body.
Also, glutInit is a GLUT library function, not a function to redefine. The code shown appears to be intended as main, because it ends with return 0;.
Use this structure instead:
void display(void)
{
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH);
glutInitWindowPosition(100, 200);
glutInitWindowSize(800, 700);
glutCreateWindow("This is a window title");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
return 0;
}
Key points:
- Remove the
;aftervoid display(void)when defining the function. - Do not define
glutInitas a function. Call it frommain. -
return 0;belongs inmain, not in avoidfunction.
If removing the semicolon causes an error at {, that usually means there is another syntax problem nearby, but the semicolon itself is definitely wrong for a function definition.