void Image::upload_texture() { if (tex != 0 || image == NULL) return; #ifndef CHOWDREN_IS_WIIU // create alpha mask int size = width * height; BaseBitArray::word_t * data; data = (BaseBitArray::word_t*)malloc(GET_BITARRAY_SIZE(size)); int i = 0; int ii = 0; unsigned char c; while (i < size) { BaseBitArray::word_t word = 0; for (BaseBitArray::word_t m = 1UL; m != 0UL; m <<= 1UL) { c = ((unsigned char*)(((unsigned int*)image) + i))[3]; if (c != 0) word |= m; ++i; if (i >= size) break; } data[ii++] = word; } alpha.data = data; #endif int gl_width, gl_height; gl_width = width; gl_height = height; tex = Render::create_tex(image, Render::RGBA, gl_width, gl_height); Render::set_filter(tex, (flags & LINEAR_FILTER) != 0); if (flags & KEEP) return; // for memory reasons, we delete the image and access the alpha or // the texture directly stbi_image_free(image); image = NULL; }
void PathPlanner::create_map() { int size = GET_BITARRAY_SIZE(map_width * map_height); map.data = (BaseBitArray::word_t*)malloc(size); memset(map.data, 0, size); }
void Image::upload_texture() { if (tex != 0 || image == NULL) return; #ifndef CHOWDREN_IS_WIIU // create alpha mask int size = width * height; BaseBitArray::word_t * data; data = (BaseBitArray::word_t*)malloc(GET_BITARRAY_SIZE(size) * 4); int i = 0; int ii = 0; unsigned char c; while (i < size) { BaseBitArray::word_t word = 0; for (BaseBitArray::word_t m = 1UL; m != 0UL; m <<= 1UL) { c = ((unsigned char*)(((unsigned int*)image) + i))[3]; if (c != 0) word |= m; ++i; if (i >= size) break; } data[ii++] = word; } alpha.data = data; #endif int gl_width, gl_height; #ifdef CHOWDREN_NO_NPOT pot_w = std::max(8, round_pow2(width)); pot_h = std::max(8, round_pow2(height)); if (pot_w >= 1024 || pot_h >= 1024) { pot_w = std::min<short>(1024, pot_w); pot_h = std::min<short>(1024, pot_h); } gl_width = pot_w; gl_height = pot_h; if (pot_w != width || pot_h != height) { unsigned int * old_image =(unsigned int*)image; image = (unsigned char*)malloc(pot_w * pot_h * 4); unsigned int * image_arr = (unsigned int*)image; // in case the image is being cut off due to dimension restrictions int ww = std::min(width, pot_w); int hh = std::min(height, pot_h); for (int x = 0; x < ww; x++) for (int y = 0; y < hh; y++) { image_arr[x + y * pot_w] = old_image[x + y * width]; } stbi_image_free(old_image); } #else gl_width = width; gl_height = height; #endif tex = Render::create_tex(image, Render::RGBA, gl_width, gl_height); Render::set_filter(tex, (flags & LINEAR_FILTER) != 0); if (flags & KEEP) return; // for memory reasons, we delete the image and access the alpha or // the texture directly stbi_image_free(image); image = NULL; }