2 * $Id: genglsl.c,v 1.1 2007-09-28 07:24:14 nkeynes Exp $
4 * Trivial tool to take two shader source files and dump them out in
5 * a C file with appropriate escaping.
7 * Copyright (c) 2007 Nathan Keynes.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
24 * Copy input to output, quoting " characters as we go.
26 void writeShader( FILE *out, FILE *in )
30 while( (ch = fgetc(in)) != EOF ) {
33 } else if( ch == '\n') {
34 fputs( "\\n\\", out );
40 int main( int argc, char *argv[] )
43 fprintf( stderr, "Usage: genglsl <vertex-shader-file> <fragment-shader-file> <output-file>\n");
47 FILE *vsin = fopen( argv[1], "ro" );
49 perror( "Unable to open vertex shader source" );
53 FILE *fsin = fopen( argv[2], "ro" );
55 perror( "Unable to open fragment shader source" );
59 FILE *out = fopen( argv[3], "wo" );
61 perror( "Unable to open output file" );
65 fprintf( out, "/**\n * This file is automatically generated - do not edit\n */\n\n" );
66 fprintf( out, "const char *glsl_vertex_shader_src = \"" );
68 writeShader( out, vsin );
70 fprintf( out, "\";\n\n" );
71 fprintf( out, "const char *glsl_fragment_shader_src = \"" );
72 writeShader( out, fsin );
73 fprintf( out, "\";\n\n" );
.