From ccb3e58071b3e807109918184727b305df8b96a0 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 5 Nov 2021 14:44:21 +0100 Subject: Fix font being corrupt with certain sizes, fix image being corrupt if its rgb, fix window resize incorrect size --- src/graphics/image.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/graphics/image.c') 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 #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; -- cgit v1.2.3