#include <gl//glut.h>
//#include<math.h>
void init ()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glPointSize(5.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//setting the resolution for the 2D object
gluOrtho2D(0.0,300.0, 0.0, 300.0); //void gluOrtho2D(left,r,bot,top);
//gluOrtho2D sets up a two-dimensional orthographic viewing region.
//equivalent to calling glOrtho with near = -1 and far = 1 .
//void glOrtho(left,right,bottom,top,nearVal,farVal);
}
void CheckerBoard()
{
glPointSize(5.0);
//
int x1,y1;
x1=0;
y1=500;
for(int i=1;i<=8;i++)
{
x1=x1+50;
y1=500;
for(int j=1;j<=8;j++)
{
y1=y1-50;
glBegin(GL_QUADS);
if(i%2 != 0 )
{
if( j%2 != 0 )
{
//glColor3f(1.0,1.0,1.0); //white
glColor3f(202.0/255.00, 169.0/255.0,
106.0/255.0);//orange
glVertex3f(x1,y1,0);
glVertex3f(x1+50,y1,0);
glVertex3f(x1+50,y1-50,0);
glVertex3f(x1,y1-50,0);
}
else
{
glColor3f(146.0/255.0, 140.0/255.0,
168.0/255.0);//brown
//glColor3f(0.0,0.0,0.0); //black
glVertex3f(x1,y1,0);
glVertex3f(x1+50,y1,0);
glVertex3f(x1+50,y1-50,0);
glVertex3f(x1,y1-50,0);
}
}
else{
if(j%2 != 0)
{
glColor3f(146.0/255.0, 140.0/255.0,
168.0/255.0);
//glColor3f(0.0,0.0,0.0);
glVertex3f(x1,y1,0);
glVertex3f(x1+50,y1,0);
glVertex3f(x1+50,y1-50,0);
glVertex3f(x1,y1-50,0);
}
else{
glColor3f(202.0/255.00, 169.0/255.0,
106.0/255.0);
// glColor3f(1.0,1.0,1.0);
glVertex3f(x1,y1,0);
glVertex3f(x1+50,y1,0);
glVertex3f(x1+50,y1-50,0);
glVertex3f(x1,y1-50,0);
}
}
glEnd();
}
}
}
void Display()
{
glClear(GL_COLOR_BUFFER_BIT);
//calling
CheckerBoard();
glFlush ();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (900, 450);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Assignment: Lab 2");
init ();
glutDisplayFunc(Display);
glutMainLoop();
}

Ass day2 1_checkerboard...copy in cpp

  • 1.
    #include <gl//glut.h> //#include<math.h> void init() { glClearColor(0.0, 0.0, 0.0, 0.0); glPointSize(5.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); //setting the resolution for the 2D object gluOrtho2D(0.0,300.0, 0.0, 300.0); //void gluOrtho2D(left,r,bot,top); //gluOrtho2D sets up a two-dimensional orthographic viewing region. //equivalent to calling glOrtho with near = -1 and far = 1 . //void glOrtho(left,right,bottom,top,nearVal,farVal); } void CheckerBoard() { glPointSize(5.0); // int x1,y1; x1=0; y1=500; for(int i=1;i<=8;i++) { x1=x1+50; y1=500; for(int j=1;j<=8;j++) { y1=y1-50; glBegin(GL_QUADS); if(i%2 != 0 ) { if( j%2 != 0 ) { //glColor3f(1.0,1.0,1.0); //white glColor3f(202.0/255.00, 169.0/255.0, 106.0/255.0);//orange glVertex3f(x1,y1,0); glVertex3f(x1+50,y1,0); glVertex3f(x1+50,y1-50,0); glVertex3f(x1,y1-50,0); } else { glColor3f(146.0/255.0, 140.0/255.0, 168.0/255.0);//brown //glColor3f(0.0,0.0,0.0); //black glVertex3f(x1,y1,0); glVertex3f(x1+50,y1,0); glVertex3f(x1+50,y1-50,0); glVertex3f(x1,y1-50,0); } }
  • 2.
    else{ if(j%2 != 0) { glColor3f(146.0/255.0,140.0/255.0, 168.0/255.0); //glColor3f(0.0,0.0,0.0); glVertex3f(x1,y1,0); glVertex3f(x1+50,y1,0); glVertex3f(x1+50,y1-50,0); glVertex3f(x1,y1-50,0); } else{ glColor3f(202.0/255.00, 169.0/255.0, 106.0/255.0); // glColor3f(1.0,1.0,1.0); glVertex3f(x1,y1,0); glVertex3f(x1+50,y1,0); glVertex3f(x1+50,y1-50,0); glVertex3f(x1,y1-50,0); } } glEnd(); } } } void Display() { glClear(GL_COLOR_BUFFER_BIT); //calling CheckerBoard(); glFlush (); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (900, 450); glutInitWindowPosition (100, 100); glutCreateWindow ("Assignment: Lab 2"); init (); glutDisplayFunc(Display); glutMainLoop(); }