From 07a8d082e414c21182aeecb9096da78153e34862 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 30 Aug 2017 17:43:29 +0100 Subject: [PATCH] Added --shader filename command line parsing and associated set up of osg::Program to allow shaders to be passed into example to customize rendering --- examples/osgfont/osgfont.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/examples/osgfont/osgfont.cpp b/examples/osgfont/osgfont.cpp index 43a8653d5..823e7ae24 100644 --- a/examples/osgfont/osgfont.cpp +++ b/examples/osgfont/osgfont.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -200,6 +201,29 @@ int main(int argc, char** argv) root = transform; } + osg::ref_ptr program = new osg::Program; + std::string shaderFilename; + while(args.read("--shader", shaderFilename)) + { + osg::ref_ptr shader = osgDB::readRefShaderFile(shaderFilename); + if (shader.get()) + { + OSG_NOTICE<<"Loading shader "<addShader(shader.get()); + } + } + + if (program->getNumShaders()>0) + { + OSG_NOTICE<<"Using shaders"<getOrCreateStateSet()->setAttribute(program.get(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON); + root->getOrCreateStateSet()->addUniform(new osg::Uniform("glyphTexture", 0)); + } + + + std::string outputFilename; + if (args.read("-o", outputFilename)) {} + if (args.argc() > 1) { settings.fontFilename = argv[1]; @@ -235,10 +259,9 @@ int main(int argc, char** argv) root->addChild(geode); - std::string filename; - if (args.read("-o", filename)) + if (!outputFilename.empty()) { - osgDB::writeNodeFile(*root, filename); + osgDB::writeNodeFile(*root, outputFilename); return 0; }