/******************************************************************** File: interface.cc Author: Dana Vrajitoru Project: Optical illusion Last updated: January 23, 2017. Interface functions for the program. ********************************************************************/ #include "glheader.h" #include "interface.h" #include "illusion.h" #include #include using namespace std; int winWidth = 300, winHeight = 200; // some colors to play with float black[3] = {0.0, 0.0, 0.0}; float white[3] = {1.0, 1.0, 1.0}; float red[3] = {1.0, 0.0, 0.0}; float green[3] = {0.0, 1.0, 0.0}; float blue[3] = {0.0, 0.0, 1.0}; float purple[3] = {0.8, 0.0, 1.0}; // Create a window and set up the GUI functions void createWindowGUI() { glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB ); glutInitWindowSize(winWidth, winHeight); glutCreateWindow("Homework 2"); glutDisplayFunc(display); glutReshapeFunc(myResize); //glutIdleFunc(display); glutKeyboardFunc(key); glutSpecialFunc(spkey); //glutMouseFunc(mouse); } // Defining some of the application parameters void myinit() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, winWidth, 0, winHeight); glMatrixMode(GL_MODELVIEW); glClearColor (purple[0], purple[1], purple[2], 1.0); glColor3f(1.0, 0.0, 0.0); glLineWidth(2); } // To be called whenever the window is resized. void myResize(int w, int h) { winWidth = w; winHeight = h; glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, winWidth, 0, winHeight); glMatrixMode(GL_MODELVIEW); } // Callback function for redrawing the window void display(void) { // set the background in the color we want glClear(GL_COLOR_BUFFER_BIT); glClearColor (purple[0], purple[1], purple[2], 1.0); // draw the illution lensIllusion(5, white, winWidth, winHeight); // send the content of the view buffer to the window glFlush(); } // Callback function for an Ascii key being pressed void key(unsigned char key, int x, int y) { switch (key) { case 'q': case 'Q': exit(0); case ' ': glutPostRedisplay(); break; } } // Callback function for a special key being pressed void spkey(int key, int x, int y) { switch (key) { case GLUT_KEY_LEFT: glutPostRedisplay(); break; case GLUT_KEY_RIGHT: glutPostRedisplay(); break; } }