Changeset 269


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

Convert NPOT textures in code.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/font.cpp

    r259 r269  
    8989        data->height = data->img->h / 16;
    9090
     91        GLuint format = data->img->format->Amask ? GL_RGBA : GL_RGB;
     92        int planes = data->img->format->Amask ? 4 : 3;
     93
     94        int w = PotUp(data->img->w);
     95        int h = PotUp(data->img->h);
     96
     97        uint8_t *pixels = (uint8_t *)data->img->pixels;
     98        if (w != data->img->w || h != data->img->h)
     99        {
     100            uint8_t *tmp = (uint8_t *)malloc(planes * w * h);
     101            for (int line = 0; line < data->img->h; line++)
     102                memcpy(tmp + planes * w * line,
     103                       pixels + planes * data->img->w * line,
     104                       planes * data->img->w);
     105            pixels = tmp;
     106        }
     107
    91108        glGenTextures(1, &data->texture);
    92109        glBindTexture(GL_TEXTURE_2D, data->texture);
    93110
    94         glTexImage2D(GL_TEXTURE_2D, 0, 4, data->img->w, data->img->h, 0,
    95                      GL_RGBA, GL_UNSIGNED_BYTE, data->img->pixels);
     111        glTexImage2D(GL_TEXTURE_2D, 0, planes, w, h, 0,
     112                     format, GL_UNSIGNED_BYTE, pixels);
    96113
    97114        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    98115        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    99116
     117        if (pixels != data->img->pixels)
     118            free(pixels);
    100119        SDL_FreeSurface(data->img);
    101120        data->img = NULL;
  • 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.