6 TgaImage* readTga(const char* path) {
7 FILE* tgaFile = fopen(path, "rb");
14 if (fread(&header, sizeof(TgaHeader), 1, tgaFile) != 1) {
20 GLint imageComponents;
22 switch (header.imageBpp) {
24 imageFormat = GL_BGRA;
25 imageComponents = GL_RGBA8;
29 imageComponents = GL_RGB8;
32 imageFormat = GL_LUMINANCE;
33 imageComponents = GL_LUMINANCE8;
40 unsigned long imageSize = header.imageWidth * header.imageHeight * (header.imageBpp >> 3);
42 GLbyte* bytes = malloc(imageSize * sizeof(GLbyte));
48 if (fread(bytes, imageSize, 1, tgaFile) != 1) {
56 TgaImage* image = malloc(sizeof(TgaImage));
61 (*image).header = header;
62 (*image).imageFormat = imageFormat;
63 (*image).imageComponents = imageComponents;
64 (*image).bytes = bytes;