/************************************************************ * File: simple1.cc * Author: C.Yap * Date: Sep 7, 2001. * Synopsis: * Elaboration of simple.cc * --Puts a multicolor frame around window * ************************************************************/ #include // needed for use of cout #include // needed for math functions exp(x), etc // #include #include ///////////////////////////////////////////////////////////// // Constants ///////////////////////////////////////////////////////////// const int screenWidth = 640; const int screenHeight = 480; ///////////////////////////////////////////////////////////// // Initialization ///////////////////////////////////////////////////////////// void myInit(void) { glClearColor(1.0, 1.0, 1.0, 0.0); // background is white glColor3f(0.0f, 0.0f, 1.0f); // pen is blue glPointSize(2.0); // dot is 2pixels wide glMatrixMode(GL_PROJECTION); // set camera shape glLoadIdentity(); // initialize projection matrix gluOrtho2D(0.0, (GLdouble)screenWidth, 0.0, (GLdouble)screenHeight); // set matrix for 2D graphics }//myInit() ///////////////////////////////////////////////////////////// // callback functions ///////////////////////////////////////////////////////////// void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT); // clear screen // DRAW A COLORED FRAME AROUND WINDOW glLineWidth(4.0); glBegin(GL_LINE_LOOP); glColor3f(0.1, 0.9, 0.1); // green glVertex2d(screenWidth-10, screenHeight-10); glVertex2d(screenWidth-10, 10); glColor3f(0.9, 0.1, 0.1); // red glVertex2d(10, 10); glColor3f(0.0, 0.0, 0.0); // black glVertex2d(10, screenHeight-10); glColor3f(0.9, 0.9, 0.1); // yellow glEnd(); // PLOT FUNCTION: y = exp(-x) * cos (8 * pi * x) // -- 8*pi gives us 4 full circles. glBegin(GL_POINTS); glColor3f(0.0f, 0.0f, 1.0f); // pen is blue for (GLdouble x = 10; x < screenWidth-10; x += 1) { GLdouble y = exp(-3*x/screenWidth) * cos(16 * 3.14159265 * x/screenWidth); y = y*(screenHeight/2) + (screenHeight/2) ; glVertex2d(x, y) ; }//for glEnd(); glFlush(); }//myDisplay() ///////////////////////////////////////////////////////////// // MAIN PROGRAM ///////////////////////////////////////////////////////////// void main(int argc, char** argv) { ///////////////////////////////////////////////////////////// // initialization and create screen window glutInit(&argc, argv); // initialize toolkit glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // display mode (single buffer) glutInitWindowSize(screenWidth, screenHeight); // window size glutInitWindowPosition(100, 150); // position of top right corner glutCreateWindow("My First Window"); // open it ///////////////////////////////////////////////////////////// // register callback functions glutDisplayFunc(myDisplay); // redraw window event // glutReshapeFunc(myReshape); // reshape window event // glutMouseFunc(myMouse); // mouse button event // glutKeyboardFunc(myKeyboard); // keyboard event myInit(); // special initialization glutMainLoop(); // mandatory final call to glut }//main ///////////////////////////////////////////////////////////// // The end /////////////////////////////////////////////////////////////