[osg-users] fixed size texture

Robert Osfield robert.osfield at gmail.com
Mon Aug 3 03:20:07 PDT 2015


My best guess is that the hardware is rounding down the tex coords when
sampling the texture so that it's not always picking out the right hand set
of pixels due to numerical precision issues.  Try setting the Border of the
osg::Texture2D::setBorderColor(Vec4(r,g,b,a)); and set the wrap mode to
CLAMP_TO_BORDER.

On 3 August 2015 at 10:39, Vitaliy Polyakov <poljak181 at yandex.ru> wrote:

>
> robertosfield wrote:
> > Try changing the Texure type to Texture2D and the tex coordinates to 0
> to 1.0.
> >
>
>
> New code,  but old behaviour..
>
>
> Code:
>
> osg::ref_ptr<osg::Node> createFixedSizeTexture()
> {
> osg::ref_ptr<osg::Image> image = osgDB::readImageFile("8x8.png");
> float width = image->s();
> float height = image->t();
>
> osg::Vec3Array* verts = new osg::Vec3Array(4);
> (*verts)[0] = osg::Vec3(-width/2.0f, -height/2.0, 0.0f);
> (*verts)[1] = osg::Vec3(width/2.0f, -height/2.0, 0.0f);
> (*verts)[2] = osg::Vec3(width/2.0f, height/2.0, 0.0f);
> (*verts)[3] = osg::Vec3(-width/2.0f,height/2.0, 0.0f);
>
> osg::Geometry* geometry = new osg::Geometry;
> geometry->setVertexArray( verts );
>
> osg::Vec2Array* texcoords = new osg::Vec2Array(4);
> (*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);
>
> geometry->setTexCoordArray(0, texcoords);
>
> osg::Vec4Array* colors = new osg::Vec4Array(1);
> (*colors)[0].set(1, 1, 1, 1);
> geometry->setColorArray( colors );
> geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
>
> geometry->addPrimitiveSet( new osg::DrawArrays(GL_QUADS, 0, 4));
>
> osg::StateSet* stateSet = geometry->getOrCreateStateSet();
>
> osg::Texture2D* texture = new osg::Texture2D( image );
> texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::NEAREST);
> texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::NEAREST);
> texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
> texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
> stateSet->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);
>
> stateSet->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
> stateSet->setAttributeAndModes( new osg::Depth(osg::Depth::ALWAYS,false),
> 1 );
>
> osg::Geode* geode = new osg::Geode;
> geode->addDrawable( geometry );
>
> osg::AutoTransform *at = new osg::AutoTransform;
> at->setAutoScaleToScreen(true);
> at->setAutoRotateMode( osg::AutoTransform::ROTATE_TO_SCREEN );
> at->addChild( geode );
>
> return at;
> }
>
>
>
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=64574#64574
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20150803/125df87f/attachment-0003.htm>


More information about the osg-users mailing list