Sonia kh 0 Newbie Poster

I have mentioned the code for checker board made on visual studio .I dont know whats the problem with this code .. it just draw only one row of checker board on the drawing window :( help me

//#include <windows.h>   // use as needed for your system
//#include <gl/Gl.h>
#include<stdlib.h>
#include <GL/glut.h>
#include<conio.h>
#include<fstream>
#include<iostream>
int y1=0;
int x1=0;
int x2=0;
int y2=0;


using namespace std;
//<<<<<<<<<<<<<<<<<<<<<<< myInit >>>>>>>>>>>>>>>>>>>>

//void drawPolyLineFile(char * fileName)
//{
//  fstream inStream;//fstream provides an interface to read and write data from files as input/output streams.
//  inStream.open(fileName, ios ::in);  // open the file
//  if(inStream.fail())
//      return;
//  glClear(GL_COLOR_BUFFER_BIT);      // clear the screen 
//  GLint numpolys, numLines, x ,y;
//  inStream >> numpolys;              // read the number of polylines
//  for(int j = 0; j < numpolys; j++)  // read each polyline
//  {
//      inStream >> numLines;
//      glBegin(GL_LINE_STRIP);      // draw the next polyline
//      for (int i = 0; i < numLines; i++)
//      {
//          inStream >> x >> y;        // read the next x, y pair
//          glVertex2i(x, y);
//      }
//      glEnd();
//  }
//  
//  inStream.close();
//}

/////////////////////////////////////////////////////
 void myInit(void)
 {
    glClearColor(0.5,0.5,0.5,0.0);          // set white background color
    glColor3f(0.0f, 0.0f, 0.0f);            // set the drawing color 
    glPointSize(4.0);                       // a ‘dot’ is 4 by 4 pixels
    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity();
    gluOrtho2D (0.0, 640.0, 0.0, 480.0);
}
//<<<<<<<<<<<<<<<<<<<<<<<< myDisplay >>>>>>>>>>>>>>>>>
void myDisplay(void)
{

    glClearColor(1.0,1.0,1.0,0.0); // white background 
    glClear(GL_COLOR_BUFFER_BIT);  // clear the window
    glColor3f(0.6,0.6,0.6); 
      // bright gray


    for(int i = 1; i<=8 ; i++)  // read each polyline
    { 

        glColor3f(0.6,0.6,0.6);
        if(i>1)
    {y1=y1+20;}
        for (int j = 1; j<=8 ; j++)
    {
        if(i%2!=0)
        {
        if(j%2!=0)
        {
        glColor3f(0.6,0.6,0.6);}
        }


         if(i%2!=0)
        {
        if(j%2==0)
        {
        glColor3f(0.0,0.0,0.0);}
        }

          if(i%2==0)
        {
        if(j%2!=0)
        {
        glColor3f(0.0,0.0,0.0);}
        }

            if(i%2==0)
        {
        if(j%2==0)
        {
        glColor3f(0.6,0.6,0.6);}
        }

        if (j==1)
        {
                //glColor3f(0.0,0.0,0.0);   
            x1=j*20;
        y1=j*20;
        x2=x1+20;
        y2=y1+20;
        glRecti(x1, y1, x2, y2);
        }
        else
        {//glColor3f(0.6,0.6,0.6);  
        x1=x2;
        y1=y1;
        x2=x2+20;
        y2=y1+20;
        glRecti(x1, y1, x2, y2);}

        /*if(i==2)
        {glClearColor(0.5,0.0,0.0,0.0);}*/

    }   

    }

          // dark gray


    glFlush();
       // send all output to display 
}



//<<<<<<<<<<<<<<<<<<<<<<<< main >>>>>>>>>>>>>>>>>>>>>>
void main(int argc, char** argv)
{
    glutInit(&argc, argv);          // initialize the toolkit
    glutInitDisplayMode(GLUT_SINGLE |GLUT_RGB); // set display mode
    glutInitWindowSize(640,480);     // set window size
    glutInitWindowPosition(100, 150); // set window position on screen
    glutCreateWindow("Draw Dino"); // open the screen window
    glutDisplayFunc(myDisplay);
    myInit(); 
    glutMainLoop();              // go into a perpetual loop
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.