commit 56d21f210cb40456a3d30d35d7e429808a3a2dd9
parent 300221b1551048b29b92b78fee9da849dc64c71c
Author: amin <dev@aminmesbah.com>
Date: Mon, 8 Jul 2019 20:38:11 +0000
Convert BGRA image to RGBA
FossilOrigin-Name: 4fadea43f5ca769f50a8e248fa85cf09e81588b167113395e70c7f38087df976
Diffstat:
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/game.c b/src/game.c
@@ -194,7 +194,6 @@ internal void game_init(struct GameMemory *game_memory, v2u framebuffer)
// game_load_images
{
size_t file_len = 0;
- //u8 *t = platform.platform_read_entire_file("assets/test_sw_origin.tga", &file_len);
u8 *t = platform.platform_read_entire_file("assets/tile0.tga", &file_len);
assert(t);
diff --git a/src/image.c b/src/image.c
@@ -102,6 +102,15 @@ internal u8 *img_load_from_memory(u8 *buffer, size_t len, i32 *out_width, i32 *o
}
}
+ // NOTE(amin): we convert BGRA to RGBA because OpenGL ES and WebGL don't
+ // support the GL_BGRA texture format.
+ for (size_t b = 0; b < img_data_buf_len; b += 4)
+ {
+ u8 temp = img_data[b];
+ img_data[b + 0] = img_data[b + 2];
+ img_data[b + 2] = temp;
+ }
+
// NOTE(amin): Intentional truncating division. If height is odd, we want
// our last row offset to be 1 less than the middle row.
u32 half_height = h.height / 2;
diff --git a/src/render.c b/src/render.c
@@ -53,7 +53,7 @@ internal void renderer_init(struct RendererState *renderer, struct Image *images
u32 texture_id;
glGenTextures(1, &texture_id);
glBindTexture(GL_TEXTURE_2D, texture_id);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.dim.width, img.dim.height, 0, GL_BGRA, GL_UNSIGNED_BYTE, img.data);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.dim.width, img.dim.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.data);
glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);