aboutsummaryrefslogtreecommitdiff
path: root/loader.c
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2015-11-05 20:34:05 +0000
committerHarry Jeffery <harry@exec64.co.uk>2015-11-05 20:43:31 +0000
commit0e1a6d0a7ae5053a70c2e35e18ac3713528f0870 (patch)
treefcbc8bd839416ef28e8350f4ccf90b36f711bcf9 /loader.c
parent0639d83b2d79e2c03c43cdc85e1cb28630ed14bb (diff)
downloadimv-0e1a6d0a7ae5053a70c2e35e18ac3713528f0870.tar.gz
Add image loading stub
Diffstat (limited to 'loader.c')
-rw-r--r--loader.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/loader.c b/loader.c
new file mode 100644
index 0000000..0a94cf9
--- /dev/null
+++ b/loader.c
@@ -0,0 +1,29 @@
+#include <SDL2/SDL.h>
+#include <string.h>
+
+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",
+ path);
+ } else if(strcasecmp(ext, ".test") == 0) {
+ const int width = 1280;
+ const int height = 720;
+ img = SDL_CreateTexture(r,
+ SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STATIC,
+ width, height);
+ void *pixels = malloc(width*height*3);
+ memset(pixels, 255, width*height*3);
+ SDL_Rect area = {0,0,width,height};
+ SDL_UpdateTexture(img, &area, pixels, width * 3);
+ free(pixels);
+ }
+
+ return img;
+}