aboutsummaryrefslogtreecommitdiff
path: root/loader.c
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2015-11-05 20:53:11 +0000
committerHarry Jeffery <harry@exec64.co.uk>2015-11-05 21:14:34 +0000
commitb6b9b5084fc482df71b020897453e63f55ec2726 (patch)
treeb1390f6b6da2509e46a879d5896374f1108e7532 /loader.c
parent0e1a6d0a7ae5053a70c2e35e18ac3713528f0870 (diff)
downloadimv-b6b9b5084fc482df71b020897453e63f55ec2726.tar.gz
Add a PNG loader
Diffstat (limited to 'loader.c')
-rw-r--r--loader.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/loader.c b/loader.c
index 0a94cf9..9f62d24 100644
--- a/loader.c
+++ b/loader.c
@@ -1,13 +1,14 @@
#include <SDL2/SDL.h>
#include <string.h>
+extern SDL_Texture* imv_load_png(SDL_Renderer *r, const char* path);
+
SDL_Texture* imv_load_image(SDL_Renderer *r, const char* path)
{
if(!path)
return NULL;
const char* ext = strrchr(path, '.');
- SDL_Texture *img = NULL;
if(ext == NULL) {
fprintf(stderr,
"Could not determine filetype of '%s' from its extension.\n",
@@ -15,7 +16,7 @@ SDL_Texture* imv_load_image(SDL_Renderer *r, const char* path)
} else if(strcasecmp(ext, ".test") == 0) {
const int width = 1280;
const int height = 720;
- img = SDL_CreateTexture(r,
+ SDL_Texture *img = SDL_CreateTexture(r,
SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STATIC,
width, height);
void *pixels = malloc(width*height*3);
@@ -23,7 +24,10 @@ SDL_Texture* imv_load_image(SDL_Renderer *r, const char* path)
SDL_Rect area = {0,0,width,height};
SDL_UpdateTexture(img, &area, pixels, width * 3);
free(pixels);
+ return img;
+ } else if(strcasecmp(ext, ".png") == 0) {
+ return imv_load_png(r, path);
}
- return img;
+ return NULL;
}