aboutsummaryrefslogtreecommitdiff
path: root/src/graphics/image.c
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-10-24 04:52:30 +0200
committerdec05eba <dec05eba@protonmail.com>2021-10-24 04:52:30 +0200
commit115630b520668304af1ccd3eb0b13c06e17ecccc (patch)
treee3949bd4fe36ae3b43c11d4e9ecd0bf523a6e910 /src/graphics/image.c
parent898b8c95f1f904307c02e978b57301cf1cb0560f (diff)
Add function to load image from memory, initialize window from an existing window, allow creating text without font/string
Diffstat (limited to 'src/graphics/image.c')
-rw-r--r--src/graphics/image.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/graphics/image.c b/src/graphics/image.c
index 430f03a..593a3d2 100644
--- a/src/graphics/image.c
+++ b/src/graphics/image.c
@@ -52,6 +52,25 @@ int mgl_image_load_from_file(mgl_image *self, const char *filepath) {
return 0;
}
+/* TODO: Ensure texture is power of 2 if the hardware doesn't support non power of two textures */
+/* TODO: Verify if source format should always be 4 components (RGBA) because apparently if its another format then opengl will internally convert it to RGBA */
+int mgl_image_load_from_memory(mgl_image *self, const unsigned char *data, size_t size) {
+ self->data = NULL;
+ self->width = 0;
+ self->height = 0;
+
+ int format;
+ self->data = stbi_load_from_memory(data, size, &self->width, &self->height, &format, 0);
+ if(!self->data) {
+ fprintf(stderr, "Error: failed to load image from memory, error: %s\n", stbi_failure_reason());
+ mgl_image_unload(self);
+ return -1;
+ }
+ self->format = stbi_format_to_mgl_image_format(format);
+
+ return 0;
+}
+
void mgl_image_unload(mgl_image *self) {
if(self->data) {
stbi_image_free(self->data);