Hi all,
I'm trying to render a height map of some of our 3D scenarios.
So I'm rendering from the top center of the worlds bounding volume using a
orthograhic camera. I thought I could try to use a FBOViewport for that purpose
but until now I get no reasonanble result (the resulting image is empty).
I've attached my source code, maybe someone can have a look?
Best regards,
Michael
--
GMX DSL Doppel-Flat ab 19,99 €/mtl.! Jetzt auch mit
gratis Notebook-Flat! http://portal.gmx.net/de/go/dsl
void test_heightMap_click1(NodePtr root)
{
// get world volume
DynamicVolume vol;
root->getWorldVolume(vol);
// get camera position
Vec3f camPos(
vol.getMin().x() + (vol.getMax().x() - vol.getMin().x())/2.0f,
vol.getMin().y() + (vol.getMax().y() - vol.getMin().y())/2.0f,
vol.getMax().z()
);
// create camera beacon
osg::RefPtr<osg::NodePtr> camBeacon;
camBeacon = Node::create();
ComponentTransformPtr t = ComponentTransform::create();
beginEditCP(t);
t->setTranslation(camPos);
endEditCP(t);
beginEditCP(camBeacon);
camBeacon->setCore(t);
endEditCP(camBeacon);
// create ortho cam
osg::RefPtr<osg::OrthographicCameraPtr> ocam;
ocam = osg::OrthographicCamera::create();
beginEditCP(ocam);
ocam->setBeacon(camBeacon);
ocam->setNear(0.0f);
ocam->setFar(vol.getMax().z() - vol.getMin().z());
ocam->setHorizontalSize(vol.getMax().x() - vol.getMin().x());
ocam->setVerticalSize(vol.getMax().y() - vol.getMin().y());
ocam->setAspect(1.0f);
endEditCP(ocam);
int fboWidth = 100;
int fboHeight = 100;
// create fbo result image
osg::ImagePtr heightMapImg = osg::Image::create();
beginEditCP(heightMapImg);
heightMapImg->set(osg::Image::OSG_I_PF, fboWidth, fboHeight, 1,
1, 1, 0.0, NULL, osg::Image::OSG_FLOAT32_IMAGEDATA);
endEditCP(heightMapImg);
// create fbo texture
osg::TextureChunkPtr fboTexture = osg::TextureChunk::create();
beginEditCP(fboTexture);
fboTexture->setImage(heightMapImg);
fboTexture->setMinFilter(GL_LINEAR);
fboTexture->setMagFilter(GL_LINEAR);
fboTexture->setWrapS(GL_CLAMP);
fboTexture->setWrapT(GL_CLAMP);
fboTexture->setEnvMode(GL_REPLACE);
fboTexture->setTarget(GL_TEXTURE_2D);
fboTexture->setInternalFormat(GL_DEPTH_COMPONENT);
endEditCP(fboTexture);
// create dummy window
osg::PassiveWindowPtr pwin = osg::PassiveWindow::create();
pwin->init();
pwin->resize(fboWidth, fboHeight);
// create fbo viewport
FBOViewportPtr vp = FBOViewport::create();
beginEditCP(vp);
//vp_left->setSize(left, 0.0f, right, 1.0f);
vp->setSize(0.0f, 0.0f, 1.0f, 1.0f);
vp->setStorageWidth(fboWidth);
vp->setStorageHeight(fboHeight);
vp->setBackground(SolidBackground::create());
vp->setCamera(ocam);
vp->setParent(pwin);
vp->setIgnoreCameraDecorators(true);
// attach texture as render target
vp->editMFTextures()->push_back(fboTexture);
vp->setRoot(root);
vp->setFboOn(true);
endEditCP(vp);
// attach fbo to dummy window
beginEditCP(pwin);
pwin->addPort(vp);
endEditCP(pwin);
// create render action
RenderAction* ract = RenderAction::create();
ract->setSortTrans(true);
ract->setZWriteTrans(true);
ract->setLocalLights(true);
ract->setFrustumCulling(false);
ract->setStateSorting(true);
// render
pwin->render(ract);
// write result
heightMapImg->write("C:\\test.png");
}
------------------------------------------------------------------------------
The Next 800 Companies to Lead America's Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book "Blueprint to a
Billion" shares his insights and actions to help propel your
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users