Computer Graphics – 9. (i) Chess Board

[wpdm_package id=’1224′]
Sample Output –Chess_Board_1

[sourcecode lang=”cpp”]
#include<GL/glut.h>

void chess_board(void){
glClear(GL_COLOR_BUFFER_BIT);
int y=290,s=30,c=0,r=0,x;
while(r<8){
x=10;
while(c<8){
glColor3f(1.0,1.0,1);
glRecti(x,y,x+30,y+30);
x+=40;
c+=1;
}
c=0;y-=40;
r+=1;
}
glFlush();
}
int main(int argc,char **argv){
glutInit(&argc,argv);
glutInitWindowSize(330,330);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutCreateWindow("Chess Board");

glutDisplayFunc(chess_board);
glClearColor(0.0,0.0,0.0,0.0);
gluOrtho2D(0,330,0,330);
glutMainLoop();
}
[/sourcecode]

To compile the above program in ubuntu terminal –
# g++ -lGL -lGLU -lglut Chess_Board_1.cpp
# ./a.out

Leave a Reply

Your email address will not be published. Required fields are marked *