Exemple #1
0
u32 installtex(const char *texname, bool clamp) {
  auto s = IMG_Load(texname);
  if (!s) {
    con::out("couldn't load texture %s", texname);
    return 0;
  }
#if !defined(__WEBGL__)
  else if (s->format->BitsPerPixel!=24) {
    con::out("texture must be 24bpp: %s (got %i bpp)", texname, s->format->BitsPerPixel);
    return 0;
  }
#endif // __WEBGL__

  loopi(int(TEX_NUM)) bindedtexture[i] = 0;
  con::out("loading %s (%ix%i)", texname, s->w, s->h);
  if (s->w>glmaxtexsize || s->h>glmaxtexsize)
    sys::fatal("texture dimensions are too large");
  const auto ispowerof2 = ispoweroftwo(s->w) && ispoweroftwo(s->h);
  const auto minf = ispowerof2 ? 'M' : 'n';
  const auto mm = ispowerof2 ? 'G' : ' ';
  const auto fmt = s->format->BitsPerPixel == 24 ? '3' : '4';
  const auto wrap = clamp ? 'e' : 'r';
  auto id = maketex("TB I% D% B2 % Ws% Wt% Ml m%",fmt,fmt,s->pixels,s->w,s->h,mm,wrap,wrap,minf);
  SDL_FreeSurface(s);
  return id;
}
Exemple #2
0
Texture*
loadtexstruct(const char *path) {
    Texture *tex = NULL;
    SDL_Surface *orig = NULL;
    SDL_Surface *pow2 = NULL;
    SDL_Surface *conv = NULL;
    unsigned int handle = 0;

    orig = IMG_Load(path);
    if(!orig)
        goto out_orig;

    pow2 = pow2img(orig);
    if(!pow2)
        goto out_pow2;

    conv = formatimg(pow2);
    if(!conv)
        goto out_conv;

    handle = maketex(conv);
    SDL_FreeSurface(conv);
    if(!handle)
        goto out_conv;

    tex = malloc(sizeof(tex[0]));

    tex->handle = handle;

    Vec2 s = {
        orig->w / (double)pow2->w,
        orig->h / (double)pow2->h
    };
    tex->coords[0] = (Vec2) {
        0, s.y
    };
    tex->coords[1] = s;
    tex->coords[2] = (Vec2) {
        s.x, 0
    };
    tex->coords[3] = vec2zero;

    tex->name = malloc((strlen(path) + 1) * sizeof(path[0]));
    strcpy(tex->name, path);

out_conv:
    if(orig != pow2)
        SDL_FreeSurface(pow2);
out_pow2:
    SDL_FreeSurface(orig);
out_orig:
    return tex;
}
Exemple #3
0
unsigned int
loadtex(const char *path) {
    unsigned int handle = 0;
    SDL_Surface *orig = NULL;
    SDL_Surface *conv = NULL;

    orig = IMG_Load(path);
    if(!orig)
        goto out_orig;

    conv = formatimg(orig);
    if(!conv)
        goto out_conv;

    handle = maketex(conv);

    SDL_FreeSurface(conv);
out_conv:
    SDL_FreeSurface(orig);
out_orig:
    return handle;
}
Exemple #4
0
string
kpathsea_make_tex (kpathsea kpse, kpse_file_format_type format,
                   const_string base)
{
  kpse_format_info_type spec; /* some compilers lack struct initialization */
  string ret = NULL;

  spec = kpse->format_info[format];
  if (!spec.type) { /* Not initialized yet? */
    kpathsea_init_format (kpse, format);
    spec = kpse->format_info[format];
  }

  if (spec.program && spec.program_enabled_p) {
    /* See the documentation for the envvars we're dealing with here.  */
    /* Number of arguments is spec.argc + 1, plus the trailing NULL. */
    string *args = XTALLOC (spec.argc + 2, string);
    /* Helpers */
    int argnum;
    int i;

    /* FIXME
     * Check whether the name we were given is likely to be a problem.
     * Right now we err on the side of strictness:
     * - may not start with a hyphen (fixable in the scripts).
     * - allowed are: alphanumeric, underscore, hyphen, period, plus
     * ? also allowed DIRSEP, as we can be fed that when creating pk fonts
     * No doubt some possibilities were overlooked.
     */
    if (base[0] == '-' /* || IS_DIR_SEP(base[0])  */) {
      fprintf(stderr, "kpathsea:make_tex: Invalid filename `%s', starts with '%c'\n",
              base, base[0]);
      return NULL;
    }
    for (i = 0; base[i]; i++) {
      if (!ISALNUM(base[i])
          && base[i] != '-'
          && base[i] != '+'
          && base[i] != '_'
          && base[i] != '.'
          && !IS_DIR_SEP(base[i]))
      {
        fprintf(stderr, "kpathsea:make_tex: Invalid filename `%s', contains '%c'\n",
                base, base[i]);
        return NULL;
      }
    }

    if (format == kpse_gf_format
        || format == kpse_pk_format
        || format == kpse_any_glyph_format)
      set_maketex_mag (kpse);

    /* Here's an awful kludge: if the mode is `/', mktexpk recognizes
       it as a special case.  `kpse_prog_init' sets it to this in the
       first place when no mode is otherwise specified; this is so
       when the user defines a resolution, they don't also have to
       specify a mode; instead, mktexpk's guesses will take over.
       They use / for the value because then when it is expanded as
       part of the PKFONTS et al. path values, we'll wind up searching
       all the pk directories.  We put $MAKETEX_MODE in the path
       values in the first place so that sites with two different
       devices with the same resolution can find the right fonts; but
       such sites are uncommon, so they shouldn't make things harder
       for everyone else.  */
    for (argnum = 0; argnum < spec.argc; argnum++) {
        args[argnum] = kpathsea_var_expand (kpse, spec.argv[argnum]);
    }
    args[argnum++] = xstrdup(base);
    args[argnum] = NULL;

    ret = maketex (kpse, format, args);

    for (argnum = 0; args[argnum] != NULL; argnum++)
      free (args[argnum]);
    free (args);
  }

  return ret;
}