/* * paint.c * * Sweep out rectangles using the mouse. * * Left button: sweep out a new rectangle * Middle button: clear the screen *key: exit * * Pat Hanrahan 1/97 */ #include <stdlib.h> #include <glut.h> int Width = 512; int Height = 512; Reshape(GLint w, GLint h) { Width = w; Height = h; glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, w, 0, h, 0.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB); glutInitWindowSize(512, 512); glutCreateWindow("Paint "); glutDisplayFunc(Display); glutReshapeFunc(Reshape); glutKeyboardFunc(Keyboard); glutMouseFunc(Mouse); glutMotionFunc(MouseDrag); glutMainLoop(); }
main is almost identical to the main in the Mondrian Example.
The only difference is the additional of an additional glut call to register a callback during mouse motion. This is done with the procedure glutMotionFunc which causes MouseDrag whenever the mouse is moved when a button is pressed.
The reshape procedure has been modified to set up a one to one integer mapping from window coordinates to viewport coordinates.
CS248: Introduction to Computer Graphics, Pat Hanrahan