#include #include void display(void) { /* clear all pixels */ glClear (GL_COLOR_BUFFER_BIT); /* draw white polygon (rectangle) with corners at * (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0) */ bool color_change=false; for(int x=0;x<=400;x+=100)//row maintain { for(int y=0;y<=400;y+=100)//column maintain { if(color_change) { glColor3f(1.0,0.75,0.0); color_change=!color_change; } else { glColor3f(0.0,0.0,0.0); color_change=!color_change; } glBegin(GL_QUADS); glVertex2i(x,y); glVertex2i(x,y+100); glVertex2i(x+100,y+100); glVertex2i(x+100,y); glEnd(); glFlush (); } } //glFlush (); } void init (void) { /* select clearing (background) color */ glClearColor (0.0, 0.0, 0.0, 0.0); /* initialize viewing values */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0,400.0,0.0,400.0); } /* * Declare initial window size, position, and display mode * (single buffer and RGBA). Open window with "hello" * in its title bar. Call initialization routines. * Register callback function to display graphics. * Enter main loop and process events. */ int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (600, 600); glutInitWindowPosition (100, 100); glutCreateWindow ("kl"); init (); glutDisplayFunc(display); glutMainLoop(); return 0; /* ISO C requires main to return int. */ }