vancegroup / vr-jugglua

VR JuggLua: A Framework for VR Applications Combining Lua, OpenSceneGraph, and VR Juggler
Boost Software License 1.0
11 stars 11 forks source link

Easily load images, videos, etc. into quads #122

Open rpavlik opened 10 years ago

rpavlik commented 10 years ago

Some code from Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments,const ReaderWriter::Options* options):


    while (arguments.read("--image",filename))
    {
        osg::ref_ptr<osg::Image> image = readImageFile(filename.c_str(), options);
        if (image.valid())
        {
            osg::Geode* geode = osg::createGeodeForImage(image.get());

            if (image->isImageTranslucent())
            {
                osg::notify()<<"Image "<<image->getFileName()<<" is translucent; setting up blending."<<std::endl;
                geode->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
                geode->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
            }

            nodeList.push_back(geode);
        }
    }

    while (arguments.read("--movie",filename))
    {
        osg::ref_ptr<osg::Image> image = readImageFile(filename.c_str(), options);
        osg::ref_ptr<osg::ImageStream> imageStream = dynamic_cast<osg::ImageStream*>(image.get());
        if (imageStream.valid())
        {
            // start the stream playing.
            imageStream->play();

            osg::ref_ptr<osg::Geometry> pictureQuad = 0;

            bool useTextureRectangle = true;
            if (useTextureRectangle)
            {
                pictureQuad = osg::createTexturedQuadGeometry(osg::Vec3(0.0f,0.0f,0.0f),
                                                   osg::Vec3(image->s(),0.0f,0.0f),
                                                   osg::Vec3(0.0f,0.0f,image->t()),
                                                   0.0f,image->t(), image->s(),0.0f);

                pictureQuad->getOrCreateStateSet()->setTextureAttributeAndModes(0,
                            new osg::TextureRectangle(image.get()),
                            osg::StateAttribute::ON);
            }
            else
            {
                pictureQuad = osg::createTexturedQuadGeometry(osg::Vec3(0.0f,0.0f,0.0f),
                                                   osg::Vec3(image->s(),0.0f,0.0f),
                                                   osg::Vec3(0.0f,0.0f,image->t()),
                                                   0.0f,0.0f, 1.0f,1.0f);

                pictureQuad->getOrCreateStateSet()->setTextureAttributeAndModes(0,
                            new osg::Texture2D(image.get()),
                            osg::StateAttribute::ON);
            }

            if (pictureQuad.valid())
            {
                osg::ref_ptr<osg::Geode> geode = new osg::Geode;
                geode->addDrawable(pictureQuad.get());
                nodeList.push_back(geode.get());

            }
        }
        else if (image.valid())
        {
            nodeList.push_back(osg::createGeodeForImage(image.get()));
        }
    }

    while (arguments.read("--dem",filename))
    {
        osg::HeightField* hf = readHeightFieldFile(filename.c_str(), options);
        if (hf)
        {
            osg::Geode* geode = new osg::Geode;
            geode->addDrawable(new osg::ShapeDrawable(hf));
            nodeList.push_back(geode);
        }
    }