title: Updating Textures on Runtime in OpenSceneGraph
body: <p>I am working on a project in which I am required to capture frames from external device video and render them on openSceneGraph Node. I am also using GLSL shaders. But I don't know how to update textures on runtime. For other uniforms we need to make callbacks but do we also need to make callbacks for samplers in glsl and openSceneGraph ?</p>
  
  <p>My code looks like this. All I am getting right now is a black window.</p>
  
  <pre class="lang-c++ prettyprint-override"><code>osg::ref_ptr&lt;osg::Geometry&gt; pictureQuad = osg::createTexturedQuadGeometry(osg::Vec3(0.0f,0.0f,0.0f),
      osg::Vec3(_deviceNameToImageFrameMap[deviceName].frame-&gt;s(),0.0f,0.0f), osg::Vec3(0.0f,0.0f,_deviceNameToImageFrameMap[deviceName].frame-&gt;t()),
      0.0f, 1.0f,_deviceNameToImageFrameMap[deviceName].frame-&gt;s(), _deviceNameToImageFrameMap[deviceName].frame-&gt;t()); 
  
      //creating texture and setting up parameters for video frame
      osg::ref_ptr&lt;osg::TextureRectangle&gt; myTex= new osg::TextureRectangle(_deviceNameToImageFrameMap[deviceName].frame.get());
      myTex-&gt;setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
      myTex-&gt;setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
      myTex-&gt;setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
      myTex-&gt;setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
  
  
  
      _videoSourceNameToNodeMap[sourceName].geode = new osg::Geode();
      _videoSourceNameToNodeMap[sourceName].geode-&gt;setDataVariance(osg::Object::DYNAMIC);
      _videoSourceNameToNodeMap[sourceName].geode-&gt;addDrawable(pictureQuad.get());
  
      //apply texture to node
      _videoSourceNameToNodeMap[sourceName].geode-&gt;getOrCreateStateSet()-&gt;setTextureAttributeAndModes(0, myTex.get(), osg::StateAttribute::ON);
      _videoSourceNameToNodeMap[sourceName].geode-&gt;getOrCreateStateSet()-&gt;setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
      _videoSourceNameToNodeMap[sourceName].geode-&gt;setDataVariance(osg::Object::DYNAMIC);
  
      //Set uniform sampler
      osg::Uniform* srcFrame   = new osg::Uniform( osg::Uniform::SAMPLER_2D, "srcFrame" );
      srcFrame-&gt;set(0);
      //Set Uniform Alpha
      osg::Uniform* alpha   = new osg::Uniform( osg::Uniform::FLOAT, "alpha" );
      alpha-&gt;set(.5f);
      alpha-&gt;setUpdateCallback(new ExampleCallback());
  
      //Enable blending
      _videoSourceNameToNodeMap[sourceName].geode-&gt;getOrCreateStateSet()-&gt;setMode( GL_BLEND, osg::StateAttribute::ON);
      //Adding blend function to node
      osg::BlendFunc *bf = new osg::BlendFunc();
      bf-&gt;setFunction(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      _videoSourceNameToNodeMap[sourceName].geode-&gt;getOrCreateStateSet()-&gt;setAttributeAndModes(bf);
  
      //apply shader to quad
      _videoSourceNameToNodeMap[sourceName].geode-&gt;getOrCreateStateSet()-&gt;setAttributeAndModes(program, osg::StateAttribute::ON);
      //add Uniform to shader
      _videoSourceNameToNodeMap[sourceName].geode-&gt;getOrCreateStateSet()-&gt;addUniform( srcFrame );
      _videoSourceNameToNodeMap[sourceName].geode-&gt;getOrCreateStateSet()-&gt;addUniform( alpha );
  </code></pre>