Please, what’s wrong with my code which draws a 2D chessboard ,but the chessboard disappers when resizing the window and never shows up again?!
#include<GL/glut.h>
GLint row = 8;
void chessBoard()
{
glClear(GL_COLOR_BUFFER_BIT);
glPointSize(50);
glLoadIdentity();
glBegin(GL_POINTS);
glVertex2i(100,50);
glEnd();
GLint y = 380;
while(row>0)
{
GLint x = 100;
if(row%2==0)
{
for(int i=0;i<8;i++)
{
if(i%2!=0)
glColor3d(0.6,0.6,0.6);
else
glColor3d(0.2,0.2,0.2);
glRecti(x,480-y,x+50,480-(y+50));
x+=50;
}
}
else
{
for(int i=0;i<8;i++)
{
if(i%2!=0)
glColor3d(0.2,0.2,0.2);
else
glColor3d(0.6,0.6,0.6);
glRecti(x,480-y,x+50,480-(y+50));
x+=50;
}
}
y-=50;
row--;
}
glFlush();
}
void myReshape (int w, int h)
{
glViewport(0,0,w,h);
glClearColor(0.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,w,0.0,h);
glMatrixMode(GL_MODELVIEW);
}
void main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(640,480);
glutInitWindowPosition(0,0);
glutCreateWindow("HwOne, Ex2!");
glutReshapeFunc(myReshape);
glutDisplayFunc(chessBoard);
glutMainLoop();
}