Ignore:
Timestamp:
Jan 23, 2011, 6:46:02 PM (11 years ago)
Author:
sam
Message:

Convert NPOT textures in code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tileset.cpp

    r259 r269  
    8484    data->nh = data->img->h / h;
    8585    data->ntiles = data->nw * data->nh;
    86     data->tx = (float)w / data->img->w;
    87     data->ty = (float)h / data->img->h;
     86    data->tx = (float)w / PotUp(data->img->w);
     87    data->ty = (float)h / PotUp(data->img->h);
    8888
    8989    drawgroup = DRAWGROUP_BEFORE;
     
    113113        int planes = data->img->format->Amask ? 4 : 3;
    114114
     115        int w = PotUp(data->img->w);
     116        int h = PotUp(data->img->h);
     117
     118        uint8_t *pixels = (uint8_t *)data->img->pixels;
     119        if (w != data->img->w || h != data->img->h)
     120        {
     121            uint8_t *tmp = (uint8_t *)malloc(planes * w * h);
     122            for (int line = 0; line < data->img->h; line++)
     123                memcpy(tmp + planes * w * line,
     124                       pixels + planes * data->img->w * line,
     125                       planes * data->img->w);
     126            pixels = tmp;
     127        }
     128
    115129        glGenTextures(1, &data->texture);
    116130        glBindTexture(GL_TEXTURE_2D, data->texture);
    117131
    118         glTexImage2D(GL_TEXTURE_2D, 0, planes, data->img->w, data->img->h, 0,
    119                      format, GL_UNSIGNED_BYTE, data->img->pixels);
     132        glTexImage2D(GL_TEXTURE_2D, 0, planes, w, h, 0,
     133                     format, GL_UNSIGNED_BYTE, pixels);
    120134
    121135        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    122136        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    123137
     138        if (pixels != data->img->pixels)
     139            free(pixels);
    124140        SDL_FreeSurface(data->img);
    125141        data->img = NULL;
Note: See TracChangeset for help on using the changeset viewer.