[osg-users] conversion from .vert/.frag files to cpp inline

Robert Osfield robert.osfield at gmail.com
Tue May 15 00:27:33 PDT 2018


Hi Christoph,

On 15 May 2018 at 07:47, Christoph Dohmen <christoph.dohmen at cae.de> wrote:
> is there any easy 'conversion utility' to create cpp inlined definition of shader sources from .vert / .frag files?

There is the osg2cpp example, you need to build OpenSceneGraph with
the BULD_EXAMPLES set to ON to build it.  To use it to generate cpp
files from your shaders run:


  osg2cpp --shader myshaderfile.frag

This will generate a myshaderfile_frag.cpp file that you can include.

Within the OSG code base this is used in the osgParctile, osgTerrain,
osgVolume and osgText libraries - look in their shaders/
subdirectories directories.

The way to use the files in your main source code is also demonstrated
in the above NodeKits, for instance in
OpenSceneGraph/src/osgText/Text.cpp (in 3.6) you'll find:


    {
        DEBUG_MESSAGE<<"Using shaders/osgText_Text.vert"<<std::endl;

        #include "shaders/osgText_Text_vert.cpp"
        program->addShader(osgDB::readRefShaderFileWithFallback(osg::Shader::VERTEX,
"shaders/osgText_Text.vert", osgText_Text_vert));
    }

    {
        DEBUG_MESSAGE<<"Using shaders/osgText_Text.frag"<<std::endl;

        #include "shaders/osgText_Text_frag.cpp"
        program->addShader(osgDB::readRefShaderFileWithFallback(osg::Shader::FRAGMENT,
"shaders/osgText_Text.frag", osgText_Text_frag));
    }


This loads the original .vert or .frag file if it's available
otherwise it falls back to the version that is compiled in.

Cheers,
Robert.


More information about the osg-users mailing list