#include #include #include #include #define WinWidth 640 #define WinHeight 480 const int MAX_POINTS = 20 ; int Npoints = 0 ; int Points[MAX_POINTS][2] ; void myInit(void) { glClearColor(1.0,1.0,1.0,0.0) ; glColor3f(0.0, 0.0, 0.0) ; glPointSize(4.0) ; glMatrixMode(GL_PROJECTION) ; glLoadIdentity() ; gluOrtho2D(0.0, 640.0, 0.0, 480.0) ; } void myMouse(int button, int state, int x, int y) { if( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) { if( Npoints != MAX_POINTS ) { Points[Npoints][0] = x ; Points[Npoints][1] = WinHeight - y ; Npoints++ ; printf("x = %d, y = %d\n", x,y) ; } else printf("Number of Points Exceeded\n") ; } // Tell the system to redraw the window glutPostRedisplay() ; } // The function that draws everything void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT) ; glBegin(GL_POINTS) ; glVertex2i(100,50) ; glVertex2i(100,130) ; glVertex2i(150,130) ; int i ; for(i = 0; i < Npoints ; i++ ) glVertex2i(Points[i][0],Points[i][1]) ; glEnd() ; // Swap the front and the back buffers glutSwapBuffers() ; } void main(int argc, char **argv) { glutInit(&argc, argv) ; glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB) ; // glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) ; glutInitWindowSize(WinWidth, WinHeight) ; glutInitWindowPosition(100,150) ; glutCreateWindow("my first attempt") ; glutDisplayFunc(myDisplay) ; glutMouseFunc(myMouse) ; myInit() ; glutMainLoop() ; }