Hi,

can you force single threaded osgviewer and see if it still is a problem?

jp

Engvall Åsa wrote:
Hi!

I want to render the scene to a texture and use the texture in a shader. The texture image is saved to file by a postdraw callback, so I can look at it. I'm doing something wrong because the texture becomes all gray.

My scene graph looks like this:

RTT camera      root
       |                 |
       \                /
        world

The main viewer looks at the root and the shader program is applied to the root stateset. Below is a code snippet.

I would be very grateful if somebody could point out what I'm doing wrong.
Thanks in advance,

Åsa Engvall


// Create a scene texture.
osg::Texture2D* texture = new osg::Texture2D;
texture->setResizeNonPowerOfTwoHint(false);
texture->setTextureSize(traits->width, traits->height);
texture->setInternalFormat(GL_RGBA);
texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST);
texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST);
osg::Image* textureImage = new osg::Image;
textureImage->allocateImage(traits->width, traits->height, 1, GL_RGBA, GL_UNSIGNED_BYTE);
texture->setImage(0, textureImage);

// Add program and uniforms to the root's stateset.
osg::StateSet* state = root->getOrCreateStateSet();
state->addUniform(numberOfTimeStepsU);
state->addUniform(timeConstantU);
state->addUniform(frameTimeU);
state->addUniform(sceneTextureU);
state->addUniform(prevModelViewMatrixU);
state->addUniform(prevModelViewProjectionMatrixU);
state->setAttributeAndModes(motionBlurProgram, osg::StateAttribute::ON);
state->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);

// Create a camera that renders the scene to a texture.
osg::Camera* RTTcamera = new osg::Camera;
RTTcamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); RTTcamera->setClearColor(osg::Vec4(1,1,1,1));
RTTcamera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
RTTcamera->setViewport(0, 0, traits->width, traits->height);
RTTcamera->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR);
RTTcamera->setRenderOrder(osg::Camera::PRE_RENDER);
RTTcamera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
RTTcamera->attach(osg::Camera::COLOR_BUFFER, texture);
RTTcamera->addChild(world);
RTTcamera->attach(osg::Camera::COLOR_BUFFER, textureImage);
RTTcamera->setPostDrawCallback(new ScreenShotCallback(traits->width, traits->height, *textureImage, GL_RGB, GL_UNSIGNED_BYTE));



------------------------------------------------------------------------

_______________________________________________
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