comparison 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
comparison
equal deleted inserted replaced
496:6fc71114d145 497:0820a71b80f3
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 #include "render.h" 8 #include "render.h"
9 #include "blastem.h" 9 #include "blastem.h"
10 #include "io.h" 10 #include "io.h"
11 #include "util.h"
11 12
12 #ifndef DISABLE_OPENGL 13 #ifndef DISABLE_OPENGL
13 #include <GL/glew.h> 14 #include <GL/glew.h>
14 #endif 15 #endif
15 16
109 110
110 const GLushort element_data[] = {0, 1, 2, 3}; 111 const GLushort element_data[] = {0, 1, 2, 3};
111 112
112 GLuint load_shader(char * fname, GLenum shader_type) 113 GLuint load_shader(char * fname, GLenum shader_type)
113 { 114 {
114 FILE * f = fopen(fname, "r"); 115 char * parts[] = {getenv("HOME"), "/.config/blastem/shaders/", fname};
116 char * shader_path = alloc_concat_m(3, parts);
117 FILE * f = fopen(shader_path, "r");
118 free(shader_path);
115 if (!f) { 119 if (!f) {
116 fprintf(stderr, "Failed to open shader file %s for reading\n", fname); 120 parts[0] = get_exe_dir();
117 return 0; 121 parts[1] = "/shaders/";
118 } 122 shader_path = alloc_concat_m(3, parts);
119 fseek(f, 0, SEEK_END); 123 f = fopen(shader_path, "r");
120 long fsize = ftell(f); 124 free(shader_path);
121 fseek(f, 0, SEEK_SET); 125 if (!f) {
126 fprintf(stderr, "Failed to open shader file %s for reading\n", fname);
127 return 0;
128 }
129 }
130 long fsize = file_size(f);
122 GLchar * text = malloc(fsize); 131 GLchar * text = malloc(fsize);
123 if (fread(text, 1, fsize, f) != fsize) { 132 if (fread(text, 1, fsize, f) != fsize) {
124 fprintf(stderr, "Error reading from shader file %s\n", fname); 133 fprintf(stderr, "Error reading from shader file %s\n", fname);
125 free(text); 134 free(text);
126 return 0; 135 return 0;