/* Example 1.1.point.c: draw multiple randomly generated points */ // by Jim X. Chen; September 2000 #include #include #define Height 400 #define Width 400 void display(void) { int x, y; //1. specify a drawing color: red glColor3f(1, 0, 0); //2. generate a random point x = rand() % Width; y = rand() % Height; //3. specify to draw the point glBegin(GL_POINTS); glVertex2i (x,y); glEnd(); //4. make picture appear on the screen glFlush(); } static void reshape(int w, int h) { //5. specify the window's coordinates glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho(0, Width, 0, Height, -1.0, 1.0); } int main(int argc, char **argv) { //6. initialize a drawing area & window glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE); glutInitWindowSize(Width, Height); glutCreateWindow("Example 1.1.point.c: randomly generated points"); //7. event callback functions glutReshapeFunc(reshape); glutDisplayFunc(display); glutIdleFunc(display); glutMainLoop(); }