Changeset 689 for trunk/src/tileset.cpp
- Timestamp:
- Feb 22, 2011, 2:39:26 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tileset.cpp
r686 r689 16 16 #include <cstdio> 17 17 #include <cmath> 18 #include <cstring> 18 19 19 20 #ifdef WIN32 … … 22 23 #endif 23 24 24 #if defined USE_SDL25 # include <SDL.h>26 # include <SDL_image.h>27 #endif28 29 25 #include "core.h" 30 26 #include "lolgl.h" … … 44 40 char *name, *path; 45 41 int *tiles, ntiles; 46 vec2i size, count;42 vec2i size, isize, count; 47 43 float dilate, tx, ty; 48 44 49 #if defined USE_SDL 50 SDL_Surface *img; 51 #endif 45 Image *img; 52 46 GLuint texture; 53 47 }; … … 65 59 66 60 data->tiles = NULL; 67 #if defined USE_SDL68 data->img = NULL;69 #endif70 61 data->texture = 0; 71 72 #if defined USE_SDL 73 for (char const *name = path; *name; name++) 74 if ((data->img = IMG_Load(name))) 75 break; 76 77 if (!data->img) 78 { 79 #if !LOL_RELEASE 80 fprintf(stderr, "ERROR: could not load %s\n", path); 81 #endif 82 SDL_Quit(); 83 exit(1); 84 } 62 data->img = new Image(path); 63 data->isize = data->img->GetSize(); 85 64 86 65 if (count.i > 0 && count.j > 0) 87 66 { 88 67 data->count = count; 89 data->size = vec2i(data->img->w, data->img->h)/ count;68 data->size = data->isize / count; 90 69 } 91 70 else … … 93 72 if (size.x <= 0 || size.y <= 0) 94 73 size = 32; 95 data->count.i = data->i mg->w > size.i ? data->img->w/ size.i : 1;96 data->count.j = data->i mg->h > size.j ? data->img->h/ size.j : 1;74 data->count.i = data->isize.x > size.i ? data->isize.x / size.i : 1; 75 data->count.j = data->isize.y > size.j ? data->isize.y / size.j : 1; 97 76 data->size = size; 98 77 } 99 78 100 data->tx = (float)data->size.x / PotUp(data->img->w); 101 data->ty = (float)data->size.y / PotUp(data->img->h); 102 #endif 79 data->tx = (float)data->size.x / PotUp(data->isize.x); 80 data->ty = (float)data->size.y / PotUp(data->isize.y); 103 81 104 82 data->dilate = dilate; … … 119 97 Entity::TickDraw(deltams); 120 98 121 #if defined USE_SDL122 99 if (IsDestroying()) 123 100 { 124 101 if (data->img) 125 SDL_FreeSurface(data->img);102 delete data->img; 126 103 else 127 104 glDeleteTextures(1, &data->texture); … … 129 106 else if (data->img) 130 107 { 131 GLuint format = data->img->format->Amask ? GL_RGBA : GL_RGB; 132 int planes = data->img->format->Amask ? 4 : 3; 133 134 int w = PotUp(data->img->w); 135 int h = PotUp(data->img->h); 136 137 uint8_t *pixels = (uint8_t *)data->img->pixels; 138 if (w != data->img->w || h != data->img->h) 108 GLuint format; 109 int planes; 110 111 switch (data->img->GetFormat()) 112 { 113 case Image::FORMAT_RGB: 114 format = GL_RGB; 115 planes = 3; 116 break; 117 case Image::FORMAT_RGBA: 118 default: 119 format = GL_RGBA; 120 planes = 4; 121 break; 122 } 123 124 int w = PotUp(data->isize.x); 125 int h = PotUp(data->isize.y); 126 127 uint8_t *pixels = (uint8_t *)data->img->GetData(); 128 if (w != data->isize.x || h != data->isize.y) 139 129 { 140 130 uint8_t *tmp = (uint8_t *)malloc(planes * w * h); 141 for (int line = 0; line < data->i mg->h; line++)131 for (int line = 0; line < data->isize.y; line++) 142 132 memcpy(tmp + planes * w * line, 143 pixels + planes * data->i mg->w* line,144 planes * data->i mg->w);133 pixels + planes * data->isize.x * line, 134 planes * data->isize.x); 145 135 pixels = tmp; 146 136 } … … 155 145 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 156 146 157 if (pixels != data->img-> pixels)147 if (pixels != data->img->GetData()) 158 148 free(pixels); 159 SDL_FreeSurface(data->img);149 delete data->img; 160 150 data->img = NULL; 161 151 } 162 #endif163 152 } 164 153 … … 180 169 void TileSet::Bind() 181 170 { 182 #if defined USE_SDL 183 if (!data->img) 171 if (!data->img && data->texture) 184 172 glBindTexture(GL_TEXTURE_2D, data->texture); 185 #endif186 173 } 187 174 … … 197 184 int dz = o ? data->size.y : 0; 198 185 199 #if defined USE_SDL 200 if (!data->img) 186 if (!data->img && data->texture) 201 187 { 202 188 float tmp[10]; … … 239 225 } 240 226 else 241 #endif242 227 { 243 228 memset(vertex, 0, 3 * sizeof(float));
Note: See TracChangeset
for help on using the changeset viewer.