Hi,

On 03/01/2012 23:39, wang shuiying wrote:
Hello,

(1)to J.P.

the related source code is as following:

// camera and image setup
osg::Camera::RenderTargetImplementation renderTargetImplementation;
renderTargetImplementation = osg::CameraNode::FRAME_BUFFER;

^ If you want FBO, you probably want FRAME_BUFFER_OBJECT here.


osg::Program * program = new osg::Program();
program->addShader(osg::Shader::readShaderFile(osg::Shader::FRAGMENT, 
fragmentShaderPath));
program->addShader(osg::Shader::readShaderFile(osg::Shader::VERTEX, 
vertexShaderPath));

osg::Image * image = new osg::Image();
image->allocateImage((int)XRes, (int)YRes, 1, GL_RGBA, GL_FLOAT);

osg::ref_ptr<osg::CameraNode>  camera(new osg::CameraNode());
camera->setClearColor(osg::Vec4(1000.0f, 1000.0f, 1000.0f, 1000.0f));
camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
camera->setRenderOrder(osg::CameraNode::PRE_RENDER);
camera->setRenderTargetImplementation(renderTargetImplementation);
camera->attach(osg::CameraNode::COLOR_BUFFER, image);

OpenGL would happily convert from one render target pixel format on the GPU to another one on the CPU when transferring data. So you must make sure that the formats are what you expect. The easiest way is to attach both a texture and an osg::Image to the camera and explicitly set the internal texture format and data type. See the osgprerender example. You can also inspect the code in RenderStage::runCameraSetUp to see exactly how OSG determines the format of the render target.

Also, if you want values outside of [0.0, 1.0] you must attach to osg::CameraNode::COLOR_BUFFER0 and use gl_FragData in your shaders.

camera->getOrCreateStateSet()->setAttribute(program, osg::StateAttribute::ON);

// access data  (only for instance)
osg::Vec4f * fragments = (osg::Vec4f *)(image->data());
osg::Vec4f  color= distances[10];
float color_a= distances[3];

As can be seen from the source code, I attach an image to the camera, and 
access data from the image,
I am rendering to an FBO.

I don't think you are rendering to an FBO with the above code.


So would you please give me some advice further?

Thank you very much!


*(2) to Paul*

Refer to (1) of this message, does  osg::CameraNode::COLOR_BUFFER imply a RGB  
or  RGBA buffer
? or it doesn't even matter?

It does not imply anything.

rgds
jp


Thank you very much !

Shuiying




_______________________________________________
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.

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

Reply via email to