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@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to