/* simple1.c draws a white filled rectangle on a black background OpenGL 1.x Laura Toma */ #include #include #include #include #ifdef __APPLE__ #include #else #include #endif /* forward declarations of functions */ void display(void); void keypress(unsigned char key, int x, int y); int main(int argc, char** argv) { /* open a window */ glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(500, 500); glutInitWindowPosition(100,100); glutCreateWindow(argv[0]); /* OpenGL init */ glClearColor(0, 0, 0, 0); /* set background color black*/ glEnable(GL_DEPTH_TEST); //not necessary in 2D /* callback functions */ glutDisplayFunc(display); glutKeyboardFunc(keypress); /* event handler */ glutMainLoop(); return 0; } void display(void) { //clear the screen, need to clear also the depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //set polygons to be filled glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); /* draw a polygon with vertices in [-1,1]x[-1,1]*/ glColor3f(1.0,1.0,1.0); /* set draw color white */ glBegin(GL_POLYGON); glVertex2f(-0.5,-0.5); glVertex2f(-0.5,0.5); glVertex2f(0.5,0.5); glVertex2f(0.5,-0.5); glEnd(); /* execute the drawing commands */ glFlush(); } void keypress(unsigned char key, int x, int y) { switch(key) { case 'q': exit(0); break; } }