/* dirchilet.c Dirichlet Domain or Voronoi Polygon */ #include #include static GLfloat points[8][3]; static GLfloat colors[8][3] = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.7, 0.7, 0.7, 0.5, 0.5, 0.7}; static int n_points = 0; static int n = 0; static int width=200; static int height=200; void display(void) { char text1[]="press button 1 for point"; char text2[]="press button 3 for domian"; char text3[]="click here to exit"; char *p; int i, j, k; GLfloat xf, yf, d, dmin; GLfloat dx = 1.8/180.0; /* clear window */ glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity (); glColor3f(0.0, 0.0, 0.0); /* draw rectangle */ glBegin(GL_LINE_LOOP); glVertex2f(-0.90, 0.70); glVertex2f(-0.90, -0.80); glVertex2f( 0.90, -0.80); glVertex2f( 0.90, 0.70); glEnd(); /* draw text1, 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.8, 0.89, 0.0); glScalef(0.0008, 0.0008, 0.0); for(p=text1; *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.8, 0.75, 0.0); glScalef(0.0008, 0.0008, 0.0); for(p=text2; *p; p++) glutStrokeCharacter(GLUT_STROKE_ROMAN, *p); glPopMatrix(); /* draw text3, 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.9, 0.0); glScalef(0.0008, 0.0008, 0.0); for(p=text3; *p; p++) glutStrokeCharacter(GLUT_STROKE_ROMAN, *p); glPopMatrix(); /* Draw the points */ glPointSize(4.0); for(i=0; i= 8) { /* draw domains */ n_points=n; glutPostRedisplay(); n=0; 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) { /* draw domains */ 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); glutMouseFunc(mouse); init(); glutMainLoop(); return 0; }