Hi Carsten, thanks a lot, I have it working now. Actually, read back has been the problem. In "OSGRenderBuffer.cpp", it uses "pImg->getPixelFormat()" as the format, (which should be GL_DEPTH_COMPONENT for the depth buffer)
" void RenderBuffer::processPreDeactivate (DrawEnv *pEnv, UInt32 index) { if(_sfReadBack.getValue() == true) { Image *pImg = this->getImage(); if(pImg == NULL) return; if(pImg->getData() == NULL) { SINFO << "TextureBuffer::render: (Re)Allocating image " << "for read-back." << endLog; pImg->set(pImg->getPixelFormat(), pImg->getWidth (), pImg->getHeight (), pImg->getDepth (), pImg->getMipMapCount(), pImg->getFrameCount (), pImg->getFrameDelay (), NULL, pImg->getDataType (), true, pImg->getSideCount () ); } // select GL_COLORATTACHMENTn and read data into image #ifndef OSG_OGL_ES2 glReadBuffer(index); #endif glReadPixels(0, 0, pImg->getWidth (), pImg->getHeight (), pImg->getPixelFormat(), pImg->getDataType (), pImg->editData ()); #ifndef OSG_OGL_ES2 glReadBuffer(GL_NONE); #endif glErr("renderbuffer:predeactivate"); } } " Can you please consider adding a format GL_DEPTH_COMPONENT to "OSGImage.cpp" ? "OSGImage.cpp", line 110: { GL_DEPTH_COMPONENT, 1 }, With this addition, it works with RenderBuffer and TextureBuffer as well. Best regards, Christoph On 29.06.2012 16:05, Carsten Neumann wrote: > 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 > Opensg-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/opensg-users > ------------------------------------------------------------------------------ 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 Opensg-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensg-users