#include #include #ifdef OSX #include #include #include #else #include #include #include #endif #include int width; int height; void init(){ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void myReshape(int w, int h) { glViewport(0, 0, w, h); width = w; height = h; } void DrawBox(){ glBegin(GL_QUADS); glVertex2f(0.0, 0.0); glVertex2f(0.10, 0.0); glVertex2f(0.10, .10); glVertex2f(0.0, .10); glEnd(); } void myDisplay() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(0,0,0); glPushMatrix(); for (int i=0; i<10; i++) { glPushMatrix(); for (int j=0; j<10; j++) { if ((i+j)%2 == 0) { glColor3f(0,0,0); } else { glColor3f(1,1,1); } DrawBox(); glTranslatef(.1,0,0); } glPopMatrix(); glTranslatef(0,.1,0); } glPopMatrix(); glutSwapBuffers(); } void myMouse(int b, int s, int x, int y) { if (b==GLUT_LEFT_BUTTON) { printf("Mouse click at %f %f\n", (float)x/(float)width, (float)y/(float)height); } } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(400,400); glutInitWindowPosition(0,0); glutCreateWindow(argv[0]); glMatrixMode(GL_PROJECTION); gluOrtho2D(0.0, 1.0, 0.0, 1.0); //Callbacks glutDisplayFunc(myDisplay); glutReshapeFunc(myReshape); glutMouseFunc(myMouse); init(); glutMainLoop(); return 0; }