Search
lxdream.org :: lxdream/src/tools/genglsl.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/tools/genglsl.c
changeset 736:a02d1475ccfd
prev561:533f6b478071
next968:6fb1481859a4
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (13 years ago)
permissions -rw-r--r--
last change Re-indent everything consistently
Fix include guards for consistency as well
view annotate diff log raw
     1 /**
     2  * $Id$
     3  *
     4  * Trivial tool to take two shader source files and dump them out in
     5  * a C file with appropriate escaping.
     6  *
     7  * Copyright (c) 2007 Nathan Keynes.
     8  *
     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.
    13  *
    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.
    18  */
    20 #include <stdio.h>
    21 #include <stdlib.h>
    23 /**
    24  * Copy input to output, quoting " characters as we go.
    25  */
    26 void writeShader( FILE *out, FILE *in )
    27 {
    28     int ch;
    30     while( (ch = fgetc(in)) != EOF ) {
    31         if( ch == '\"' ) {
    32             fputc( '\\', out );
    33         } else if( ch == '\n') {
    34             fputs( "\\n\\", out );
    35         }
    36         fputc( ch, out );
    37     }
    38 }
    40 int main( int argc, char *argv[] )
    41 {
    42     if( argc != 4 ) {
    43         fprintf( stderr, "Usage: genglsl <vertex-shader-file> <fragment-shader-file> <output-file>\n");
    44         exit(1);
    45     }
    47     FILE *vsin = fopen( argv[1], "ro" );
    48     if( vsin == NULL ) {
    49         perror( "Unable to open vertex shader source" );
    50         exit(2);
    51     }
    53     FILE *fsin = fopen( argv[2], "ro" );
    54     if( fsin == NULL ) {
    55         perror( "Unable to open fragment shader source" );
    56         exit(2);
    57     }
    59     FILE *out = fopen( argv[3], "wo" );
    60     if( out == NULL ) {
    61         perror( "Unable to open output file" );
    62         exit(2);
    63     }
    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" );
    74     fclose( fsin );
    75     fclose( vsin );
    76     fclose( out );
    77     return 0;
    78 }
.