1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/tools/genglsl.c Wed Oct 31 11:53:35 2007 +0000
1.5 + * $Id: genglsl.c,v 1.1 2007-09-28 07:24:14 nkeynes Exp $
1.7 + * Trivial tool to take two shader source files and dump them out in
1.8 + * a C file with appropriate escaping.
1.10 + * Copyright (c) 2007 Nathan Keynes.
1.12 + * This program is free software; you can redistribute it and/or modify
1.13 + * it under the terms of the GNU General Public License as published by
1.14 + * the Free Software Foundation; either version 2 of the License, or
1.15 + * (at your option) any later version.
1.17 + * This program is distributed in the hope that it will be useful,
1.18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.20 + * GNU General Public License for more details.
1.24 +#include <stdlib.h>
1.27 + * Copy input to output, quoting " characters as we go.
1.29 +void writeShader( FILE *out, FILE *in )
1.33 + while( (ch = fgetc(in)) != EOF ) {
1.34 + if( ch == '\"' ) {
1.35 + fputc( '\\', out );
1.36 + } else if( ch == '\n') {
1.37 + fputs( "\\n\\", out );
1.43 +int main( int argc, char *argv[] )
1.46 + fprintf( stderr, "Usage: genglsl <vertex-shader-file> <fragment-shader-file> <output-file>\n");
1.50 + FILE *vsin = fopen( argv[1], "ro" );
1.51 + if( vsin == NULL ) {
1.52 + perror( "Unable to open vertex shader source" );
1.56 + FILE *fsin = fopen( argv[2], "ro" );
1.57 + if( fsin == NULL ) {
1.58 + perror( "Unable to open fragment shader source" );
1.62 + FILE *out = fopen( argv[3], "wo" );
1.63 + if( out == NULL ) {
1.64 + perror( "Unable to open output file" );
1.68 + fprintf( out, "/**\n * This file is automatically generated - do not edit\n */\n\n" );
1.69 + fprintf( out, "const char *glsl_vertex_shader_src = \"" );
1.71 + writeShader( out, vsin );
1.73 + fprintf( out, "\";\n\n" );
1.74 + fprintf( out, "const char *glsl_fragment_shader_src = \"" );
1.75 + writeShader( out, fsin );
1.76 + fprintf( out, "\";\n\n" );