unsigned char * load_targa(const char * filename, GLenum &format, int &width, int &height) { targa_header header; FILE * f; f = fopen(filename, "rb"); if (!f) return 0; fread(&header, sizeof(header), 1, f); width = header.image_spec.width; height = header.image_spec.height; GLenum type; int size; get_targa_format_type_and_size(header, format, type, size); unsigned char * data = new unsigned char [width * height * size]; if (is_compressed_targa(header)) { // TODO: Handle compressed targa files } else { fread(data, width * height, size, f); } fclose(f); return data; }
unsigned char * load_targa(const char * filename, GLenum &format, int &width, int &height) { targa_header header; FILE * f; f = fopen(filename, "rb"); if (!f) return 0; fread(&header, sizeof(header), 1, f); width = header.image_spec.width; height = header.image_spec.height; GLenum type; int size; get_targa_format_type_and_size(header, format, type, size); unsigned char * data = new unsigned char [width * height * size]; if (is_compressed_targa(header)) { // TODO: Handle compressed targa files } else { fread(data, width * height, size, f); //memset(data, 100, width * height * size); for (auto i = 0; i < width; i++) { for (auto j = 0; j < height; j++) { size_t base = (i * width + j) * 3; if (i <= 50 || i >= width - 50 || j <= 50 || j >= height - 50) { data[base] = data[base + 1] = data[base + 2] = 0x00; } else { data[base] = 0x0F; data[base + 1] = 00; data[base + 2] = 0xf0; } } } } fclose(f); return data; }