Exemplo n.º 1
0
ENTRYPOINT void
init_slideshow (ModeInfo *mi)
{
  int screen = MI_SCREEN(mi);
  slideshow_state *ss;
  int wire = MI_IS_WIREFRAME(mi);
  
  if (sss == NULL) {
    if ((sss = (slideshow_state *)
         calloc (MI_NUM_SCREENS(mi), sizeof(slideshow_state))) == NULL)
      return;
  }
  ss = &sss[screen];

  if ((ss->glx_context = init_GL(mi)) != NULL) {
    reshape_slideshow (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
  } else {
    MI_CLEARWINDOW(mi);
  }

  if (debug_p)
    fprintf (stderr, "%s: pan: %d; fade: %d; img: %d; zoom: %d%%\n",
             blurb(), pan_seconds, fade_seconds, image_seconds, zoom);

  sanity_check(mi);

  if (debug_p)
    fprintf (stderr, "%s: pan: %d; fade: %d; img: %d; zoom: %d%%\n\n",
             blurb(), pan_seconds, fade_seconds, image_seconds, zoom);

  glDisable (GL_LIGHTING);
  glDisable (GL_DEPTH_TEST);
  glDepthMask (GL_FALSE);
  glEnable (GL_CULL_FACE);
  glCullFace (GL_BACK);

  if (! wire)
    {
      glEnable (GL_TEXTURE_2D);
      glShadeModel (GL_SMOOTH);
      glEnable (GL_BLEND);
      glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }

  if (debug_p) glLineWidth (3);

  ss->font_data = load_texture_font (mi->dpy, "titleFont");

  if (debug_p)
    hack_resources();

  ss->now = double_time();
  ss->dawn_of_time = ss->now;
  ss->prev_frame_time = ss->now;

  ss->awaiting_first_image_p = True;
  alloc_image (mi);
}
Exemplo n.º 2
0
ENTRYPOINT void
init_photopile (ModeInfo *mi)
{
  int screen = MI_SCREEN(mi);
  photopile_state *ss;
  int wire = MI_IS_WIREFRAME(mi);

  if (sss == NULL) {
    if ((sss = (photopile_state *)
         calloc (MI_NUM_SCREENS(mi), sizeof(photopile_state))) == NULL)
      return;
  }
  ss = &sss[screen];
  ss->mi = mi;

  if ((ss->glx_context = init_GL(mi)) != NULL) {
    reshape_photopile (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
    clear_gl_error(); /* WTF? sometimes "invalid op" from glViewport! */
  } else {
    MI_CLEARWINDOW(mi);
  }

  ss->shadow = init_drop_shadow();
  ss->texfont = load_texture_font (MI_DISPLAY(mi), "font");

  if (debug_p)
    hack_resources (MI_DISPLAY (mi));

  ss->frames = (image *)calloc (MI_COUNT(mi) + 1, sizeof(image));
  ss->nframe = 0;
  if (!wire)
    {
      int i;
      for (i = 0; i < MI_COUNT(mi) + 1; ++i)
        {
          glGenTextures (1, &(ss->frames[i].texid));
          if (ss->frames[i].texid <= 0) abort();
        }
    }

  ss->mode = EARLY;
  load_image(mi); /* start loading the first image */
}
Exemplo n.º 3
0
ENTRYPOINT void init_wip24(ModeInfo *mi) {
    if (!states) {
        atexit(&cleanup);
        states = calloc(1, MI_NUM_SCREENS(mi)*sizeof(wip24_state));
        curl_global_init(CURL_GLOBAL_DEFAULT);
        log_entry("New process\n");
        ensure_cache_dir();
    }
    
    log_entry("Begin initialization for screen %d\n", MI_SCREEN(mi));
    
    wip24_state* state = states + MI_SCREEN(mi);
    
    state->glx_context = init_GL(mi);
    state->program = 0;
    state->font = load_texture_font(MI_DISPLAY(mi), "fpsFont");
    
    glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(state->glx_context));
    if (strstr((const char*)glGetString(GL_EXTENSIONS), "GL_ARB_debug_output")) {
        glEnable(GL_DEBUG_OUTPUT);
        glDebugMessageCallbackARB((GLDEBUGPROCARB)gl_debug_callback, NULL);
    }
    glGenFramebuffers(1, &state->framebuffer);
    glGenTextures(1, &state->fb_texture);
    
    glBindFramebuffer(GL_FRAMEBUFFER, state->framebuffer);
    glBindTexture(GL_TEXTURE_2D, state->fb_texture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                           GL_TEXTURE_2D, state->fb_texture, 0);
    glEnable(GL_TEXTURE_2D);
    
    init_shader(mi, state);
    
    log_entry("End initialization for screen %d\n", MI_SCREEN(mi));
}
Exemplo n.º 4
0
ENTRYPOINT void 
init_spheremonics (ModeInfo *mi)
{
  spheremonics_configuration *cc;

  MI_INIT (mi, ccs);

  cc = &ccs[MI_SCREEN(mi)];

  if ((cc->glx_context = init_GL(mi)) != NULL) {
    gl_init(mi);
    reshape_spheremonics (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
  }

  {
    Bool spinx=False, spiny=False, spinz=False;
    double spin_speed   = 1.0;
    double wander_speed = 0.03;

    char *s = do_spin;
    while (*s)
      {
        if      (*s == 'x' || *s == 'X') spinx = True;
        else if (*s == 'y' || *s == 'Y') spiny = True;
        else if (*s == 'z' || *s == 'Z') 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++;
      }

    cc->rot = make_rotator (spinx ? spin_speed : 0,
                            spinz ? spin_speed : 0,
                            spiny ? spin_speed : 0,
                            1.0,
                            do_wander ? wander_speed : 0,
                            (spinx && spiny && spinz));
    cc->trackball = gltrackball_init (True);
  }

  cc->tracer = -1;
  cc->mesher = -1;

  cc->resolution = res;

  cc->font_data = load_texture_font (mi->dpy, "labelfont");

  cc->dlist = glGenLists(1);
  cc->dlist2 = glGenLists(1);

  cc->m_max = 4; /* 9? */
  {
    unsigned int i;
    for (i = 0; i < countof(cc->dm); i++)
      cc->dm[i] = 1;  /* going up! */

    /* Generate a few more times so we don't always start off with a sphere */
    for (i = 0; i < 5; i++)
      tweak_parameters (mi);
  }

  generate_spheremonics(mi);
}
Exemplo n.º 5
0
ENTRYPOINT void
init_carousel (ModeInfo *mi)
{
  int screen = MI_SCREEN(mi);
  carousel_state *ss;
  int wire = MI_IS_WIREFRAME(mi);
  
  if (sss == NULL) {
    if ((sss = (carousel_state *)
         calloc (MI_NUM_SCREENS(mi), sizeof(carousel_state))) == NULL)
      return;
  }
  ss = &sss[screen];

  if ((ss->glx_context = init_GL(mi)) != NULL) {
    reshape_carousel (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
  } else {
    MI_CLEARWINDOW(mi);
  }

  if (!tilt_str || !*tilt_str)
    ;
  else if (!strcasecmp (tilt_str, "0"))
    ;
  else if (!strcasecmp (tilt_str, "X"))
    tilt_x_p = 1;
  else if (!strcasecmp (tilt_str, "Y"))
    tilt_y_p = 1;
  else if (!strcasecmp (tilt_str, "XY"))
    tilt_x_p = tilt_y_p = 1;
  else
    {
      fprintf (stderr, "%s: tilt must be 'X', 'Y', 'XY' or '', not '%s'\n",
               progname, tilt_str);
      exit (1);
    }

  {
    double spin_speed   = speed * 0.2;    /* rotation of tube around axis */
    double spin_accel   = speed * 0.1;
    double wander_speed = speed * 0.001;  /* tilting of axis */

    spin_speed   *= 0.9 + frand(0.2);
    wander_speed *= 0.9 + frand(0.2);

    ss->rot = make_rotator (spin_speed, spin_speed, spin_speed,
                            spin_accel, wander_speed, True);

    ss->trackball = gltrackball_init ();
  }

  if (strstr ((char *) glGetString(GL_EXTENSIONS),
              "GL_EXT_texture_filter_anisotropic"))
    glGetFloatv (GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &ss->anisotropic);
  else
    ss->anisotropic = 0.0;

  glDisable (GL_LIGHTING);
  glEnable (GL_DEPTH_TEST);
  glDisable (GL_CULL_FACE);

  if (! wire)
    {
      glShadeModel (GL_SMOOTH);
      glEnable (GL_LINE_SMOOTH);
      /* This gives us a transparent diagonal slice through each image! */
      /* glEnable (GL_POLYGON_SMOOTH); */
      glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
      glEnable (GL_BLEND);
      glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      glEnable (GL_ALPHA_TEST);

      glEnable (GL_POLYGON_OFFSET_FILL);
      glPolygonOffset (1.0, 1.0);

    }

  ss->texfont = load_texture_font (MI_DISPLAY(mi), "font");

  if (debug_p)
    hack_resources (MI_DISPLAY (mi));

  ss->nframes = 0;
  ss->frames_size = 10;
  ss->frames = (image_frame **)
    calloc (1, ss->frames_size * sizeof(*ss->frames));

  ss->mode = IN;
  ss->mode_tick = fade_ticks / speed;

  ss->awaiting_first_images_p = True;
}
Exemplo n.º 6
0
ENTRYPOINT void 
init_sws (ModeInfo *mi)
{
  double font_height;

  sws_configuration *sc = 0;

  if (!scs) {
    scs = (sws_configuration *)
      calloc (MI_NUM_SCREENS(mi), sizeof (sws_configuration));
    if (!scs) {
      fprintf(stderr, "%s: out of memory\n", progname);
      exit(1);
    }
  }

  sc = &scs[MI_SCREEN(mi)];

  sc->dpy = MI_DISPLAY(mi);
  sc = &scs[MI_SCREEN(mi)];
  sc->lines = (char **) calloc (max_lines+1, sizeof(char *));

  if ((sc->glx_context = init_GL(mi)) != NULL) {
    gl_init(mi);
    reshape_sws (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
    clear_gl_error(); /* WTF? sometimes "invalid op" from glViewport! */

    init_stars (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
  }

  if (textures_p)
    {
      int cw, lh;
      sc->texfont = load_texture_font (MI_DISPLAY(mi), "font");
      cw = texture_string_width (sc->texfont, "n", &lh);
      sc->char_width = cw;
      font_height = lh;
      glEnable(GL_ALPHA_TEST);
      glEnable (GL_TEXTURE_2D);

      check_gl_error ("loading font");

      /* "Anistropic filtering helps for quadrilateral-angled textures.
         A sharper image is accomplished by interpolating and filtering
         multiple samples from one or more mipmaps to better approximate
         very distorted textures.  This is the next level of filtering
         after trilinear filtering." */
      if (smooth_p && 
          strstr ((char *) glGetString(GL_EXTENSIONS),
                  "GL_EXT_texture_filter_anisotropic"))
      {
        GLfloat anisotropic = 0.0;
        glGetFloatv (GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropic);
        if (anisotropic >= 1.0)
          glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 
                           anisotropic);
      }
    }
  else
    {
      font_height = GLUT_FONT->top - GLUT_FONT->bottom;
      sc->char_width = glutStrokeWidth (GLUT_FONT, 'z'); /* 'n' seems wide */
    }
  
  sc->font_scale = 1.0 / sc->char_width;


  /* We consider a font that consumes 80 columns to be "18 points".

     If neither -size nor -columns was specified, default to 60 columns
     (which is 24 points.)

     If both were specified, -columns has priority.
   */
  {
    int base_col  = 80;
    int base_size = 18;

    if (target_columns <= 0 && font_size <= 0)
      target_columns = 60;

    if (target_columns > 0)
      font_size = base_size * (base_col / (double) target_columns);
    else if (font_size > 0)
      target_columns = base_col * (base_size / (double) font_size);
  }

  sc->line_pixel_width = target_columns * sc->char_width;

  sc->font_scale /= target_columns;
  sc->line_height = font_height * sc->font_scale;


  /* Buffer only two lines of text.
     If the buffer is too big, there's a significant delay between
     when the program launches and when the text appears, which can be
     irritating for time-sensitive output (clock, current music, etc.)
   */
  sc->buf_size = target_columns * 2;
  if (sc->buf_size < 80) sc->buf_size = 80;
  sc->buf = (char *) calloc (1, sc->buf_size);

  sc->total_lines = max_lines-1;

  if (random() & 1)
    star_spin = -star_spin;

  if (!alignment_str || !*alignment_str ||
      !strcasecmp(alignment_str, "left"))
    alignment = -1;
  else if (!strcasecmp(alignment_str, "center") ||
           !strcasecmp(alignment_str, "middle"))
    alignment = 0;
  else if (!strcasecmp(alignment_str, "right"))
    alignment = 1;
  else
    {
      fprintf (stderr,
               "%s: alignment must be left, center, or right, not \"%s\"\n",
               progname, alignment_str);
      exit (1);
    }

  sc->tc = textclient_open (sc->dpy);

  /* one more reshape, after line_height has been computed */
  reshape_sws (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
}
Exemplo n.º 7
0
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));
}
Exemplo n.º 8
0
ENTRYPOINT void 
init_unicrud (ModeInfo *mi)
{
  unicrud_configuration *bp;

  MI_INIT (mi, bps);

  bp = &bps[MI_SCREEN(mi)];

  bp->glx_context = init_GL(mi);

  reshape_unicrud (mi, MI_WIDTH(mi), MI_HEIGHT(mi));

  {
    double spin_speed   = 0.05;
    double wander_speed = 0.01;
    double spin_accel   = 1.0;

    bp->rot = make_rotator (do_spin ? spin_speed : 0,
                            do_spin ? spin_speed : 0,
                            do_spin ? spin_speed : 0,
                            spin_accel,
                            do_wander ? wander_speed : 0,
                            False);
    bp->trackball = gltrackball_init (True);
  }

  bp->title_font = load_texture_font (mi->dpy, "titleFont");
  bp->char_font  = load_texture_font (mi->dpy, "font");
  bp->state = IN;
  bp->ratio = 0;
  bp->spin_direction = (random() & 1) ? 1 : -1;



  if (matches ("all", do_block))
    do_block = strdup("");

  {
    char *s;
    for (s = do_block; *s; s++)
      if (*s == '_') *s = ' ';
  }

  if (matches ("help", do_block))
    {
      int i;
      fprintf (stderr,
               "%s: --blocks must contain one or more of these,"
               " separated by commas:\n\n", progname);
      for (i = 0; i < countof(unicode_block_names); i++)
        {
          const char *n = unicode_block_names[i].name;
          if (*n == '*')
            continue;
          if (!strncmp (n, "Unassigned", 10) ||
              !strncmp (n, "Combining", 9))
            continue;
          fprintf (stderr, "\t%s\n", n);
        }
      fprintf (stderr, "\n");
      exit (1);
    }


  /* Make sure all elements in --block are valid.
   */
  if (*do_block)
    {
      char *token = strdup (do_block ? do_block : "");
      char *otoken = token;
      char *name;
      while ((name = strtok (token, ","))) {
        token = 0;
        name = strip (name);
        if (*name)
          {
            Bool match = False;
            int i;
            for (i = 0; i < countof(unicode_block_names); i++)
              {
                const char *n = unicode_block_names[i].name;
                if (*n == '*')
                  continue;
                if (!strncmp (n, "Unassigned", 10) ||
                    !strncmp (n, "Combining", 9))
                  continue;
                if (!strcasecmp (name, n))
                  {
                    match = True;
                    break;
                  }
              }
            if (! match)
              {
                fprintf (stderr, "%s: unknown block name: \"%s\"\n", 
                         progname, name);
                fprintf (stderr, "%s: use '--block help' for a list\n", 
                         progname);
                exit (1);
              }
          }
      }
      free (otoken);
    }

  pick_unichar (mi);
}
Exemplo n.º 9
0
ENTRYPOINT void
init_planet (ModeInfo * mi)
{
  planetstruct *gp;
  int screen = MI_SCREEN(mi);
  Bool wire = MI_IS_WIREFRAME(mi);

  if (planets == NULL) {
    if ((planets = (planetstruct *) calloc(MI_NUM_SCREENS(mi),
					  sizeof (planetstruct))) == NULL)
      return;
  }
  gp = &planets[screen];

  if ((gp->glx_context = init_GL(mi)) != NULL) {
    reshape_planet(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
  }

  gp->state = STARTUP;
  gp->ratio = 0;
  gp->font_data = load_texture_font (mi->dpy, "labelFont");

  {
    double spin_speed	= 0.1;
    double wander_speed = 0.002;
    gp->rot = make_rotator (do_roll ? spin_speed : 0,
			    do_roll ? spin_speed : 0,
			    0, 1,
			    do_wander ? wander_speed : 0,
			    False);
    gp->trackball = gltrackball_init (True);
  }

  if (wire)
    do_texture = False;

  if (do_texture)
    setup_texture (mi);

  if (do_stars)
    init_stars (mi);

  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.4, 0.4, 0.4, 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);
      glLightfv(GL_LIGHT0, GL_POSITION, pos);
      glLightfv(GL_LIGHT0, GL_AMBIENT,	amb);
      glLightfv(GL_LIGHT0, GL_DIFFUSE,	dif);
      glLightfv(GL_LIGHT0, GL_SPECULAR, spc);
    }
}
Exemplo n.º 10
0
ENTRYPOINT void 
init_fliptext (ModeInfo *mi)
{
  int wire = MI_IS_WIREFRAME(mi);

  fliptext_configuration *sc;

  MI_INIT(mi, scs);

  sc = &scs[MI_SCREEN(mi)];
  sc->lines = (line **) calloc (max_lines+1, sizeof(char *));

  sc->dpy = MI_DISPLAY(mi);

  if ((sc->glx_context = init_GL(mi)) != NULL) {
    reshape_fliptext (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
    clear_gl_error(); /* WTF? sometimes "invalid op" from glViewport! */
  }

  {
    XCharStruct e;
    int cw, lh, ascent, descent;
    sc->texfont = load_texture_font (MI_DISPLAY(mi), "font");
    check_gl_error ("loading font");
    texture_string_metrics (sc->texfont, "n", &e, &ascent, &descent);
    cw = e.width;
    lh = ascent + descent;
    sc->char_width = cw;
    sc->line_height = lh;
  }

  if (!wire)
    {
      glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
      glEnable (GL_BLEND);
      glEnable (GL_ALPHA_TEST);
      glEnable (GL_TEXTURE_2D);

      /* "Anistropic filtering helps for quadrilateral-angled textures.
         A sharper image is accomplished by interpolating and filtering
         multiple samples from one or more mipmaps to better approximate
         very distorted textures.  This is the next level of filtering
         after trilinear filtering." */
      if (strstr ((char *) glGetString(GL_EXTENSIONS),
                  "GL_EXT_texture_filter_anisotropic"))
      {
        GLfloat anisotropic = 0.0;
        glGetFloatv (GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropic);
        if (anisotropic >= 1.0)
          glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 
                           anisotropic);
      }
    }
  
  /* The default font is (by fiat) "18 points".
     Interpret the user's font size request relative to that.
   */
  sc->font_scale = 3 * (font_size / 18.0);

  if (target_columns <= 2) target_columns = 2;

  /* Figure out what the wrap column should be, in font-coordinate pixels.
     Compute it from the given -columns value, but don't let it be wider
     than the screen.
   */
  {
    GLfloat maxw = 110 * sc->line_height / sc->font_scale;  /* magic... */
    sc->font_wrap_pixels = target_columns * sc->char_width;
    if (sc->font_wrap_pixels > maxw ||
        sc->font_wrap_pixels <= 0)
      sc->font_wrap_pixels = maxw;
  }

  sc->buf_size = target_columns * max_lines;
  sc->buf = (char *) calloc (1, sc->buf_size);

  alignment_random_p = False;
  if (!alignment_str || !*alignment_str ||
      !strcasecmp(alignment_str, "left"))
    sc->alignment = -1;
  else if (!strcasecmp(alignment_str, "center") ||
           !strcasecmp(alignment_str, "middle"))
    sc->alignment = 0;
  else if (!strcasecmp(alignment_str, "right"))
    sc->alignment = 1;
  else if (!strcasecmp(alignment_str, "random"))
    sc->alignment = -1, alignment_random_p = True;

  else
    {
      fprintf (stderr,
               "%s: alignment must be left/center/right/random, not \"%s\"\n",
               progname, alignment_str);
      exit (1);
    }

  sc->tc = textclient_open (sc->dpy);

  if (max_lines < 1) max_lines = 1;
  min_lines = max_lines * 0.66;
  if (min_lines > max_lines - 3) min_lines = max_lines - 4;
  if (min_lines < 1) min_lines = 1;

  parse_color (mi, "foreground",
               get_string_resource(mi->dpy, "foreground", "Foreground"),
               sc->color);

  sc->top_margin = (sc->char_width * 100);
  sc->bottom_margin = -sc->top_margin;
  reshape_fliptext (mi, MI_WIDTH(mi), MI_HEIGHT(mi));  /* compute left/right */
}
Exemplo n.º 11
0
ENTRYPOINT void 
init_sonar (ModeInfo *mi)
{
  sonar_configuration *sp;
  int wire = MI_IS_WIREFRAME(mi);

  if (!sps) {
    sps = (sonar_configuration *)
      calloc (MI_NUM_SCREENS(mi), sizeof (sonar_configuration));
    if (!sps) {
      fprintf(stderr, "%s: out of memory\n", progname);
      exit(1);
    }
  }
  sp = &sps[MI_SCREEN(mi)];
  sp->glx_context = init_GL(mi);

  reshape_sonar (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
  clear_gl_error(); /* WTF? sometimes "invalid op" from glViewport! */

  if (!wire)
    {
      GLfloat pos[4] = {0.05, 0.07, 1.00, 0.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] = {0.0, 1.0, 1.0, 1.0};

      glEnable(GL_TEXTURE_2D);
      glEnable(GL_LIGHTING);
      glEnable(GL_LIGHT0);
      glEnable(GL_CULL_FACE);
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_NORMALIZE);
      glEnable(GL_LINE_SMOOTH);
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
      glShadeModel(GL_SMOOTH);

      glLightfv(GL_LIGHT0, GL_POSITION, pos);
      glLightfv(GL_LIGHT0, GL_AMBIENT,  amb);
      glLightfv(GL_LIGHT0, GL_DIFFUSE,  dif);
      glLightfv(GL_LIGHT0, GL_SPECULAR, spc);
    }

  sp->trackball = gltrackball_init ();
  sp->rot = make_rotator (0, 0, 0, 0, speed * 0.003, True);

  sp->texfont = load_texture_font (MI_DISPLAY(mi), "font");
  check_gl_error ("loading font");

  sp->table_list = glGenLists (1);
  glNewList (sp->table_list, GL_COMPILE);
  sp->table_polys = draw_table (mi);
  glEndList ();

  sp->screen_list = glGenLists (1);
  glNewList (sp->screen_list, GL_COMPILE);
  sp->screen_polys = draw_screen (mi, False, False);
  glEndList ();

  sp->grid_list = glGenLists (1);
  glNewList (sp->grid_list, GL_COMPILE);
  sp->grid_polys = draw_screen (mi, True,  False);
  glEndList ();

  sp->sweep_list = glGenLists (1);
  glNewList (sp->sweep_list, GL_COMPILE);
  sp->sweep_polys = draw_screen (mi, False, True);
  glEndList ();

  sp->start_time = double_time ();
  sp->sweep_offset = random() % 60;
  sp->sweep_th = -1;
}