Beispiel #1
0
osg::Node* creatQuad(const std::string& name, 
                     osg::Image* image, 
                     osg::Texture::InternalFormatMode formatMode,
                     osg::Texture::FilterMode minFilter)
{

    osg::Group* group = new osg::Group;
    
    {
        osg::Geode* geode = new osg::Geode;

        geode->addDrawable(createTexturedQuadGeometry(
                osg::Vec3(0.0f,0.0f,0.0f),
                osg::Vec3(float(image->s()),0.0f,0.0f),
                osg::Vec3(0.0f,0.0f,float(image->t()))));

        geode->setName(name);

        osg::StateSet* stateset = geode->getOrCreateStateSet();

        osg::Texture2D* texture = new osg::Texture2D(image);
        texture->setInternalFormatMode(formatMode);
        texture->setFilter(osg::Texture::MIN_FILTER, minFilter);
        stateset->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);

        group->addChild(geode);
    }
    
    {
        group->addChild(createHUD(name));
    }
    
    return group;
}
Beispiel #2
0
osg::Geode* createLiveStream(osg::Vec3 pos) {
	enum Mode {IMAGE, MOVIE, LIVE};
    
	osg::ref_ptr<osg::Geode> geode = new osg::Geode;
    
#ifdef WIN32
	osgDB::Registry::instance()->getDataFilePathList().push_back("C:/Users/stephan");
	//osgDB::Registry::instance()->getDataFilePathList().push_back("C:/Dokumente und Einstellungen/stephan.WINTEILCHEN/Eigene Dateien/cefix/cefix/tests/Quicktime");
	
#endif
    std::string fileName = "dummy.mov";

    
    int w = 640; 
    int h = 480;
	osg::Image* image = NULL;
	Mode mode = LIVE;

    
    std::vector< osg::ref_ptr<osg::Image> > imageList;
    
	switch (mode){
		case IMAGE:
			imageList.push_back(osgDB::readImageFile("dummy.png"));
			break;

		case MOVIE:
			{
                int maxAllowedMovies = s_max_allowed_movies;
                int currentNdx = 0;
                
				std::string path = osgDB::findDataFile("/Users/stephan/Documents/Projekte/cefix/cefix/tests/Quicktime/movies");
                osgDB::DirectoryContents cnt = osgDB::getDirectoryContents(path);
                for(osgDB::DirectoryContents::iterator itr = cnt.begin(); itr != cnt.end(); itr++) {
                
                    std::string  file =  path + "/" + (*itr);
                    if  (osgDB::getFileExtension(file) == "mov") {
                        currentNdx++;
						std::cout << "reading " << file << std::endl;
                        osg::ref_ptr<osg::ImageStream> is = dynamic_cast<osg::ImageStream*>(osgDB::readImageFile(file));
                        
                        if ((is) && (currentNdx <= maxAllowedMovies)) {
                            
                            is->play();
                            imageList.push_back(is);
                        }
                        
                    }
                }
				
				
				// test http-streaming
				if (0) {
					osg::setNotifyLevel(osg::DEBUG_INFO);
					// http://digitalmind.de/sites/digitalmind.de/files/livefeedbackSchnappschuss001.mp4
					osg::ref_ptr<osg::ImageStream> is = dynamic_cast<osg::ImageStream*>(osgDB::readImageFile("http://digitalmind.de/sites/digitalmind.de/files/livefeedbackSchnappschuss001.mp4"));
					osg::setNotifyLevel(osg::NOTICE);
					if ((is) && (currentNdx <= maxAllowedMovies)) {
						is->play();
						imageList.push_back(is);
					}

				}
            }
			break;

		case LIVE:
			{
                const cefix::SequenceGrabberDeviceInfoList& devices = cefix::SequenceGrabberManager::instance()->getDeviceInfoList();
                for(cefix::SequenceGrabberDeviceInfoList::const_iterator i = devices.begin(); i != devices.end(); ++i) {
                    std::cout << (*i).getGrabberId() << "/" << (*i).getId() << std::endl;
                }
				cefix::SequenceGrabber* sq = cefix::SequenceGrabberManager::instance()->get(devices[0].getKey(), 160,120);
				sq->showSettings();
                sq->start();
				imageList.push_back(sq->getImage());
				if (devices.size() > 1) {
					cefix::SequenceGrabber* sq2 = cefix::SequenceGrabberManager::instance()->get(devices[1], 160,120);
					sq2->start();
					imageList.push_back(sq2->getImage());
				}

			}
			break;
	}
	if (imageList.size() == 0) {
		//osg::notify(osg::ALWAYS) << "could not load image/movie" << std::endl;
		return geode;
	}
	
	if (0) {// Image kopieren
		osg::Image* copyimage = new osg::Image(*(imageList[0].get()), osg::CopyOp::DEEP_COPY_ALL);
		copyimage->setFileName("");
		imageList.push_back(copyimage);
	}
    w = imageList[0]->s();
    h = imageList[0]->t();
    
    int maxImages = imageList.size() ;
    int max = (maxImages > 10) ? maxImages : 10;
    for (int y = 0; y < 4; y++) {
        for (int x = 0; x < 4; x++) {
            pos = osg::Vec3((x-5) * (w+10), 0, (y-5) * (h+10));
            osg::ref_ptr<osg::Geometry> g;
            image = imageList[(x % maxImages)].get();
            g = createTexturedQuadGeometry(pos,image->s(),image->t(),image); 
			
			//g->setUseDisplayList(false);
            geode->addDrawable(g);
        }
    }
    
    osg::StateSet* state = geode->getOrCreateStateSet();
    
    state->setMode(GL_BLEND,osg::StateAttribute::ON);
    state->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
    state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
    
    osg::Depth* depth = new osg::Depth();
    depth->setWriteMask(false);
    state->setAttribute(depth);
    
    osg::BlendFunc* b = new osg::BlendFunc();
    b->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
    state->setAttribute(b);
	
	return geode.release();
}