// prog0.cpp : Defines the entry point for the console application.
//

#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"freeglut.lib")
#include <stdlib.h>
#include <math.h>
#include "gl/glut.h"
int w = 512, h = 512;
const int cs = 200;
const double PI = 3.14;
double angle = 0;
double k = 1;
void inc(void)
{
	angle -= 0.01;
	k += 0.002;
	glutPostRedisplay();

}
void disp(void)
{
	int l, r, t, b;
	double x, y;
	l = (w - cs) / 2; r = l + cs;
	b = (h - cs) / 2; t = b + cs;
	glClearColor(0.7, 0.7, 0.7, 1);
	glClear(GL_COLOR_BUFFER_BIT);//GL_DEPTH_BUFFER_BIT
	glLoadIdentity();
	glPushMatrix();
	glScalef(k, k, k);
	glTranslatef(100, 100, 0);
	glRotatef(angle, 0, 0, 1);
	glColor3ub(0, 120, 0);
	glBegin(GL_POLYGON);//GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP, 
					  //GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN,
					  //GL_QUADS, GL_QUAD_STRIP,
					  //GL_POLYGON
	for (int i = 0; i < 360; i++)
	{
		x = 25 * cos(2 * PI / 360 * i);
		y = 50 * sin(2 * PI / 360 * i);
		glVertex2f(x, y);
	}
	glEnd();
	glFinish();
	glPopMatrix();
	glFlush();
	glutSwapBuffers();
}
void reshape(int w1, int h1)
{
	w = w1; h = h1;
	glViewport(0, 0, w1, h1);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, w1, 0, h1, -1.0, 1.0);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glShadeModel(GL_SMOOTH);//GL_FLAT

}

void keyb(unsigned char key, int x, int y)
{
	const char esc = '\033';
	if (key == esc)exit(0);

}

int main(int argc, char* argv[])
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
	//GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL. 
	//За умовч.: GLUT_INDEX | GLUT_SINGLE 

	glutInitWindowSize(w, h);
	glutCreateWindow("Обертання овалу");
	glutDisplayFunc(disp);
	glutReshapeFunc(reshape);
	glutKeyboardFunc(keyb);
	glutIdleFunc(inc);
	glutMainLoop();
	return 0;
}

