[osg-users] Background image texture rescaling problem

Robert Osfield robert.osfield at gmail.com
Thu Sep 13 02:08:53 PDT 2007


Hi John,

The rescaling is done on non power of two textures by default,
rescaling is slow op so best avoided.  You have two choices to disable
the resize of the non power of two texture as you have down to move to
using TextureRectangle instead of Texture2D.  If moving to the
TextureRectangle you'll need to move you pixel coords rather than
normal non dimensions texture coords - see osgtexturerectangle
example.

Robert.

On 9/12/07, John Steinbis <jsteinbis at gmail.com> wrote:
> For an AR project, I need to render a model with video image as
> background. My program is based around osgViewer using osg v2.0. I
> found an example for a HUD and with a few changes made it work as
> background. The code can be found below.
>
> The code runs ok but there is a problem occurring that I cannot figure
> out. Any ideas … ?
>
> When new images are loaded, they are rescaled for some reason. This
> adds a noticeable delay, ~250 ms, and distorts the images, which is
> not acceptable. Output looks like "Scaling image 'x' from (720,480) to
> (512,512)".
>
> To prevent resizing I use "BGTexture->setResizeNonPowerOfTwoHint(false)".
> To update an image I use "BGTexture->setImage(newImg)".
>
> Thanks,
> John
>
>
>
> root->addChild(BGProjectionMatrix);
>
> BGProjectionMatrix->setMatrix(osg::Matrix::ortho2D(0,width,0,height));
> BGProjectionMatrix->addChild(BGModelViewMatrix);
>
> BGModelViewMatrix->setMatrix(osg::Matrix::identity());
> BGModelViewMatrix->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
> BGModelViewMatrix->addChild( BGGeode );
>
> BGTexture->setDataVariance(osg::Object::DYNAMIC);
> BGTexture->setResizeNonPowerOfTwoHint(false); // <--
> BGTexture->setImage(BGImage);
>
> BGGeode->addDrawable(BGBackgroundGeometry);
> BGGeode->setStateSet(BGStateSet);
>
> BGBackgroundVertices->push_back( osg::Vec3( 0, 0, 0) );
> BGBackgroundVertices->push_back( osg::Vec3(width, 0, 0) );
> BGBackgroundVertices->push_back( osg::Vec3(width, height, 0) );
> BGBackgroundVertices->push_back( osg::Vec3( 0, height, 0) );
>
> (*texcoords)[0].set(0.0f,0.0f);
> (*texcoords)[1].set(1.0f,0.0f);
> (*texcoords)[2].set(1.0f,1.0f);
> (*texcoords)[3].set(0.0f,1.0f);
>
> BGcolors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
> BGnormals->push_back(osg::Vec3(1.0f,1.0f,1.0f));
>
> BGBackgroundGeometry->setTexCoordArray(0,texcoords);
> BGBackgroundGeometry->setColorArray(BGcolors);
> BGBackgroundGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);
> BGBackgroundGeometry->setNormalArray(BGnormals);
> BGBackgroundGeometry->setNormalBinding(osg::Geometry::BIND_OVERALL);
> BGBackgroundGeometry->addPrimitiveSet(BGBackgroundIndices);
> BGBackgroundGeometry->setVertexArray(BGBackgroundVertices);
>
> BGBackgroundIndices->push_back(0);
> BGBackgroundIndices->push_back(1);
> BGBackgroundIndices->push_back(2);
> BGBackgroundIndices->push_back(3);
>
> BGStateSet->setTextureAttributeAndModes(0,BGTexture,osg::StateAttribute::ON);
> BGStateSet->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
> BGStateSet->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
> BGStateSet->setRenderBinDetails( 1, "RenderBin");
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>



More information about the osg-users mailing list