From 27eb6b37f9b2a9b0c05770475fb28f8792fcf5c5 Mon Sep 17 00:00:00 2001 From: Mike Pavone Date: Mon, 28 Oct 2013 23:50:28 -0700 Subject: Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory. --- render_sdl.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'render_sdl.c') diff --git a/render_sdl.c b/render_sdl.c index f4241fc..f36318d 100644 --- a/render_sdl.c +++ b/render_sdl.c @@ -8,6 +8,7 @@ #include "render.h" #include "blastem.h" #include "io.h" +#include "util.h" #ifndef DISABLE_OPENGL #include @@ -111,14 +112,22 @@ const GLushort element_data[] = {0, 1, 2, 3}; GLuint load_shader(char * fname, GLenum shader_type) { - FILE * f = fopen(fname, "r"); + char * parts[] = {getenv("HOME"), "/.config/blastem/shaders/", fname}; + char * shader_path = alloc_concat_m(3, parts); + FILE * f = fopen(shader_path, "r"); + free(shader_path); if (!f) { - fprintf(stderr, "Failed to open shader file %s for reading\n", fname); - return 0; + parts[0] = get_exe_dir(); + parts[1] = "/shaders/"; + shader_path = alloc_concat_m(3, parts); + f = fopen(shader_path, "r"); + free(shader_path); + if (!f) { + fprintf(stderr, "Failed to open shader file %s for reading\n", fname); + return 0; + } } - fseek(f, 0, SEEK_END); - long fsize = ftell(f); - fseek(f, 0, SEEK_SET); + long fsize = file_size(f); GLchar * text = malloc(fsize); if (fread(text, 1, fsize, f) != fsize) { fprintf(stderr, "Error reading from shader file %s\n", fname); -- cgit v1.2.3