#define GLUT_DISABLE_ATEXIT_HACK
#include <windows.h>
#include <iostream>
#include <gl/glut.h>
using namespace std;
#define screenWidth 640
#define screenHeight 480
int size;
void myInit(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, (GLdouble)screenWidth, 0.0, (GLdouble)screenHeight);
}
void checkerboard(int size)
{
glClear(GL_COLOR_BUFFER_BIT);
GLdouble length = size / 8.0;
for(int i = 0; i < 8; i++)
for(int j = 0; j < 8; j++)
{
if((i + j) % 2 == 0)
glColor3f(0.6, 0.6, 0.6);
else
glColor3f(0.0, 0.0, 0.0);
glRectf((screenWidth - size) / 2.0 + j * length, (screenHeight - size) / 2.0 + i * length,
(screenWidth - size) / 2.0 + (j + 1) * length, (screenHeight -size) / 2.0 + (i + 1) * length);
}
glFlush();
}
void myDisplay(void)
{
checkerboard(size);
}
void main(int argc, char **argv)
{
glutInit(&argc, argv);
cout << "Enter the size of the checkerboard(not bigger than 480):";
cin >> size;
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(100, 150);
glutInitWindowSize(screenWidth, screenHeight);
glutCreateWindow("Checkboard");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
}