summaryrefslogtreecommitdiff
path: root/render_sdl.c
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2019-01-22 21:15:38 -0800
committerMichael Pavone <pavone@retrodev.com>2019-01-22 21:15:38 -0800
commitf69db0983a2f435e7a0147bf8ad82b16196d4397 (patch)
tree206952a99c231a5a2214c41a8576fe7e82db6871 /render_sdl.c
parent3916a1dcdac01b4a7da14c9561707046af6a1ef5 (diff)
Added some Makefile options to build a packaging friendly executable
Diffstat (limited to 'render_sdl.c')
-rwxr-xr-xrender_sdl.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/render_sdl.c b/render_sdl.c
index 62bac8f..2f5bfcd 100755
--- a/render_sdl.c
+++ b/render_sdl.c
@@ -13,6 +13,7 @@
#include "genesis.h"
#include "bindings.h"
#include "util.h"
+#include "paths.h"
#include "ppm.h"
#include "png.h"
#include "config.h"
@@ -489,24 +490,28 @@ static GLuint load_shader(char * fname, GLenum shader_type)
char * shader_path = alloc_concat_m(3, parts);
FILE * f = fopen(shader_path, "rb");
free(shader_path);
- if (!f) {
- parts[0] = get_exe_dir();
- parts[1] = "/shaders/";
- shader_path = alloc_concat_m(3, parts);
- f = fopen(shader_path, "rb");
+ GLchar * text;
+ long fsize;
+ if (f) {
+ fsize = file_size(f);
+ text = malloc(fsize);
+ if (fread(text, 1, fsize, f) != fsize) {
+ warning("Error reading from shader file %s\n", fname);
+ free(text);
+ return 0;
+ }
+ } else {
+ shader_path = path_append("shaders", fname);
+ uint32_t fsize32;
+ text = read_bundled_file(shader_path, &fsize32);
free(shader_path);
- if (!f) {
+ if (!text) {
warning("Failed to open shader file %s for reading\n", fname);
return 0;
}
+ fsize = fsize32;
}
- long fsize = file_size(f);
- GLchar * text = malloc(fsize);
- if (fread(text, 1, fsize, f) != fsize) {
- warning("Error reading from shader file %s\n", fname);
- free(text);
- return 0;
- }
+
if (strncmp(text, "#version", strlen("#version"))) {
GLchar *tmp = text;
text = alloc_concat(shader_prefix, tmp);