<div dir="ltr"><div><br>Maybe you forgot to add the camera to the main scene graph?<br></div><br>An addChild() into the scene graph root should do the trick.<br><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-04-14 15:16 GMT+02:00 Andreas Schreiber <span dir="ltr"><<a href="mailto:ayss@online.de" target="_blank">ayss@online.de</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi<br>
<br>
<br>
I'm trying to generate a texture with a rtt-camera, so I can use this texture later in my main scene.<br>
To verify if the texture is correct I'm trying to put the texture on a quad in my main scene.<br>
<br>
I use the following method for the rtt-camera, the red clearColor I used to test what the camera renders, but it did not help me out.<br>
<br>
<br>
Code:<br>
osg::Camera *createRTTCamera(osg::Camera::BufferComponent buffer, osg::Texture *tex, bool isAbsolute)<br>
{<br>
osg::ref_ptr<osg::Camera> camera = new osg::Camera;<br>
osg::Vec4f textureStartColor = osg::Vec4f(1.0, 0.0, 0.0, 0.0);<br>
camera->setClearColor(textureStartColor);<br>
camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);<br>
camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);<br>
camera->setRenderOrder(osg::Camera::PRE_RENDER);<br>
<br>
if (tex)<br>
{<br>
tex->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);<br>
tex->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);<br>
camera->setViewport(0, 0, tex->getTextureWidth(), tex->getTextureHeight());<br>
camera->attach(buffer, tex);<br>
}<br>
if (isAbsolute)<br>
{<br>
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);<br>
camera->setProjectionMatrix(osg::Matrix::ortho2D(0.0, 1.0, 0.0, 1.0));<br>
camera->setViewMatrix(osg::Matrix::identity());<br>
osg::Vec3 corner = osg::Vec3();<br>
camera->addChild(createScreenQuad(1.0f, 1.0f, 1, corner));<br>
}<br>
return camera.release();<br>
}<br>
<br>
<br>
<br>
In the main part I do the following:<br>
<br>
1. I initialize the global texture2D variable with an image<br>
<br>
2. Create the rrt camera with color_buffer, the texture (which is global), and 1 for absolute<br>
<br>
3. load geometry<br>
<br>
4. Setup Light, here an example<br>
<br>
Code:<br>
osg::ref_ptr<osg::LightSource> sunLight = new osg::LightSource();<br>
sunLight.get()->setLight(createLightSpot(osg::Vec4(0, 1, 0, 0), osg::Vec4(0, 1, 0, 1)));<br>
sunLight.get()->setReferenceFrame(osg::LightSource::ABSOLUTE_RF);<br>
sunLight.get()->setLocalStateSetModes(osg::StateAttribute::ON);<br>
<br>
<br>
<br>
5. Add the light and the geometry to the rtt camera<br>
6. Add the light and the geometry to the main scene<br>
<br>
Now there should be the scene on the quad geometry which I generated, but this is always rendered with the color of the light and nothing else on it.<br>
It isn't even a mix of the light color and the clear color of the rtt camera, its just the light color.<br>
<br>
Here is my quad generation as well:<br>
<br>
Code:<br>
osg::ref_ptr<osg::Geode> planeRTT = new osg::Geode();<br>
osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry();<br>
planeRTT->addDrawable(geometry);<br>
<br>
osg::ref_ptr<osg::Vec3Array> vertexArray = new osg::Vec3Array();<br>
vertexArray->push_back(osg::Vec3(1, -0.25, -1));<br>
vertexArray->push_back(osg::Vec3(1, 0.75, -1));<br>
vertexArray->push_back(osg::Vec3(1, 0.75, 1));<br>
vertexArray->push_back(osg::Vec3(1, -0.25, 1));<br>
geometry->setVertexArray(vertexArray);<br>
<br>
osg::ref_ptr<osg::Vec4Array> colorArray = new osg::Vec4Array();<br>
colorArray->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));<br>
geometry->setColorArray(colorArray);<br>
geometry->setColorBinding(osg::Geometry::BIND_OVERALL);<br>
<br>
osg::ref_ptr<osg::Vec2Array> texCoordArray = new osg::Vec2Array();<br>
texCoordArray->push_back(osg::Vec2(0.0f, 0.0f));<br>
texCoordArray->push_back(osg::Vec2(1.0f, 0.0f));<br>
texCoordArray->push_back(osg::Vec2(1.0f, 1.0f));<br>
texCoordArray->push_back(osg::Vec2(0.0f, 1.0f));<br>
geometry->setTexCoordArray(0, texCoordArray);<br>
<br>
geometry->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLE_FAN, 0, 4));<br>
<br>
planeRTT.get()->getOrCreateStateSet()->setTextureAttributeAndModes(0, rttTexture.get(), osg::StateAttribute::ON);<br>
<br>
<br>
<br>
Did I miss something or did I mixed up some order?!<br>
Would be grateful for any help!<br>
<br>
...<br>
<br>
Thank you!<br>
<br>
Cheers,<br>
Andreas<br>
<br>
------------------<br>
Read this topic online here:<br>
<a href="http://forum.openscenegraph.org/viewtopic.php?p=63381#63381" target="_blank">http://forum.openscenegraph.org/viewtopic.php?p=63381#63381</a><br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" target="_blank">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
</blockquote></div><br></div>