/* drawcurve.cpp * This program demonstrates the drawing of a curve entered by * a moved mouse with one of the button held. * Use right button to exit. */ #include << X11/Xlib.h> #include << GLUT/glut.h> //#include << OpenGL/gl.h> //#include << stdlib.h> #include << stdio.h> const int screenWidth = 640, screenHeight = 480; class GLintPoint { public: GLint x, y; }; void myInit(void) { glClearColor (1.0, 1.0, 1.0, 0.0); // set black background color glColor3f (0.0f, 0.0f, 0.0f); // set the drawing color glPointSize (2.0); // set dot size 2 x 2 glMatrixMode (GL_PROJECTION); // set "camera shape" glLoadIdentity (); // clear the matrix // viewing transformation gluOrtho2D (0.0, (GLdouble)screenWidth, 0.0, (GLdouble)screenHeight); // set the Worlk Window } void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT); // clear the screen } void myMouse(int button, int state, int x, int y) { switch (button) { case GLUT_RIGHT_BUTTON: if (state == GLUT_DOWN) exit (-1); break; default: break; } } void myMovedMouse(int mouseX, int mouseY) { GLint x = mouseX; GLint y = screenHeight - mouseY; GLint brushSize = 20; glColor3f(1.0, 0.0, 0.0); // set the drawing color to red glRecti(x, y, x+brushSize, y+brushSize); glFlush(); } int main(int argc, char** argv) { glutInit(&argc, argv); // initialize the toolkit glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); // set display mode glutInitWindowSize (screenWidth, screenHeight); // set screen window size glutInitWindowPosition (100, 150); // set window position on screen glutCreateWindow (argv[0]); // open the screen window myInit (); glutDisplayFunc(myDisplay); // register redraw function glutMouseFunc(myMouse); // register myMouse function glutMotionFunc(myMovedMouse); // register myMoveMouse function glutMainLoop(); // go into a perpetual loop return 0; }