Wednesday, June 27, 2012

Chess in OpenGL Complete Code



   1:  #include<Windows.h>
   2:  #include<glut.h>   
   3:   
   4:  void Draw()
   5:  {
   6:      glClear(GL_COLOR_BUFFER_BIT);
   7:      float b=-0.99;             //  WIDTH
   8:      float c=-0.74;            //   WIDTH
   9:      float s=-0.99;           //    HEIGHT    
  10:      float e=-0.74;           //    HEIGHT
  11:      int a=0;  
  12:   
  13:      for(int o=0; o<8;o++)  
  14:      {
  15:          if(o==0 || o==2 || o==4 || o==6 || o==8 )
  16:              {   
  17:          for(a=0; a<8; a++)
  18:                     {
  19:                         glBegin(GL_POLYGON);
  20:                         glVertex3f(b,s,0.0);
  21:                         glVertex3f(c,s,0.0);   
  22:                         glVertex3f(c,e,0.0);
  23:                         glVertex3f(b,e,0.0);
  24:   
  25:                          if( a==0 ||  a==2 || a==4 || a==6 || a==8 )
  26:                             {
  27:                                glColor3f(0.0,0.0,0.0);
  28:                             }
  29:                          else
  30:                             glColor3f(1.0,1.0,1.0);
  31:                             glEnd();
  32:                             b=b+0.25;       
  33:                             c=c+0.25;                                  
  34:                             glFlush();
  35:                     }
  36:          b=-0.99;              //back to left position
  37:          c=-0.74;              //back to left position
  38:          }
  39:   
  40:          else if(o==1 || o==3 || o==5 || o==7 || o==9)
  41:              {       
  42:                  glColor3f(0.0,0.0,0.0);
  43:                  for(a=0; a<8; a++)
  44:                          {
  45:                              glBegin(GL_POLYGON);
  46:                              glVertex3f(b,s,0.0);
  47:                              glVertex3f(c,s,0.0);      
  48:                              glVertex3f(c,e,0.0);              
  49:                              glVertex3f(b,e,0.0);   
  50:   
  51:                              if( a==0 ||  a==2 || a==4 || a==6 || a==8)
  52:                                  {
  53:                                     glColor3f(1.0,1.0,1.0);
  54:                                  }
  55:                      else
  56:                          glColor3f(0.0,0.0,0.0);
  57:                          glEnd();
  58:                          b=b+0.25;      
  59:                          c=c+0.25;         
  60:                          glFlush();
  61:                          }   
  62:              }
  63:          b=-0.99;                
  64:          c=-0.74;                         
  65:          e=e+0.25;                 
  66:          s=s+0.25;                  
  67:          glColor3f(1.0,1.0,1.0);
  68:      }   
  69:  }
  70:   
  71:  void Initialize()
  72:  {
  73:      glClearColor(0.0,0.0,0.0,0.0);
  74:      glMatrixMode(GL_PROJECTION);
  75:      glLoadIdentity();
  76:      glOrtho(2.0,2.0,2.0,2.0,2.0,2.0);       
  77:  }
  78:   
  79:  int main(int iArgc,char** cppArgv)
  80:  {
  81:      glutInit(&iArgc,cppArgv);
  82:      glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  83:      glutInitWindowPosition(200,200);
  84:      glutCreateWindow("Chess By Muhammad Taqi");
  85:      Initialize();
  86:      glutDisplayFunc(Draw);
  87:      glutMainLoop();
  88:      return 0;
  89:  }
 
 

No comments:

Post a Comment