]> git.lizzy.rs Git - shadowclad.git/blobdiff - src/engine/tga.c
But we shouldn't yet, because we're using extensions without asking for them
[shadowclad.git] / src / engine / tga.c
index 53ff29a2ee77ad86b750ba6f4bf5f1ee20a59e0f..bf239ac0901173279f3a9a4477997fdfc56f1728 100644 (file)
@@ -3,6 +3,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+// TODO Ask for extensions through GLEW
 #include <GL/glext.h>
 
 TgaImage* readTga(const char* path) {
@@ -10,17 +11,17 @@ TgaImage* readTga(const char* path) {
        if (tgaFile == NULL) {
                return NULL;
        }
-       
+
        TgaHeader header;
-       
+
        if (fread(&header, sizeof(TgaHeader), 1, tgaFile) != 1) {
                fclose(tgaFile);
                return NULL;
        }
-       
+
        GLenum imageFormat;
        GLint imageComponents;
-       
+
        switch (header.imageBpp) {
                case 32:
                        imageFormat = GL_BGRA;
@@ -38,32 +39,32 @@ TgaImage* readTga(const char* path) {
                        fclose(tgaFile);
                        return NULL;
        }
-       
+
        unsigned long imageSize = header.imageWidth * header.imageHeight * (header.imageBpp >> 3);
-       
+
        GLbyte* bytes = malloc(imageSize * sizeof(GLbyte));
        if (bytes == NULL) {
                fclose(tgaFile);
                return NULL;
        }
-       
+
        if (fread(bytes, imageSize, 1, tgaFile) != 1) {
                free(bytes);
                fclose(tgaFile);
                return NULL;
        }
-       
+
        fclose(tgaFile);
-       
+
        TgaImage* image = malloc(sizeof(TgaImage));
        if (image == NULL) {
                return NULL;
        }
-       
+
        (*image).header = header;
        (*image).imageFormat = imageFormat;
        (*image).imageComponents = imageComponents;
        (*image).bytes = bytes;
-       
+
        return image;
 }