#include <stdlib.h>
#include <glut.h>
#include "bitmap.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

/* Two-Dimensional Sierpinski Gasket          */
/* Generated Using Randomly Selected Vertices */
/* And Bisection                              */

/* BG modified code to include rotation as per assignment */
/* code was in text book */int masterWindow,subWindow1, subWindow2;

int width = 1000, height = 500;


float cube[16]={1,0,0,0,
			 0,1,0,0,
			 0,0,1,0,
			 0,0,0,1};
			 
float cubeSheared[16]={1,1,0,0,
			 0,1,0,0,
			 0,0,1,0,
			 0,0,0,1};
			 

void displaySub1(void){
	glClearColor(0.0, 0.0, 1.0, 1.0);
	glLoadIdentity();
	//get background to contrast
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0,1.0, 0.0);	
	//change color for suqare

    glMatrixMode(GL_MODELVIEW);
    glMultMatrixf(cube);
   
	glBegin(GL_POLYGON); 
	glVertex2f(-0.5, -0.5);        
	glVertex2f(-0.5, 0.5); 
	glVertex2f(0.5, 0.5);  
	glVertex2f(0.5, -0.5);    
	glEnd();
	glFlush(); 

}

void displaySub2(void){
	glClearColor(0.0, 0.50, 1.0, 1.0);
	glLoadIdentity();
	//get background to contrast
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0,1.0, 0.0);	
	//change color for suqare

    glMatrixMode(GL_MODELVIEW);
    glMultMatrixf(cubeSheared);
   
	glBegin(GL_POLYGON); 
	glVertex2f(-0.5, -0.5);        
	glVertex2f(-0.5, 0.5); 
	glVertex2f(0.5, 0.5);  
	glVertex2f(0.5, -0.5);    
	glEnd();
	glFlush(); 

}

void init(void){
	glClearColor(1.0, 0.0, 0.0, 1.0);
}

int main(int argc, char **argv)
{
//intitialize
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB);
glutInitWindowSize(width, height);
glutInitWindowPosition(100,100);

//make master window
masterWindow = glutCreateWindow("Square/Cube ? original and sheared");
glutDisplayFunc(init);

//make subwindow1 and call the square display
subWindow1 = glutCreateSubWindow (masterWindow, 0, 0, 500, 500);
glutDisplayFunc(displaySub1);

//make subwindow2 and call the triangle display
subWindow2 = glutCreateSubWindow (masterWindow, 500, 0, 500, 500);
glutDisplayFunc(displaySub2);

// Enter Glut Main Loop and wait for events
glutMainLoop();
return 0;
