#include<stdlib.h>
#include<GL/glut.h>
GLfloat vertices[][2] = {
{-0.1, 0.1}, {-0.1, -0.1}, {0.1, -0.1}, {0.1, 0.1}
};
int R=120, G=0, B=120;
double rec_size=1;
void drawSquare(){
int i;
glColor3ub( R, G, B );
glBegin(GL_POLYGON);
for(i=0; i<4; i++) glVertex3fv(vertices[i]);
glEnd();
}
void display(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glScalef(rec_size, rec_size, rec_size);
drawSquare();
glFlush();
glutSwapBuffers();
}
void mouse(int btn, int state, int x, int y){
if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN && rec_size<32){
R+=20; B-=20;
rec_size *= 2;
}
if(btn==GLUT_RIGHT_BUTTON && state==GLUT_DOWN && rec_size>0.1){
R-=20; B+=20;
rec_size /= 2;
}
glutPostRedisplay();
}
void myReshape(int w, int h){
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2.0, 2.0, -2.0 * (GLfloat)h / (GLfloat)w, 2.0 * (GLfloat)h / (GLfloat)w, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
}
void main(int argc, char **argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutCreateWindow("Square!!");
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}