Search
lxdream.org :: lxdream/src/tools/genglsl.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/tools/genglsl.c
changeset 405:570d93abb5b7
next561:533f6b478071
author nkeynes
date Thu Dec 06 09:25:24 2007 +0000 (16 years ago)
permissions -rw-r--r--
last change Suppress enable/disable actions if there's no gui
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/tools/genglsl.c Thu Dec 06 09:25:24 2007 +0000
1.3 @@ -0,0 +1,78 @@
1.4 +/**
1.5 + * $Id: genglsl.c,v 1.1 2007-09-28 07:24:14 nkeynes Exp $
1.6 + *
1.7 + * Trivial tool to take two shader source files and dump them out in
1.8 + * a C file with appropriate escaping.
1.9 + *
1.10 + * Copyright (c) 2007 Nathan Keynes.
1.11 + *
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.16 + *
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.21 + */
1.22 +
1.23 +#include <stdio.h>
1.24 +#include <stdlib.h>
1.25 +
1.26 +/**
1.27 + * Copy input to output, quoting " characters as we go.
1.28 + */
1.29 +void writeShader( FILE *out, FILE *in )
1.30 +{
1.31 + int ch;
1.32 +
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.38 + }
1.39 + fputc( ch, out );
1.40 + }
1.41 +}
1.42 +
1.43 +int main( int argc, char *argv[] )
1.44 +{
1.45 + if( argc != 4 ) {
1.46 + fprintf( stderr, "Usage: genglsl <vertex-shader-file> <fragment-shader-file> <output-file>\n");
1.47 + exit(1);
1.48 + }
1.49 +
1.50 + FILE *vsin = fopen( argv[1], "ro" );
1.51 + if( vsin == NULL ) {
1.52 + perror( "Unable to open vertex shader source" );
1.53 + exit(2);
1.54 + }
1.55 +
1.56 + FILE *fsin = fopen( argv[2], "ro" );
1.57 + if( fsin == NULL ) {
1.58 + perror( "Unable to open fragment shader source" );
1.59 + exit(2);
1.60 + }
1.61 +
1.62 + FILE *out = fopen( argv[3], "wo" );
1.63 + if( out == NULL ) {
1.64 + perror( "Unable to open output file" );
1.65 + exit(2);
1.66 + }
1.67 +
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.70 +
1.71 + writeShader( out, vsin );
1.72 +
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" );
1.77 + fclose( fsin );
1.78 + fclose( vsin );
1.79 + fclose( out );
1.80 + return 0;
1.81 +}
.