diff --git a/examples/osg2cpp/osg2cpp.cpp b/examples/osg2cpp/osg2cpp.cpp index 893eb1956..ee306eab4 100644 --- a/examples/osg2cpp/osg2cpp.cpp +++ b/examples/osg2cpp/osg2cpp.cpp @@ -30,13 +30,13 @@ void writeShader(osg::Shader* shader, const std::string& cppFileName, const std: searchAndReplace(shaderSource, "\r\n", "\n"); searchAndReplace(shaderSource, "\r", "\n"); searchAndReplace(shaderSource, "\"", "\\\""); - + std::string variableString = std::string("char ")+variableName+std::string("[] = "); - + std::string::size_type startOfLine = 0; std::string::size_type endOfLine = shaderSource.find_first_of('\n', startOfLine); - - if (endOfLine==std::string::npos) + + if (endOfLine==std::string::npos) { fout<setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is a utility for converting glsl shader files into char arrays that can be compiled into applications."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); arguments.getApplicationUsage()->addCommandLineOption("--shader ","Shader file to create a .cpp file for."); + arguments.getApplicationUsage()->addCommandLineOption("--write-to-source-file-directory","Use the path to the source filename as the directory to write to."); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display command line parameters"); // if user request help write it out to cout. if (arguments.read("-h") || arguments.read("--help")) - { + { arguments.getApplicationUsage()->write(std::cout); return 1; } - + + bool useSamePathAsSourceFile = false; + if (arguments.read("--write-to-source-file-directory")) useSamePathAsSourceFile = true; + std::string filename; if (arguments.read("--shader",filename)) { @@ -94,9 +98,11 @@ int main( int argc, char **argv ) name[pos] = '_'; pos = name.find_first_of(invalidCharacters); } - + std::string ext = osgDB::getFileExtension(filename); - std::string cppFileName = osgDB::concatPaths(path, name + "_" + ext + ".cpp"); + std::string cppFileName = name + "_" + ext + ".cpp"; + if (useSamePathAsSourceFile) cppFileName = osgDB::concatPaths(path, cppFileName); + std::string variableName = name + "_" + ext; writeShader(shader.get(), cppFileName, variableName); @@ -107,7 +113,7 @@ int main( int argc, char **argv ) std::cout<<"Error: could not find file '"<