#include <GL/glut.h>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#define xpix 500
#include <cstring>
using
namespace
std;
float
r, g, b, x, y;
bool
flag =
true
;
int
counter = 0;
void
mouse(
int
button,
int
state,
int
mousex,
int
mousey)
{
if
(button == GLUT_LEFT_BUTTON
&& state == GLUT_DOWN) {
flag =
true
;
x = mousex;
y = 600 - mousey;
}
else
if
(button == GLUT_RIGHT_BUTTON
&& state == GLUT_DOWN) {
if
(counter > 4) {
counter = 0;
}
counter++;
glutPostRedisplay();
}
}
void
keyboard(unsigned
char
key,
int
x,
int
y)
{
switch
(key) {
case
27:
glutHideWindow();
}
}
void
display(
void
)
{
float
angle_theta;
if
(counter == 1) {
glColor3f(1, 0, 0);
}
else
if
(counter == 2) {
glColor3f(0, 1, 0);
}
else
if
(counter == 3) {
glColor3f(0, 1, 1);
}
else
if
(counter == 4) {
glColor3f(0.5, 0, 1);
}
else
if
(counter == 5) {
glColor3f(0, 0.5, 1);
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 800.0,
0.0, 600.0);
if
(flag) {
glBegin(GL_POLYGON);
for
(
int
i = 0; i < 360; i++) {
angle_theta = i * 3.142 / 180;
glVertex2f(x + 50 *
cos
(angle_theta),
y + 50 *
sin
(angle_theta));
}
glEnd();
}
glFlush();
}
int
main(
int
argc,
char
** argv)
{
glutInit(&argc, argv);
glutInitWindowSize(800, 600);
glutInitWindowPosition(100, 100);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutCreateWindow(
"Circle Creation "
"on mouse click"
);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
glutMainLoop();
}