Ignore:
Timestamp:
Aug 29, 2010, 12:51:13 AM (10 years ago)
Author:
sam
Message:

Support tilesets larger than 512x512 and switch the coordinates system to
(0,0) at the bottom left.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tileset.cpp

    r170 r186  
    3838    char *name;
    3939    int *tiles;
    40     int ntiles;
     40    int nw, nh, ntiles;
     41    float tx, ty;
    4142
    4243    SDL_Surface *img;
     
    5354    data->name = strdup(path);
    5455    data->tiles = NULL;
    55     data->ntiles = 0;
    5656    data->img = NULL;
    5757    data->texture = 0;
     
    6666        exit(1);
    6767    }
     68
     69    data->nw = data->img->w / 32;
     70    data->nh = data->img->h / 32;
     71    data->ntiles = data->nw * data->nh;
     72    data->tx = 32.0f / data->img->w;
     73    data->ty = 32.0f / data->img->h;
    6874}
    6975
     
    114120void TileSet::BlitTile(uint32_t id, int x, int y, int z, int o)
    115121{
    116     float tx = .0625f * (id & 0xf);
    117     float ty = .0625f * ((id >> 4) & 0xf);
     122    float tx = data->tx * ((id & 0xffff) % data->nw);
     123    float ty = data->ty * ((id & 0xffff) / data->nw);
    118124
    119125    float sqrt2 = sqrtf(2.0f);
     
    124130        glBindTexture(GL_TEXTURE_2D, data->texture);
    125131        glBegin(GL_QUADS);
     132            glTexCoord2f(tx, ty + data->ty);
     133            glVertex3f(x, sqrt2 * (y - 70 + off), sqrt2 * (z + off));
     134            glTexCoord2f(tx + data->tx, ty + data->ty);
     135            glVertex3f(x + 32, sqrt2 * (y - 70 + off), sqrt2 * (z + off));
     136            glTexCoord2f(tx + data->tx, ty);
     137            glVertex3f(x + 32, sqrt2 * (y - 38), sqrt2 * z);
    126138            glTexCoord2f(tx, ty);
    127             glVertex3f(x, sqrt2 * (y + off), sqrt2 * (z + off));
    128             glTexCoord2f(tx + .0625f, ty);
    129             glVertex3f(x + 32, sqrt2 * (y + off), sqrt2 * (z + off));
    130             glTexCoord2f(tx + .0625f, ty + .0625f);
    131             glVertex3f(x + 32, sqrt2 * (y + 32), sqrt2 * z);
    132             glTexCoord2f(tx, ty + .0625f);
    133             glVertex3f(x, sqrt2 * (y + 32), sqrt2 * z);
     139            glVertex3f(x, sqrt2 * (y - 38), sqrt2 * z);
    134140        glEnd();
    135141    }
Note: See TracChangeset for help on using the changeset viewer.