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

