changeset 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 6fc71114d145
children 51bf87f76d15
files default.f.glsl default.v.glsl render_sdl.c shaders/default.f.glsl shaders/default.v.glsl
diffstat 5 files changed, 39 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/default.f.glsl	Mon Oct 28 21:48:46 2013 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-#version 110
-
-uniform sampler2D textures[2];
-
-varying vec2 texcoord;
-
-void main()
-{
-	gl_FragColor = mix(
-		texture2D(textures[0], texcoord),
-		texture2D(textures[1], vec2(texcoord.x, texcoord.y - 1.0/512.0)),
-		sin((texcoord.y * 512.0 - 0.75) * 3.14159265359) / 2.0 + 0.5
-	);
-}
--- a/default.v.glsl	Mon Oct 28 21:48:46 2013 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-#version 110
-
-attribute vec2 pos;
-varying vec2 texcoord;
-
-void main()
-{
-	gl_Position = vec4(pos, 0.0, 1.0);
-	texcoord = pos * vec2(320.0/1024.0, 240.0/-512.0) + vec2(320.0/1024.0, 240.0/512.0);
-}
--- 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);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/shaders/default.f.glsl	Mon Oct 28 23:50:28 2013 -0700
@@ -0,0 +1,14 @@
+#version 110
+
+uniform sampler2D textures[2];
+
+varying vec2 texcoord;
+
+void main()
+{
+	gl_FragColor = mix(
+		texture2D(textures[0], texcoord),
+		texture2D(textures[1], vec2(texcoord.x, texcoord.y - 1.0/512.0)),
+		sin((texcoord.y * 512.0 - 0.75) * 3.14159265359) / 2.0 + 0.5
+	);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/shaders/default.v.glsl	Mon Oct 28 23:50:28 2013 -0700
@@ -0,0 +1,10 @@
+#version 110
+
+attribute vec2 pos;
+varying vec2 texcoord;
+
+void main()
+{
+	gl_Position = vec4(pos, 0.0, 1.0);
+	texcoord = pos * vec2(320.0/1024.0, 240.0/-512.0) + vec2(320.0/1024.0, 240.0/512.0);
+}