static void startup_blurb (ModeInfo *mi) { molecule_configuration *mc = &mcs[MI_SCREEN(mi)]; const char *s = "Constructing molecules..."; print_gl_string (mi->dpy, mc->xfont3, mc->font3_dlist, mi->xgwa.width, mi->xgwa.height, 10, mi->xgwa.height - 10, s, False); glFinish(); glXSwapBuffers(MI_DISPLAY(mi), MI_WINDOW(mi)); }
static void new_label (ModeInfo *mi) { pinion_configuration *pp = &pps[MI_SCREEN(mi)]; char label[1024]; int i; gear *g = 0; if (pp->mouse_gear_id) for (i = 0; i < pp->ngears; i++) if (pp->gears[i]->id == pp->mouse_gear_id) { g = pp->gears[i]; break; } if (!g) *label = 0; else { sprintf (label, "%d teeth\n", (int) g->nteeth); rpm_string (g->rpm, label + strlen(label)); if (debug_p) sprintf (label + strlen (label), "\nPolys: %d\nModel: %s (%.2f)\n", g->polygons, (g->size == INVOLUTE_SMALL ? "small" : g->size == INVOLUTE_MEDIUM ? "medium" : "large"), g->tooth_h * MI_HEIGHT(mi)); } glNewList (pp->title_list, GL_COMPILE); if (*label) { XFontStruct *f; GLuint fl; if (MI_WIDTH(mi) >= 500 && MI_HEIGHT(mi) >= 375) f = pp->xfont1, fl = pp->font1_dlist; /* big font */ else if (MI_WIDTH(mi) >= 350 && MI_HEIGHT(mi) >= 260) f = pp->xfont2, fl = pp->font2_dlist; /* small font */ else f = pp->xfont3, fl = pp->font3_dlist; /* tiny font */ glColor3f (0.8, 0.8, 0); print_gl_string (mi->dpy, f, fl, mi->xgwa.width, mi->xgwa.height, 10, mi->xgwa.height - 10, label, False); } glEndList (); }
ENTRYPOINT void draw_molecule (ModeInfo *mi) { time_t now = time ((time_t *) 0); GLfloat speed = 4.0; /* speed at which the zoom out/in happens */ molecule_configuration *mc = &mcs[MI_SCREEN(mi)]; Display *dpy = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); if (!mc->glx_context) return; glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(mc->glx_context)); if (mc->draw_time == 0) { pick_new_molecule (mi, mc->draw_time); mc->draw_time = now; } else if (mc->mode == 0) { if (mc->draw_tick++ > 10) { time_t now = time((time_t *) 0); if (mc->draw_time == 0) mc->draw_time = now; mc->draw_tick = 0; if (!mc->button_down_p && mc->nmolecules > 1 && mc->draw_time + timeout <= now) { /* randomize molecules every -timeout seconds */ mc->mode = 1; /* go out */ mc->mode_tick = 10 * speed; mc->draw_time = now; } } } else if (mc->mode == 1) /* out */ { if (--mc->mode_tick <= 0) { mc->mode_tick = 10 * speed; mc->mode = 2; /* go in */ pick_new_molecule (mi, mc->draw_time); mc->draw_time = now; } } else if (mc->mode == 2) /* in */ { if (--mc->mode_tick <= 0) mc->mode = 0; /* normal */ } else abort(); glPushMatrix (); glScalef(1.1, 1.1, 1.1); { double x, y, z; get_position (mc->rot, &x, &y, &z, !mc->button_down_p); glTranslatef((x - 0.5) * 9, (y - 0.5) * 9, (z - 0.5) * 9); gltrackball_rotate (mc->trackball); get_rotation (mc->rot, &x, &y, &z, !mc->button_down_p); glRotatef (x * 360, 1.0, 0.0, 0.0); glRotatef (y * 360, 0.0, 1.0, 0.0); glRotatef (z * 360, 0.0, 0.0, 1.0); } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (mc->mode != 0) { GLfloat s = (mc->mode == 1 ? mc->mode_tick / (10 * speed) : ((10 * speed) - mc->mode_tick + 1) / (10 * speed)); glScalef (s, s, s); } glPushMatrix(); glCallList (mc->molecule_dlist); if (mc->mode == 0) { molecule *m = &mc->molecules[mc->which]; draw_labels (mi); /* This can't go in the display list, or the characters are spaced wrongly when the window is resized. */ if (do_titles && m->label && *m->label) { set_atom_color (mi, 0, True, 1); print_gl_string (mi->dpy, mc->xfont3, mc->font3_dlist, mi->xgwa.width, mi->xgwa.height, 10, mi->xgwa.height - 10, m->label, False); } } glPopMatrix(); if (do_shells) { glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glPushMatrix(); glCallList (mc->shell_dlist); glPopMatrix(); glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glDepthFunc (GL_EQUAL); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPushMatrix(); glCallList (mc->shell_dlist); glPopMatrix(); glDepthFunc (GL_LESS); glDisable (GL_BLEND); } glPopMatrix (); mi->polygon_count = mc->polygon_count; if (mi->fps_p) do_fps (mi); glFinish(); glXSwapBuffers(dpy, window); }