Hi,

On 18/04/11 08:26, sun qi wrote:
Hi,all

I was trying to save a render-to-texture image file many ways, however, failed 
each time.
when i attach texture to camera.it works fine.
but i attach image to camera. it doesn't work right.
I saved the image data to .jpg, .png, .bmp format . but when i double-click the 
saved image file, there's nothing but blank.and when i tried do the same thing 
in the osg example osgprerender, the problem was still that.  i use
osgDB::writeImageFile(*image, "d:\\data\\test.bmp");
  why? Is there someone met this problem? How did you fix it?

[code]
osg::ref_ptr<osg::Texture2D>  colorMap = new osg::Texture2D;
colorMap->setTextureSize(width, height);
colorMap->setInternalFormat(GL_RGBA);
colorMap->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
colorMap->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);

osg::ref_ptr<osg::Texture2D>  depthMap = new osg::Texture2D;
depthMap->setTextureSize(width,height);
depthMap->setInternalFormat(GL_DEPTH_COMPONENT);
depthMap->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
depthMap->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);

osg::ref_ptr<osg::Camera>  camera = new osg::Camera;
camera->setClearColor(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
camera->setReferenceFrame(osg::Transform::RELATIVE_RF);
camera->setProjectionMatrixAsFrustum(-proj_right, proj_right, -proj_top, 
proj_top, znear, zfar);
//camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera->setProjectionMatrix(osg::Matrixd::identity());
camera->setViewMatrixAsLookAt(bs.center()-osg::Vec3(0.0f,2.0f,0.0f)*bs.radius(),bs.center(),osg::Vec3(0.0f,0.0f,1.0f));
camera->setViewMatrix(osg::Matrixd::identity());
camera->setViewport(0, 0, width, height);
camera->setRenderOrder(osg::Camera::PRE_RENDER);
camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
camera->attach(osg::Camera::DEPTH_BUFFER, depthMap);
camera->attach(osg::Camera::COLOR_BUFFER, colorMap);
osg::ref_ptr<osg::Image>  image = new osg::Image;
image->allocateImage(width, height, 1, GL_RGBA, GL_FLOAT);

Not many image writers support float output, try GL_UNSIGNED_CHAR instead of GL_FLOAT here.

Also, try write the image out in the Camera callback.

jp


image->setInternalTextureFormat(GL_RGBA);
camera->attach(osg::Camera::COLOR_BUFFER, image.get());
osg::ref_ptr<osg::Geode>  geo = createCube(colorMap, depthMap);
camera->addChild(modelNode.get());
osg::ref_ptr<osg::Group>  parent = new osg::Group;
parent->addChild(geo.get());
parent->addChild(camera.get());
osgDB::writeImageFile(*image, "test.bmp");
//colorMap->setImage(0, image);
return parent.get();
[/code]
...

Thank you!

Cheers,
sun

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=38548#38548





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks Transtec Computers for their support.

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to