/* * DrawYellowSquare.cpp * * Created on: Mar 1, 2013 * Author: debure */ // Simple program to draw a yellow square where the user clicks #include #include #include void display() { // don't glClear here or previous square in erases each time a new one is drawn glFlush(); } void init() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, 500.0, 500.0, 0.0); // makes y right side up glMatrixMode(GL_MODELVIEW); glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); // clear display at start-up glColor3f(1.0, 1.0, 1.0); } void mouse(int button, int state, int x, int y) { if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) { exit(0); } else if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { // NOTE: x, y are in screen coordinates!! This affect size and y placement. glColor3f(1.0, 1.0, 0.0); glRecti(x-10, y-10, x+10, y+10); // draws a rectangle // uses the input y without correction because glOrtho sets up direction glFlush(); } } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitWindowSize(500,500); glutCreateWindow("simple"); glutDisplayFunc(display); init(); glutMouseFunc (mouse); glutMainLoop(); return 0; }