8 TgaImage* readTga(const char* path) {
9 FILE* tgaFile = fopen(path, "rb");
10 if (tgaFile == NULL) {
16 if (fread(&header, sizeof(TgaHeader), 1, tgaFile) != 1) {
22 GLint imageComponents;
24 switch (header.imageBpp) {
26 imageFormat = GL_BGRA_EXT;
27 imageComponents = GL_RGBA8;
30 imageFormat = GL_BGR_EXT;
31 imageComponents = GL_RGB8;
34 imageFormat = GL_LUMINANCE;
35 imageComponents = GL_LUMINANCE8;
42 unsigned long imageSize = header.imageWidth * header.imageHeight * (header.imageBpp >> 3);
44 GLbyte* bytes = malloc(imageSize * sizeof(GLbyte));
50 if (fread(bytes, imageSize, 1, tgaFile) != 1) {
58 TgaImage* image = malloc(sizeof(TgaImage));
63 (*image).header = header;
64 (*image).imageFormat = imageFormat;
65 (*image).imageComponents = imageComponents;
66 (*image).bytes = bytes;