diff render_sdl.c @ 497:0820a71b80f3

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.
author Mike Pavone <pavone@retrodev.com>
date Mon, 28 Oct 2013 23:50:28 -0700
parents 39cad98d2789
children 51bf87f76d15
line wrap: on
line diff
--- a/render_sdl.c	Mon Oct 28 21:48:46 2013 -0700
+++ b/render_sdl.c	Mon Oct 28 23:50:28 2013 -0700
@@ -8,6 +8,7 @@
 #include "render.h"
 #include "blastem.h"
 #include "io.h"
+#include "util.h"
 
 #ifndef DISABLE_OPENGL
 #include <GL/glew.h>
@@ -111,14 +112,22 @@
 
 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);