// First Try: a first OpenGL graphics program #include // include windows header file #include // include OpenGL header file #include #include #include void myInit(); // function prototype for my initialization function void myDisplay(); // function prototype for my display function void main(int argc, char* argv[]) // main program function { glutInit(&argc, argv); // initialize the GLUT toolkit glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set display mode glutInitWindowSize(640, 480); // set window size glutInitWindowPosition(50, 100); // set window position on the screen glutCreateWindow("First Try"); // title and open the window glutDisplayFunc(myDisplay); // register my display function myInit(); // call my initialization function glutMainLoop(); // begin endless main loop } void myInit() // initialize Open GL state { glClearColor(1.0, 1.0, 1.0, 0.0); // set background color to white glColor3f(0.0, 0.0, 0.0); // set drawing color to black glPointSize(4.0); // set dot size to 4 pixels glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, 640.0, 0.0, 480.0); } void myDisplay() // draw my image { glClear(GL_COLOR_BUFFER_BIT); // clear the screen glBegin(GL_POINTS); // draw four points glVertex2i(150, 150); glVertex2i(200, 200); glVertex2i(150, 200); glVertex2i(200, 150); glEnd(); glColor3f(0.0, 1.0, 0.0); // set drawing color to green glBegin(GL_POLYGON); // draw triangle glVertex2f(10.0, 10.0); glVertex2f(100.0, 10.0); glVertex2f(10.0, 100.0); glEnd(); glFlush(); // send output to display }