Hi,
I'm still moving from 1.8 to 2.0. We have reached a reasonable state but there are still some open issues. Currently I'm to port our height map generation code.
The plan was to use a FBO with RenderBuffer for depth information attached. This is my current code:
// create result image
OSG::ImageUnrecPtr result = OSG::Image::create();
result->set(OSG::Image::OSG_DEPTH_PF, 512, 512, 1, 1, 1, 0.0f, NULL, OSG::Image::OSG_FLOAT32_IMAGEDATA);
OSG::ImageUnrecPtr result = OSG::Image::create();
result->set(OSG::Image::OSG_DEPTH_PF, 512, 512, 1, 1, 1, 0.0f, NULL, OSG::Image::OSG_FLOAT32_IMAGEDATA);
// create camera beacon and transformation
OSG::NodeUnrecPtr camBeacon;
camBeacon = Node::create();
ComponentTransformUnrecPtr camTransform = ComponentTransform::create();
camBeacon->setCore(camTransform);
OSG::NodeUnrecPtr camBeacon;
camBeacon = Node::create();
ComponentTransformUnrecPtr camTransform = ComponentTransform::create();
camBeacon->setCore(camTransform);
// create orthographic camera
OSG::OrthographicCameraUnrecPtr ocam;
ocam = OSG::OrthographicCamera::create();
ocam->setBeacon(camBeacon);
ocam->setNear(0.0f);
ocam->setFar(volumeMax.z() - volumeMin.z());
ocam->setHorizontalSize(volumeMax.x() - volumeMin.x());
ocam->setVerticalSize(volumeMax.y() - volumeMin.y());
ocam->setAspect(volAspect);
OSG::OrthographicCameraUnrecPtr ocam;
ocam = OSG::OrthographicCamera::create();
ocam->setBeacon(camBeacon);
ocam->setNear(0.0f);
ocam->setFar(volumeMax.z() - volumeMin.z());
ocam->setHorizontalSize(volumeMax.x() - volumeMin.x());
ocam->setVerticalSize(volumeMax.y() - volumeMin.y());
ocam->setAspect(volAspect);
ImageUnrecPtr dummy = Image::create();
dummy->set(Image::OSG_RGBA_PF, 512, 512, 1, 1, 1, 0.0f, NULL, OSG::Image::OSG_UINT8_IMAGEDATA, true);
OSG::TextureObjChunkUnrecPtr fboTextureObj;
fboTextureObj = TextureObjChunk::create();
fboTextureObj->setMinFilter(GL_LINEAR);
fboTextureObj->setMagFilter(GL_LINEAR);
fboTextureObj->setWrapS(GL_CLAMP);
fboTextureObj->setWrapT(GL_CLAMP);
fboTextureObj->setTarget(GL_TEXTURE_2D);
fboTextureObj->setImage(dummy);
OSG::TextureBufferUnrecPtr texBuf = OSG::TextureBuffer::create();
texBuf->setTexture(fboTextureObj);
//texBuf->setReadBack(true);
dummy->set(Image::OSG_RGBA_PF, 512, 512, 1, 1, 1, 0.0f, NULL, OSG::Image::OSG_UINT8_IMAGEDATA, true);
OSG::TextureObjChunkUnrecPtr fboTextureObj;
fboTextureObj = TextureObjChunk::create();
fboTextureObj->setMinFilter(GL_LINEAR);
fboTextureObj->setMagFilter(GL_LINEAR);
fboTextureObj->setWrapS(GL_CLAMP);
fboTextureObj->setWrapT(GL_CLAMP);
fboTextureObj->setTarget(GL_TEXTURE_2D);
fboTextureObj->setImage(dummy);
OSG::TextureBufferUnrecPtr texBuf = OSG::TextureBuffer::create();
texBuf->setTexture(fboTextureObj);
//texBuf->setReadBack(true);
OSG::TextureObjChunkUnrecPtr fboDepthTexture;
fboDepthTexture = TextureObjChunk::create();
fboDepthTexture->setInternalFormat(GL_DEPTH_COMPONENT24);
fboDepthTexture->setExternalFormat(GL_DEPTH_COMPONENT);
fboDepthTexture->setMinFilter(GL_LINEAR);
fboDepthTexture->setMagFilter(GL_LINEAR);
fboDepthTexture->setWrapS(GL_CLAMP_TO_EDGE);
fboDepthTexture->setWrapT(GL_CLAMP_TO_EDGE);
fboDepthTexture->setTarget(GL_TEXTURE_2D);
fboDepthTexture->setImage(result);
TextureBufferUnrecPtr depthBuf = TextureBuffer::create();
depthBuf->setTexture(fboDepthTexture);
depthBuf->setReadBack(true);
// create fbo
OSG::FrameBufferObjectUnrecPtr fbo = OSG::FrameBufferObject::create();
fbo->setSize(512, 512);
//fbo->setColorAttachment(texBuf, 0);
fbo->setDepthAttachment(depthBuf);
//fbo->editMFDrawBuffers()->clear();
//fbo->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT);
fbo->setPostProcessOnDeactivate(true);
OSG::VisitSubTreeUnrecPtr fboStageSubTreeVisit = OSG::VisitSubTree::create();
OSG::NodeUnrecPtr pVisitNode = OSG::Node::create();
pVisitNode->setCore(fboStageSubTreeVisit);
OSG::NodeUnrecPtr pVisitNode = OSG::Node::create();
pVisitNode->setCore(fboStageSubTreeVisit);
OSG::StageUnrecPtr pStage = OSG::Stage::create();
pStage->setRenderTarget(fbo);
pStage->setRenderTarget(fbo);
OSG::NodeUnrecPtr fboStageNode = OSG::Node::create();
fboStageNode->setCore(pStage);
fboStageNode->addChild(pVisitNode);
fboStageNode->setCore(pStage);
fboStageNode->addChild(pVisitNode);
OSG::ViewportUnrecPtr fboViewport;
fboViewport = OSG::Viewport::create();
fboViewport->setSize(0, 0, 1, 1);
fboViewport->setBackground(bg));
fboViewport->setCamera(ocam);
fboViewport->setRoot(fboStageNode);
fboViewport = OSG::Viewport::create();
fboViewport->setSize(0, 0, 1, 1);
fboViewport->setBackground(bg));
fboViewport->setCamera(ocam);
fboViewport->setRoot(fboStageNode);
OSG::PassiveWindowUnrecPtr pWin;
pWin = OSG::PassiveWindow::create();
pWin->setSize(512, 512);
pWin->init();
pWin->addPort(fboViewport);
pWin = OSG::PassiveWindow::create();
pWin->setSize(512, 512);
pWin->init();
pWin->addPort(fboViewport);
OSG::RenderActionRefPtr ract = OSG::RenderAction::create();
pWin->render(ract);
There are 2 things that I could discover:
1.) I don't get any result :-(
2.) And more significant, after the one attempt, my main rendering seems to be broken. It starts flickered .. only every second image is rendered correctly, the others remain black!
Do you have any idea what may went wrong?
Thanks in advance!
Michael
------------------------------------------------------------------------------ Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. Written by three acclaimed leaders in the field, this first edition is now available. Download your free book today! http://p.sf.net/sfu/NeoTech
_______________________________________________ Opensg-users mailing list Opensg-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensg-users