Hi,

I am using a texture chunk in the same PolygonForeground field container,
which is rendered to by an FBO (same as in fboxtexture.cpp).
Now, I do not get anything in the non-aspect-0 windows. Colored rendering
works just fine.
How to use FBOs rendering to a texture with several aspects?

Thanks again,
Christoph
 

OSG::ForegroundUnrecPtr createFBOTex (OSG::Node*  root,
                                                                        
OSG::NodeUnrecPtr& stageN)
{
   // create FBO
   // Background
   OSG::SolidBackgroundUnrecPtr bg = OSG::SolidBackground::create();
   bg->setColor(OSG::Color3f(0.0,0.0,0.0));
   
   // Begin by setting up an FBO with a TextureBuffer, so we can capture
   // and reuse what is being rendered to the FBO.
   OSG::ImageRefPtr           fboTexImg = OSG::Image            ::create();
   fboTexImg->set(OSG::Image::OSG_RGB_PF, 1920, 1200);
   fboTex    = OSG::TextureObjChunk  ::create();
   fboTex->setImage(fboTexImg);  
   fboTex->setMinFilter(GL_LINEAR);
   fboTex->setMagFilter(GL_LINEAR);
   fboTex->setWrapS    (GL_CLAMP );
   fboTex->setWrapT    (GL_CLAMP );

   OSG::FrameBufferObjectRefPtr fbo       = OSG::FrameBufferObject::create();
   OSG::TextureBufferRefPtr     texBuf    = OSG::TextureBuffer    ::create();
   OSG::RenderBufferRefPtr      depthBuf  = OSG::RenderBuffer     ::create();
   // ... and add it to the texture buffer
   texBuf->setTexture(fboTex);   
   // add a depth attachment, otherwise there is no depth buffer when rendering 
to the FBO
   depthBuf->setInternalFormat(GL_DEPTH_COMPONENT24);   
   // make the fbo render to the texture
   fbo->setColorAttachment(texBuf,   0);
   fbo->setDepthAttachment(depthBuf   );
   fbo->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT);
   fbo->setWidth (1920);
   fbo->setHeight(1200);
   // mipmaps
   fbo->setPostProcessOnDeactivate(false);

   // Next we set up a Stage, which renders the subtree below it to its render 
target (the FBO from above).
   OSG::SimpleStageRefPtr stage  = OSG::SimpleStage::create();
   stageN = OSG::makeNodeFor(stage);
   stageN->addChild(root);   
   // make the stage render to the FBO instead of the normal framebuffer
   stage->setRenderTarget(fbo);   
   // use the full size of the target (this is like setting up the viewport of 
the stage)
   stage->setSize(0.0f, 0.0f, 1.0f, 1.0f);
   stage->setBackground(bg);
   stage->setCamera(m_cam);

   // create polygon foreground   
   OSG::TextureEnvChunkUnrecPtr fboTexEnv = OSG::TextureEnvChunk::create();
   fboTexEnv->setEnvMode  (GL_REPLACE);
  
   OSG::SimpleMaterialUnrecPtr mat = OSG::SimpleMaterial::create();   
   mat->setDiffuse(OSG::Color3f(1,1,1));
   mat->setLit    (false);
   mat->addChunk  (fboTex);
   mat->addChunk  (fboTexEnv);

   OSG::PolygonForegroundUnrecPtr
   fgPolygon = OSG::PolygonForeground::create();
   fgPolygon->setMaterial  (mat);
   OSG::MFPnt2f* pPos = fgPolygon->editMFPositions();
   OSG::MFVec3f* pTex = fgPolygon->editMFTexCoords();
   pPos->push_back(OSG::Pnt2f(0.0f, 0.0f));
   pPos->push_back(OSG::Pnt2f(1.0f, 0.0f));
   pPos->push_back(OSG::Pnt2f(1.0f, 1.0f));
   pPos->push_back(OSG::Pnt2f(0.0f, 1.0f));
  
   pTex->push_back(OSG::Vec3f(0.0f, 0.0f, 0.0f));
   pTex->push_back(OSG::Vec3f(1.0f, 0.0f, 0.0f));
   pTex->push_back(OSG::Vec3f(1.0f, 1.0f, 0.0f));
   pTex->push_back(OSG::Vec3f(0.0f, 1.0f, 0.0f));
   return fgPolygon;
}

-- 
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to