ENTRYPOINT void init_splitflap (ModeInfo *mi) { splitflap_configuration *bp; int wire = MI_IS_WIREFRAME(mi); int i; MI_INIT (mi, bps); bp = &bps[MI_SCREEN(mi)]; bp->glx_context = init_GL(mi); reshape_splitflap (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); bp->first_time_p = True; if (!mode_str || !*mode_str || !strcasecmp(mode_str, "text")) { bp->clock_p = 0; } else if (!strcasecmp (mode_str, "clock") || !strcasecmp (mode_str, "clock12")) { bp->clock_p = 12; grid_width = 8; grid_height = 1; } else if (!strcasecmp (mode_str, "clock24")) { bp->clock_p = 24; grid_width = 6; grid_height = 1; } else { fprintf (stderr, "%s: `mode' must be text, clock12 or clock24: not `%s'\n", progname, mode_str); exit (1); } if (! bp->clock_p) { bp->tc = textclient_open (MI_DISPLAY (mi)); bp->text[0] = 0; if (grid_width > 10) textclient_reshape (bp->tc, grid_width, grid_height, grid_width, grid_height, 0); } if (bp->clock_p) speed /= 4; glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); if (!wire) { GLfloat pos[4] = {0.4, 0.2, 0.4, 0.0}; /* GLfloat amb[4] = {0.0, 0.0, 0.0, 1.0};*/ GLfloat amb[4] = {0.2, 0.2, 0.2, 1.0}; GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0}; GLfloat spc[4] = {1.0, 1.0, 1.0, 1.0}; glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glLightfv(GL_LIGHT0, GL_POSITION, pos); glLightfv(GL_LIGHT0, GL_AMBIENT, amb); glLightfv(GL_LIGHT0, GL_DIFFUSE, dif); glLightfv(GL_LIGHT0, GL_SPECULAR, spc); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } { double spin_speed = 0.5; double wander_speed = 0.005; double tilt_speed = 0.001; double spin_accel = 0.5; char *s = do_spin; while (*s) { if (*s == 'x' || *s == 'X') bp->spinx = True; else if (*s == 'y' || *s == 'Y') bp->spiny = True; else if (*s == 'z' || *s == 'Z') bp->spinz = True; else if (*s == '0') ; else { fprintf (stderr, "%s: spin must contain only the characters X, Y, or Z (not \"%s\")\n", progname, do_spin); exit (1); } s++; } bp->rot = make_rotator (bp->spinx ? spin_speed : 0, bp->spiny ? spin_speed : 0, bp->spinz ? spin_speed : 0, spin_accel, do_wander ? wander_speed : 0, False); bp->rot2 = (face_front_p ? make_rotator (0, 0, 0, 0, tilt_speed, True) : 0); bp->trackball = gltrackball_init (False); } bp->dlists = (GLuint *) calloc (countof(all_objs)+1, sizeof(GLuint)); for (i = 0; i < countof(all_objs); i++) bp->dlists[i] = glGenLists (1); parse_color (mi, "textColor", bp->text_color); for (i = 0; i < countof(all_objs); i++) { const struct gllist *gll = *all_objs[i]; char *key = 0; GLfloat spec[4] = {0.4, 0.4, 0.4, 1.0}; GLfloat shiny = 80; /* 0-128 */ glNewList (bp->dlists[i], GL_COMPILE); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glMatrixMode(GL_TEXTURE); glPushMatrix(); glMatrixMode(GL_MODELVIEW); glRotatef (-90, 1, 0, 0); glBindTexture (GL_TEXTURE_2D, 0); switch (i) { case SPLITFLAP_QUARTER_FRAME: key = "frameColor"; break; case SPLITFLAP_OUTER_FRAME: key = "caseColor"; break; case SPLITFLAP_DISC_QUARTER: key = (wire ? "frameColor" : "discColor"); break; case SPLITFLAP_FIN_EDGE_HALF: case SPLITFLAP_FIN_FACE_HALF: key = "finColor"; break; default: abort(); } parse_color (mi, key, bp->component_colors[i]); if (wire && i == SPLITFLAP_FIN_EDGE_HALF) bp->component_colors[i][0] = bp->component_colors[i][1] = bp->component_colors[i][2] = 0.7; glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); switch (i) { case SPLITFLAP_OUTER_FRAME: if (! splitflap_obj_outer_frame) splitflap_obj_outer_frame = (struct gllist *) calloc (1, sizeof(*splitflap_obj_outer_frame)); splitflap_obj_outer_frame->points = draw_outer_frame(mi); break; default: renderList (gll, wire); break; } glMatrixMode(GL_TEXTURE); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glEndList (); } if (grid_width < 1) grid_width = 1; if (grid_height < 1) grid_height = 1; bp->flappers = (flapper *) calloc (grid_width * grid_height, sizeof (flapper)); for (i = 0; i < grid_width * grid_height; i++) { flapper *f = &bp->flappers[i]; if (!bp->clock_p) { f->spool = ascii_spool; f->spool_size = countof (ascii_spool); } else { switch (i) { case 0: if (bp->clock_p == 12) { f->spool = digit_s1_spool; f->spool_size = countof (digit_s1_spool); } else { f->spool = digit_01_spool; f->spool_size = countof (digit_01_spool); } break; case 1: case 3: case 5: f->spool = digit_spool; f->spool_size = countof (digit_spool); break; case 2: case 4: f->spool = digit_05_spool; f->spool_size = countof (digit_05_spool); break; case 6: f->spool = ap_spool; f->spool_size = countof (ap_spool); break; case 7: f->spool = m_spool; f->spool_size = countof (m_spool); break; default: abort(); } } f->target_index = random() % f->spool_size; /* f->target_index = 0; */ f->current_index = f->target_index; f->missing = (((random() % 10) == 0) ? (random() % f->spool_size) : -1); } bp->font_data = load_texture_font (mi->dpy, "flapFont"); init_textures (mi); reshape_splitflap (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); }
static void * noseguy_init (Display *d, Window w) { struct state *st = (struct state *) calloc (1, sizeof(*st)); unsigned long fg, bg, text_fg, text_bg; XWindowAttributes xgwa; Colormap cmap; char *fontname; XGCValues gcvalues; st->dpy = d; st->window = w; st->first_time = 1; fontname = get_string_resource (st->dpy, "font", "Font"); XGetWindowAttributes (st->dpy, st->window, &xgwa); st->Width = xgwa.width + 2; st->Height = xgwa.height + 2; cmap = xgwa.colormap; st->tc = textclient_open (st->dpy); { int w = 40; int h = 15; textclient_reshape (st->tc, w, h, w, h, /* Passing MAXLINES isn't actually necessary */ 0); } init_images(st); st->xftfont = XftFontOpenXlfd (st->dpy, screen_number (xgwa.screen), fontname); XftColorAllocName (st->dpy, xgwa.visual, xgwa.colormap, get_string_resource (st->dpy, "textForeground", "Foreground"), &st->xftcolor); st->xftdraw = XftDrawCreate (st->dpy, st->window, xgwa.visual, xgwa.colormap); fg = get_pixel_resource (st->dpy, cmap, "foreground", "Foreground"); bg = get_pixel_resource (st->dpy, cmap, "background", "Background"); text_fg = get_pixel_resource (st->dpy, cmap, "textForeground", "Foreground"); text_bg = get_pixel_resource (st->dpy, cmap, "textBackground", "Background"); /* notice when unspecified */ if (! get_string_resource (st->dpy, "textForeground", "Foreground")) text_fg = bg; if (! get_string_resource (st->dpy, "textBackground", "Background")) text_bg = fg; gcvalues.foreground = fg; gcvalues.background = bg; st->fg_gc = XCreateGC (st->dpy, st->window, GCForeground|GCBackground, &gcvalues); gcvalues.foreground = bg; gcvalues.background = fg; st->bg_gc = XCreateGC (st->dpy, st->window, GCForeground|GCBackground, &gcvalues); gcvalues.foreground = text_fg; gcvalues.background = text_bg; st->text_fg_gc = XCreateGC (st->dpy, st->window, GCForeground|GCBackground, &gcvalues); gcvalues.foreground = text_bg; gcvalues.background = text_fg; st->text_bg_gc = XCreateGC (st->dpy, st->window, GCForeground|GCBackground, &gcvalues); st->x = st->Width / 2; st->y = st->Height / 2; st->state = IS_MOVING; st->next_fn = move; st->walk_up = 1; return st; }