/****************************************************************************
 * Micah Acinapura                                                          *
 * Tiled modified rectangles                                                *
 *  Linkage flags:                                                          *
 *   -lX11 -lGL -lGLU -lglut -lXmu -L/usr/X11R6/lib                         *
 ****************************************************************************/
// Libraries on linux systems
#include <X11/X.h> // X libraries
#include <GL/gl.h> // Basic OpenGL Libraries 
#include <GL/glut.h> // GL Utility Toolkit

/****************************************************************************
 * Package globals into a single global object                              *
 ****************************************************************************/
class board
{
public:

	//constructor
	board() {};
	
	void init()
    {
    //<<<<<<<<<<<<<<<<<<<<<<< myInit >>>>>>>>>>>>>>>>>>>>
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set display mode
    glutInitWindowSize(640,480);          // set window size
    glutInitWindowPosition(100, 150);     // set window position on screen
    glutCreateWindow("Tessolate"); // open the screen window
    glClearColor(1.0,1.0,1.0,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);
    }
	

	void create(int rows, int cols)
	{
		for(int i=1;i<=rows;i++)
		{
			for(int j=1;j<=cols;j++)
			{
				glBegin(GL_LINE_STRIP);

				glVertex2f(i*90,j*90);
				glVertex2f(i*90+30,j*90);
				glVertex2f(i*90+30,j*90+30);
				glVertex2f(i*90+60,j*90+30);
				glVertex2f(i*90+60,j*90);
				glVertex2f(i*90+90,j*90);
				glColor3f(1.0f, 0.0f, 0.0f);
				glVertex2f(i*90+90,j*90+90);
				glVertex2f(i*90+60,j*90+90);
				glVertex2f(i*90+60,j*90+120);
				glVertex2f(i*90+30,j*90+120);
				glVertex2f(i*90+30,j*90+90);
				glVertex2f(i*90,j*90+90);
				glVertex2f(i*90,j*90);

				glEnd();
			}
		}
	}
	
	// reDisplay method updates display 
  void reDisplay(void)
  {
    //<<<<<<<<<<<<<<<<<<<<<<<< myDisplay >>>>>>>>>>>>>>>>>

	glClear(GL_COLOR_BUFFER_BIT);         // clear the screen 
    	//glBegin(GL_LINE_STRIP);
    
        create(5,3);
    	//glEnd();	
   	glFlush();		                  // send all output to display 
  }

  // private

};

// This is the display object
board tiles;

// This is the wrapper for the reDisplay callback function
void wrapDisplay(void) { tiles.reDisplay(); }

//<<<<<<<<<<<<<<<<<<<<<<<< main >>>>>>>>>>>>>>>>>>>>>>
int main(int argc, char** argv)
{
  glutInit(&argc, argv);            // initialize the toolkit
  tiles.init();                      // initialize the display
  glutDisplayFunc(wrapDisplay);     // register redraw function
  glutMainLoop(); 		    // go into a perpetual loop
}

