Hello Dan,

On 08/27/10 04:27, Dan Koschier wrote:
> I try to render an image into a texture using a FrameBufferObject. I
> used the code of the /Examples/Simple/fbotexture.cpp example, but I
> don't understand how to render the created SimpleStage.
>
> Here is my code:
>
>      OSG::ImageRefPtr fboTexImg = OSG::Image::create();
>      OSG::TextureObjChunkRefPtr fboTex = OSG::TextureObjChunk::create();
>
>      OSG::FrameBufferObjectRefPtr fbo = OSG::FrameBufferObject::create();
>      OSG::TextureBufferRefPtr texBuf = OSG::TextureBuffer::create();
>
>      // set up the texture ...
>      fboTexImg->set(OSG::Image::OSG_RGB_PF, maxWidth, maxHeight);
>      fboTex->setImage(fboTexImg);
>
>      // ... and add it to the texture buffer
>      texBuf->setTexture(fboTex);
>      texBuf->setReadBack(true); // ??
                           ^^^^^^
you only need that if you want the texture copied to main memory.

>      // make the fbo render to the texture
>      fbo->setWidth (maxWidth );
>      fbo->setHeight(maxHeight);
>      fbo->setColorAttachment(texBuf,   0);
>      fbo->editMFDrawBuffers()->clear();
>      fbo->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT);
>      fbo->setPostProcessOnDeactivate(true);
                                       ^^^^^^
this enables post processing (like readback) of the attached 
buffers/textures, so you only need it if you need readback.

>      // ... and add a camera
>      OSG::TileCameraDecoratorRefPtr camdec =
> OSG::TileCameraDecorator::create();
>      camdec->setFullSize(ResX, ResY);
>      camdec->setDecoratee(mMgr_->getCamera());
>
>      OSG::SimpleStageRefPtr simpleStage = OSG::SimpleStage::create();
>      simpleStage->setSize( 0, 0, maxWidth, maxHeight );
>      simpleStage->setCamera( camdec );
>
> simpleStage->setBackground(mMgr_->getWindow()->getPort(0)->getBackground());
>      simpleStage->setRenderTarget(fbo);
>
>
> As you see I have the SimpleStage and don't know how to render the whole
> thing. A root node with a scene exists.

the SimpleStage is a NodeCore, so you can create a Node for it and place 
it in the scene. Everything below (i.e. all children of) the Stage will 
be rendered into the FBO instead of the application framebuffer. If you 
want to use the FBO colorbuffer(s) as textures in the scene, make sure 
the stage comes before the scene in the list of children of the root.
Also note that in OpenSG Nodes can have at most one parent, so if the 
scene that uses the FBO texture is the same that is rendered into it, 
you may need a VisitSubTree core to get around that.

        Cheers,
                Carsten

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to