fixed incorrect loading of RGBA formatted images, added blend calls in main to test
authormatthew <matthew@owens.tech>
Tue, 21 Aug 2018 20:16:40 +0000 (21:16 +0100)
committermatthew <matthew@owens.tech>
Tue, 21 Aug 2018 20:16:40 +0000 (21:16 +0100)
gl/main.c
gl/texture.c
textures/target.png [new file with mode: 0644]

index d627dbc..6d5de9b 100644 (file)
--- a/gl/main.c
+++ b/gl/main.c
@@ -62,7 +62,7 @@ static void initShapes()
        // loading our textures
        stbi_set_flip_vertically_on_load(true);
        tex[0] = crpgTextureNew("textures/wall.jpg");
-       tex[1] = crpgTextureNew("textures/awesomeface.png");
+       tex[1] = crpgTextureNew("textures/target.png");
 
        shader = crpgShaderNew("tri");
        crpgShaderUse(shader);
@@ -142,6 +142,8 @@ static void render()
        glActiveTexture(GL_TEXTURE1);
        glBindTexture(GL_TEXTURE_2D, crpgTextureGetID(tex[1]));
 
+       glEnable(GL_BLEND);
+       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glBindVertexArray(vao);
        glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
 
index 69ed0d4..0056a74 100644 (file)
@@ -21,7 +21,7 @@ crpgTexture *crpgTextureNew(const char *filename){
                if(chan == 3){
                        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
                } else if (chan == 4) {
-                       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+                       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
                } else {
                        err_output("Error loading texture, images that are not formatted as\
                                        RGB or RGBA are unsupported!");
diff --git a/textures/target.png b/textures/target.png
new file mode 100644 (file)
index 0000000..75f96a3
Binary files /dev/null and b/textures/target.png differ