Here is a simple opengl program. I am trying to clear the screen before drawing a triangle. I called glClear () in my init () function, however, it seemed that it could not clear the screen.
#include <stdio.h> #include <stdlib.h> #include <GL/gl.h> #include <GL/glu.h> #include <GL/glut.h> void myIdleFunc() { glBegin(GL_TRIANGLES); { glColor3f(1.0f, 1.0f, 1.0f); glVertex2f(0.0f, 1.0f); glVertex2f(-1.0f, -1.0f); glVertex2f(1.0f, -1.0f); } glEnd(); glFlush(); usleep(1000000); } void init() { glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); glFlush(); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE); glutCreateWindow("Hello, World!"); init(); glutIdleFunc(myIdleFunc); glutMainLoop(); return 1; }
Here is a screenshot, text from the gnome's terminal in the background.

source share