#include <GL\glut.h>
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <math.h>

GLsizei winWidth=1010, winHeight=705;
GLint ptCtr=0;
int choise = 10;
int d1 , d2 , d3 , d4 , d5 ;
int t1,t2,t3 ;


class scrPt{
public: GLint x,y;
};
static scrPt endPt1,endPt2;
void init(void)
{
     glClearColor(0.7, 0.7, 0.7,1.0);
     //glColor3f(1.0, 1.0, 0.9);
     glMatrixMode(GL_PROJECTION);
     gluOrtho2D(0.0, 200.0, 0.0, 150.0);
 }

void displayFcn(void)
  {
    glClear(GL_COLOR_BUFFER_BIT);
    //Quads
      glColor3f(1.0, 1.0, 1.0);
   glBegin(GL_QUADS);

   glVertex2f(0,0);
   glVertex2f(200,0);
   glVertex2f(200,705);
   glVertex2f(0,705);
   glEnd();
   // line1
    glColor3f(0.5, 0.5, 0.5);
    glBegin (GL_LINES);
    glVertex2f (0, 50);
    glVertex2f (200, 50);
    glEnd();
  // line1

    glBegin (GL_LINES);
    glVertex2f (0, 150);
    glVertex2f (200, 150);
    glEnd();

     // line2
    glBegin (GL_LINES);
    glVertex2f (0, 300);
    glVertex2f (200, 300);
    glEnd();

     // line3
    glBegin (GL_LINES);
    glVertex2f (0, 450);
    glVertex2f (200, 450);
    glEnd();

     // line4
    glBegin (GL_LINES);
    glVertex2f (0, 600);
    glVertex2f (200, 600);
    glEnd();

       glBegin (GL_LINES);
    glVertex2f (0, 705);
    glVertex2f (200,600);
    glEnd();

      glColor3f(0.5, 0.3, 0.5);
     glBegin (GL_LINES);
     glVertex2f (50, 80);
     glVertex2f (150, 100);
     glEnd();
    //****
      glColor3f(0.5, 0.3, 0.6);
     glBegin (GL_LINE_LOOP);
     glVertex2f (50, 170);
     glVertex2f (50, 250);
     glVertex2f (150, 250);
     glVertex2f (150, 170);
     glEnd();
    //--------
      glColor3f(0.6, 0.3, 0.6);
     glBegin (GL_LINE_LOOP);
     glVertex2f (50, 350);
     glVertex2f (150, 350);
     glVertex2f (100, 400);
     glEnd();
      //*-*-*-*-*-*

   //   drowCircle(100,100,200,200) ;
       int x = 0,radius=50,xCenter=100, yCenter=520;
	int y = radius;
	int f = 1-radius;


		while (x < y) {
			x++;
			if (f < 0)
				f += 2*x+1;
			else {
				y--;
				f += 2*(x-y)+1;
    	  }

    	  glBegin(GL_POINTS);
				glVertex2i (xCenter+x, yCenter+y);
				glVertex2i (xCenter+y, yCenter+x);

            	glVertex2i (xCenter-x, yCenter+y);
				glVertex2i (xCenter+y, yCenter-x);

            	glVertex2i (xCenter+x, yCenter-y);
				glVertex2i (xCenter-y, yCenter+x);

            	glVertex2i (xCenter-x, yCenter-y);
				glVertex2i (xCenter-y, yCenter-x);


   	 glEnd();
		}
      //-*-+-+-+-+-+-+*/*/
      glColor3f(0.7, 0.8, 0.9);
      glBegin (GL_POLYGON);
      glVertex2f (50,610);
      glVertex2f (50,650);
      glVertex2f (150,650);
      glVertex2f (150, 610);
      glEnd();




     //*******color****
      //1
        glColor3f(1.0, 0.0, 0.0);
      glBegin (GL_POLYGON);
      glVertex2f (0,0);
      glVertex2f (0,25);
      glVertex2f (50,25);
      glVertex2f (50, 0);
      glEnd();
     //2
        glColor3f(0.0, 1.0, 0.0);
      glBegin (GL_POLYGON);
      glVertex2f (0,25);
      glVertex2f (0,50);
      glVertex2f (50,50);
      glVertex2f (50, 25);
      glEnd();
    //3
       glColor3f(0.0, 0.0, 1.0);
      glBegin (GL_POLYGON);
      glVertex2f (50,0);
      glVertex2f (50,25);
      glVertex2f (100,25);
      glVertex2f (100, 0);
      glEnd();
    //4
     glColor3f(0.8, 0.1, 0.4);
      glBegin (GL_POLYGON);
      glVertex2f (50,25);
      glVertex2f (50,50);
      glVertex2f (100,50);
      glVertex2f (100, 25);
      glEnd();
    //5
     glColor3f(1.0, 0.6, 0.1);
      glBegin (GL_POLYGON);
      glVertex2f (100,0);
      glVertex2f (100,25);
      glVertex2f (150,25);
      glVertex2f (150, 0);
      glEnd();
    //6
     glColor3f(0.6, 0.5, 1.0);
      glBegin (GL_POLYGON);
      glVertex2f (100,25);
      glVertex2f (100,50);
      glVertex2f (150,50);
      glVertex2f (150, 25);
      glEnd();
    //7
     glColor3f(1.0, 0.9, 0.0);
      glBegin (GL_POLYGON);
      glVertex2f (150,0);
      glVertex2f (150,25);
      glVertex2f (200,25);
      glVertex2f (200, 0);
      glEnd();
    //8
     glColor3f(0.2, 0.8, 0.4);
      glBegin (GL_POLYGON);
      glVertex2f (150,25);
      glVertex2f (150,50);
      glVertex2f (200,50);
      glVertex2f (200,25);
      glEnd();
    //end color***********



   glFlush();
  }

void drowCircle(scrPt endPt1,scrPt endPt2)
 {
  int dx , dy ;
  dx = endPt2.x - endPt1.x ;
  dy = endPt2.y - endPt1.y ;
  double r = pow ( ( pow(dx,2) + pow(dy,2)) , 0.5 ) ;
     int x = 0,radius= r , xCenter=endPt1.x , yCenter=endPt1.y;
	int y = radius;
	int f = 1-radius;


		while (x < y) {
			x++;
			if (f < 0)
				f += 2*x+1;
			else {
				y--;
				f += 2*(x-y)+1;
    	  }

    	  glBegin(GL_POINTS);
				glVertex2i (xCenter+x, yCenter+y);
				glVertex2i (xCenter+y, yCenter+x);

            	glVertex2i (xCenter-x, yCenter+y);
				glVertex2i (xCenter+y, yCenter-x);

            	glVertex2i (xCenter+x, yCenter-y);
				glVertex2i (xCenter-y, yCenter+x);

            	glVertex2i (xCenter-x, yCenter-y);
				glVertex2i (xCenter-y, yCenter-x);


   	 glEnd();
		}
   }

void drowRect(scrPt endPt1,scrPt endPt2){
glRectf(endPt1.x , endPt1.y , endPt2.x , endPt2.y );
}

void drowLine(scrPt endPt1,scrPt endPt2){
     glBegin (GL_LINES);
     glVertex2f (endPt1.x, endPt1.y);
     glVertex2f (endPt2.x, endPt2.y);
     glEnd();
}
 void check ()
  {
     if(endPt1.x >0 && endPt1.x <200 && endPt1.y > 600 && endPt1.y < 705 )
         choise = 1 ;
     else if(endPt1.x >0 && endPt1.x <200 && endPt1.y > 450 && endPt1.y < 600 )
         choise = 2 ;
     else if(endPt1.x >0 && endPt1.x <200 && endPt1.y > 300 && endPt1.y < 450 )
         choise = 3 ;
     else if(endPt1.x >0 && endPt1.x <200 && endPt1.y > 150 && endPt1.y < 300 )
         choise = 4 ;
     else if(endPt1.x >0 && endPt1.x <200 && endPt1.y > 50 && endPt1.y < 150 )
         choise = 5 ;

  }


void polyline(GLint button,GLint action,GLint xMouse,GLint yMouse)
{
 static scrPt endPt1,endPt2;
    if(ptCtr==0)
        {
            if (button==GLUT_LEFT_BUTTON&&action==GLUT_DOWN)
                {
                  endPt1.x=xMouse;
                  endPt1.y=winHeight-yMouse;
                  ptCtr=1;
                  cout<"11111";
                }
            else if(button==GLUT_RIGHT_BUTTON)exit(0);
       }
    else if(button==GLUT_LEFT_BUTTON&&action==GLUT_DOWN)
           {
              endPt2.x=xMouse;
              endPt2.y=winHeight-yMouse;
              ptCtr=0;
              drowLine(endPt1,endPt2);
           }

   else if(button==GLUT_RIGHT_BUTTON)exit(0);
   glFlush();
    }




void winReshapeFcn(GLint newWidth,GLint newHeight){

glViewport(0,0,newWidth,newHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, GLdouble (newWidth), 0.0, GLdouble (newHeight));
winWidth=newWidth;
winHeight=newHeight;

}



void main(int argc,char** argv)
{	   glutInit(&argc, argv);
  		glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB );
  		glutInitWindowPosition(-900,-600);
      glutInitWindowSize(winWidth,winHeight);
  		glutCreateWindow("OPEN GL BROJECT");
       init();
  	  	glutDisplayFunc(displayFcn);
      glutReshapeFunc(winReshapeFcn);
      glutMouseFunc(polyline);

     	glutMainLoop();
      }

