Hello Christoph,
On 06/29/2012 08:01 AM, "Christoph Fünfzig" wrote:
> I would like to render a depth image via FBO with a
> current OpenSG 2.0.
> Quite a common operation, so can someone post a code fragment for it perhaps?
the TrapezoidalShadowMapEngine (in Contrib/TrapezoidalShadowMaps) does this:
TSMEngineData *data;
TextureObjChunk *bufTex = data->getShadowTexChunk();
if(bufTex == NULL)
{
TextureObjChunkUnrecPtr newBufTex = TextureObjChunk::createLocal();
newBufTex->setMinFilter (GL_LINEAR );
newBufTex->setMagFilter (GL_LINEAR );
newBufTex->setWrapS (GL_CLAMP_TO_EDGE );
newBufTex->setWrapT (GL_CLAMP_TO_EDGE );
newBufTex->setWrapR (GL_CLAMP_TO_EDGE );
newBufTex->setScale (false );
newBufTex->setInternalFormat(GL_DEPTH_COMPONENT24 );
newBufTex->setExternalFormat(GL_DEPTH_COMPONENT );
newBufTex->setCompareMode (GL_COMPARE_R_TO_TEXTURE);
newBufTex->setCompareFunc (GL_LESS );
newBufTex->setDepthMode (GL_LUMINANCE );
data->setShadowTexChunk(newBufTex);
this->setShadowTexChunk(newBufTex);
}
Image *bufImg = data->getShadowTexImage();
if(bufImg == NULL)
{
ImageUnrecPtr newBufImg = Image::createLocal();
newBufImg->set(Image::OSG_L_PF,
this->getWidth (),
this->getHeight(),
1,
1,
1,
0.,
NULL,
Image::OSG_UINT8_IMAGEDATA,
false,
1);
bufTex->setImage (newBufImg);
data ->setShadowTexImage(newBufImg);
bufImg = newBufImg;
}
TextureObjChunk *bufTex = data->getShadowTexChunk();
if(data->getMFShadowTexBuffers()->empty() == true)
{
TextureBufferUnrecPtr newBuf = TextureBuffer::createLocal();
newBuf->setTexture (bufTex );
newBuf->setTexTarget(GL_TEXTURE_2D);
data->editMFShadowTexBuffers()->push_back(newBuf);
}
if(data->getMFRenderTargets()->empty() == true)
{
FrameBufferObjectUnrecPtr newTarget =
FrameBufferObject::createLocal();
newTarget->setWidth (this->getWidth ( ));
newTarget->setHeight (this->getHeight ( ));
newTarget->setDepthAttachment(data->getShadowTexBuffers(0));
data->editMFRenderTargets()->push_back(newTarget);
}
Please note that here the texture is not copied back to main memory (for
that you need to enable readback and post processing on the
TextureBuffer and FBO respectively - as your code does).
Hope it helps,
Carsten
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users