diff options
Diffstat (limited to 'src/graphics/image.c')
-rw-r--r-- | src/graphics/image.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/graphics/image.c b/src/graphics/image.c index 593a3d2..9934b42 100644 --- a/src/graphics/image.c +++ b/src/graphics/image.c @@ -1,4 +1,5 @@ #include "../../include/mgl/graphics/image.h" +#include <assert.h> #define STBI_NO_PSD #define STBI_NO_TGA @@ -19,7 +20,8 @@ static mgl_image_format stbi_format_to_mgl_image_format(int stbi_format) { case STBI_rgb_alpha: return MGL_IMAGE_FORMAT_RGBA; } - return 0; + assert(0); + return MGL_IMAGE_FORMAT_RGBA; } static size_t mgl_image_format_num_channels(mgl_image_format image_format) { @@ -30,7 +32,8 @@ static size_t mgl_image_format_num_channels(mgl_image_format image_format) { case MGL_IMAGE_FORMAT_RGB: return 3; case MGL_IMAGE_FORMAT_RGBA: return 4; } - return 0; + assert(0); + return 4; } /* TODO: Ensure texture is power of 2 if the hardware doesn't support non power of two textures */ @@ -41,12 +44,14 @@ int mgl_image_load_from_file(mgl_image *self, const char *filepath) { self->height = 0; int format; - self->data = stbi_load(filepath, &self->width, &self->height, &format, 0); + /* TODO: format is forced to rgba right now because rgb images cause the image to be skewed (bug) */ + self->data = stbi_load(filepath, &self->width, &self->height, &format, 4); if(!self->data) { fprintf(stderr, "Error: failed to load image %s, error: %s\n", filepath, stbi_failure_reason()); mgl_image_unload(self); return -1; } + format = 4; self->format = stbi_format_to_mgl_image_format(format); return 0; @@ -60,12 +65,14 @@ int mgl_image_load_from_memory(mgl_image *self, const unsigned char *data, size_ self->height = 0; int format; - self->data = stbi_load_from_memory(data, size, &self->width, &self->height, &format, 0); + /* TODO: format is forced to rgba right now because rgb images cause the image to be skewed (bug) */ + self->data = stbi_load_from_memory(data, size, &self->width, &self->height, &format, 4); if(!self->data) { fprintf(stderr, "Error: failed to load image from memory, error: %s\n", stbi_failure_reason()); mgl_image_unload(self); return -1; } + format = 4; self->format = stbi_format_to_mgl_image_format(format); return 0; |