/* w2gl.c connect the points */ /* mouse to place points, button 3 to connect */ #include #include #include static GLfloat points[100][3]; static int n_points = 0; static int n = 0; static int width=400; static int height=300; void display(void) { char text[]="press button 1 for point, press button 3 to connect"; char text2[]="click here to exit"; char *p; int i, j; /* clear window */ glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity (); glColor3f(0.0, 0.0, 0.0); /* draw rectangle */ glBegin(GL_LINE_LOOP); glVertex2f(-0.95, 0.85); glVertex2f(-0.95, -0.85); glVertex2f( 0.95, -0.85); glVertex2f( 0.95, 0.85); glEnd(); /* draw text, in its own context */ glPushMatrix(); glLoadIdentity (); glColor3f(0.0, 0.0, 0.0); glEnable(GL_LINE_SMOOTH); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glTranslatef(-0.95, 0.89, 0.0); glScalef(0.00055, 0.00055, 0.0); for(p=text; *p; p++) glutStrokeCharacter(GLUT_STROKE_ROMAN, *p); glPopMatrix(); /* draw text2, in its own context */ glPushMatrix(); glLoadIdentity (); glColor3f(0.0, 0.0, 0.0); glEnable(GL_LINE_SMOOTH); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glTranslatef(-0.6, -0.97, 0.0); glScalef(0.00055, 0.00055, 0.0); for(p=text2; *p; p++) glutStrokeCharacter(GLUT_STROKE_ROMAN, *p); glPopMatrix(); /* Draw the points */ glColor3f(1.0, 0.0, 0.0); glPointSize(4.0); for(i=0; i= 99) return; /* reset if already connected */ if(n_points != 0) { n_points=0; n=0; } /* Save the point */ points[n][0] = wx; points[n][1] = wy; points[n][2] = 0.0; n++; } if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) { /* connect points */ n_points=n; } glutPostRedisplay(); } /* This routine handles window resizes */ void reshape(int w, int h) { width = w; height = h; /* Set the transformations */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glViewport(0, 0, w, h); } void init() { /* set clear color to white */ glClearColor (1.0, 1.0, 1.0, 0.0); /* set fill color to black */ glColor3f(0.0, 0.0, 0.0); glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); glMatrixMode (GL_MODELVIEW); glViewport(0, 0, width, height); } int main(int argc, char* argv[]) { glutInit(&argc,argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(width, height); glutInitWindowPosition(0,0); glutCreateWindow(argv[0]); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMouseFunc(mouse); init(); glutMainLoop(); return 0; }