/************************************************************ * File: window.cc * Author: C.Yap * Date: Sep 23, 2001. * Synopsis: * OpenGL program for lecture 2 * Illustrates the initialization for a display window * in GLUT. * ************************************************************/ #include // needed for use of cout #include // needed for math functions exp(x), etc // #include #include ///////////////////////////////////////////////////////////// // constants ///////////////////////////////////////////////////////////// int screenWidth = 640; int screenHeight = 640; ///////////////////////////////////////////////////////////// // callback functions ///////////////////////////////////////////////////////////// void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT); // clear screen // Exercise: what would happen if you do not clear screen? glColor3f(0.0f, 0.0f, 1.0f); // pen is blue glBegin(GL_LINES); glVertex2d(10, 10) ; glVertex2d(900, 900) ; 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 // glClearColor(1.0, 1.0, 1.0, 0.0); // background is white (default black) glColor3f(0.0f, 0.0f, 1.0f); // pen is blue (default black) // glPointSize(2.0); // dot is 2pixels wide (default 1) glMatrixMode(GL_PROJECTION); // set camera shape glLoadIdentity(); // initialize projection matrix gluOrtho2D(0.0, (GLdouble)screenWidth, 0.0, (GLdouble)screenHeight); // set matrix for 2D graphics ///////////////////////////////////////////////////////////// // register callback functions ///////////////////////////////////////////////////////////// glutDisplayFunc(myDisplay); // redraw window event ///////////////////////////////////////////////////////////// glutMainLoop(); // mandatory final call to glut ///////////////////////////////////////////////////////////// }//main ///////////////////////////////////////////////////////////// // The end /////////////////////////////////////////////////////////////