C++ program for 8 X 8 Chess Board using OpenGL
kw.cpp
#include <iostream>
#include <GL/glut.h>
int clr = 0, size = 400;

void drawSquare(GLint x1, GLint y1, GLint x2, GLint y2, GLint x3, GLint y3, GLint x4, GLint y4)
{
    if (clr == 1)
    {
        glColor3f(0, 0, 0);
        clr = 0;
    }
    else
    {
        glColor3f(1, 1, 1);
        clr = 1;
    }

    glBegin(GL_POLYGON);
        glVertex2i(x1, y1);
        glVertex2i(x2, y2);
        glVertex2i(x3, y3);
        glVertex2i(x4, y4);
    glEnd();
}

void chessBoard()
{
    GLint x, y;
    for (x = 0; x <= size; x += 50)
    {
        for (y = 0; y <= size; y += 50)
        {
            drawSquare(x, y + 50, x + 50, y + 50, x + 50, y, x, y);
        }
    }
    glFlush();
}

int main(int agrc, char **argv)
{
    glutInit(&agrc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH);
    glutInitWindowSize(size, size);
    glutCreateWindow("8 X 8 Chess Board");
    glMatrixMode(GL_PROJECTION);
    gluOrtho2D(0, size, size, 0);
    glutDisplayFunc(chessBoard);
    glutMainLoop();
}
Output
kodingwindow@kw:~$ g++ kw.cpp -lGL -lGLU -lglut
kodingwindow@kw:~$ ./a.out
Advertisement