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 error is caused by defining display inside main. In standard C++, a function definition cannot be nested inside another function, so the compiler reports a syntax error at the { after void display(void).
Move display out of main, then register it with glutDisplayFunc and glutIdleFunc.
#include <iostream>
#include <GL/gl.h>
#include <GL/glut.h>
#include <GL/freeglut.h>
#include <cmath>
using namespace std;
void display()
{
glClearColor(0.f, 0.f, 0.f, 1.f);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutCreateWindow("Hello World");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
return 0;
}
Also correct these points:
-
glutInitis normally called with arguments:glutInit(&argc, argv); - Header casing and paths should be consistent, for example
#include <GL/gl.h>rather than mixingGlandGL. -
glLoadIdentityandglFlushare valid OpenGL calls in the display function.
References: