Hi,
Are you recreating the texture so that it fits the new view size? Are
you modifying the RTT camera viewport?
Above is however not needed when using FBO RTT, the texture size can
stay the same no matter what the final view window size is, unless you
want to match it pixel for pixel.
I double checked it with your original app. You only had:
camera_RTT->setViewport(0,0,screenWidth,screenHeight);
missing, then the FBO path works fine.
I also attach code that worked for me.
Any specific reason for not using FBO?
jp
On 07/07/11 13:14, Alessandro Terenzi wrote:
Thanks JP,
after having searched the archives, I tried to create a cull callback and in
its operator() method I tried different things among adding these lines:
Code:
cv->getCurrentRenderBin()->getStage()->setCameraRequiresSetUp(true);
cv->getCurrentRenderBin()->getStage()->runCameraSetUp(cv->getRenderInfo());
But this seems to be not enough.
I also tried to detach the COLOR_BUFFER and attach it again along with the RTT
texture, but still same issue.
I do not understand what happens behind the scenes, so I still cannot think
about what else to try...any hint about the workaround you were talking about?
:)
Cheers.
Alessandro
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=41234#41234
_______________________________________________
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.
#include <osgDB/ReadFile>
#include <osgUtil/Optimizer>
#include <osg/CoordinateSystemNode>
#include <osg/Switch>
#include <osgText/Text>
#include <osgViewer/CompositeViewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgGA/KeySwitchMatrixManipulator>
#include <osgGA/StateSetManipulator>
#include <osgGA/AnimationPathManipulator>
#include <osgGA/TerrainManipulator>
#include <iostream>
int main( int argc, char **argv )
{
osg::ArgumentParser arguments(&argc,argv);
osgViewer::Viewer viewer(arguments);
// add stats and window size handlers...
viewer.addEventHandler( new osgViewer::StatsHandler() );
viewer.addEventHandler( new osgViewer::WindowSizeHandler() );
int screenWidth = 1366;
int screenHeight = 768;
// create the texture to render to...
osg::ref_ptr<osg::Texture2D> texture_RTT = new osg::Texture2D;
texture_RTT->setTextureSize(screenWidth, screenHeight);
texture_RTT->setInternalFormat(GL_RGBA);
texture_RTT->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
texture_RTT->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
texture_RTT->setResizeNonPowerOfTwoHint(false);
// create the quad...
osg::ref_ptr<osg::Geometry> quad_RTT = osg::createTexturedQuadGeometry(
osg::Vec3(0.0, 0.0, 0.0),
osg::Vec3(screenWidth, 0.0, 0.0),
osg::Vec3(0.0, screenHeight, 0.0));
quad_RTT->setDataVariance( osg::Object::DYNAMIC );
osg::ref_ptr<osg::Geode> quad_geode_RTT = new osg::Geode;
quad_geode_RTT->addDrawable(quad_RTT.get());
quad_geode_RTT->setDataVariance( osg::Object::DYNAMIC );
osg::StateSet *quadState = quad_geode_RTT->getOrCreateStateSet();
quadState->setTextureAttributeAndModes(0, texture_RTT.get(), osg::StateAttribute::ON);
quadState->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
// create the camera...
osg::ref_ptr<osg::Camera> camera_RTT = new osg::Camera;
#ifdef USE_IMAGE
osg::ref_ptr<osg::Image> image_RTT = new osg::Image;
image_RTT->allocateImage(screenWidth, screenHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE);
camera_RTT->attach(osg::Camera::COLOR_BUFFER, image_RTT.get());
texture_RTT->setImage(0, image_RTT.get());
#else
camera_RTT->attach(osg::Camera::COLOR_BUFFER, texture_RTT.get());
#endif
camera_RTT->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
//camera_RTT->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER);
camera_RTT->setRenderOrder(osg::Camera::PRE_RENDER);
camera_RTT->setReferenceFrame( osg::Camera::ABSOLUTE_RF );
camera_RTT->setClearColor( osg::Vec4( 0., 0., 1., 1. ) );
camera_RTT->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// add whatever children you want drawn to the texture
osg::ref_ptr< osg::Node > node = osgDB::readNodeFile("cow.osg");
if(node.valid())
{
const osg::BoundingSphere& bs = node->getBound();
float znear = 1.0f*bs.radius();
float zfar = 3.0f*bs.radius();
float proj_top = 0.25f*znear;
float proj_right = 0.5f*znear;
znear *= 0.9f;
zfar *= 1.1f;
camera_RTT->setProjectionMatrixAsFrustum(-proj_right,proj_right,-proj_top,proj_top,znear,zfar);
camera_RTT->setViewMatrixAsLookAt(bs.center()-osg::Vec3(0.0f,2.0f,0.0f)*bs.radius(),bs.center(),osg::Vec3(0.0f,0.0f,1.0f));
camera_RTT->addChild(node.get());
camera_RTT->setViewport(0,0,screenWidth,screenHeight);
}
else
osg::notify(osg::FATAL)<<"model not loaded"<<std::endl;
// add camera and quad to root...
osg::Group* rootNode = new osg::Group();
rootNode->addChild(camera_RTT.get());
rootNode->addChild(quad_geode_RTT.get());
// add model to the viewer.
viewer.setSceneData( rootNode );
return viewer.run();
}
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org