John,

Try setting your texture filters, like so

    _texture->setFilter(osg::Texture::MIN_FILTER,
osg::Texture::LINEAR_MIPMAP_LINEAR);
    _texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);


Glenn Waldron / @glennwaldron


On Fri, Dec 9, 2011 at 8:14 AM, John Farrier <[email protected]> wrote:

> Hi,
>
> Prior to v3.0, I had a textured plane in my application.  Since then (and
> perhaps the two aren't related, but...) my textured plane displays as more
> of a fuzzy checkerboard than the texture that I assigned.  It must be
> something simple that I have done wrong.  I've included my setup code
> below...a quick code review would be appreciated!
>
> Thank you!
>
> Cheers,
> John
>
>
> Code:
>
> {
>  this->_switch = new osg::Switch();
>  this->_transform = new osg::PositionAttitudeTransform;
>  this->_transform->setScale(this->_scale);
>  this->_transform->setPosition(this->_position);
>
>  // Setup the texture
>  osg::Image* const image = osgDB::readImageFile(this->_textureFile);
>
>  if(image != NULL)
>  {
>    image->setDataType(GL_ALPHA);
>    image->setPixelFormat(GL_ALPHA);
>
>    this->_texture = new osg::Texture2D(image);
>    this->_texture->setBorderColor(osg::Vec4(0, 0, 0, 0));
>    this->_texture->setBorderWidth(0);
>    this->_texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::MIRROR);
>    this->_texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::MIRROR);
>
>    this->_texenv = new osg::TexEnv();
>    this->_texenv->setMode(osg::TexEnv::MODULATE);
>  }
>
>  // Build the geometry to texture
>  osg::Group* const group = new osg::Group;
>
>  const float sizeUnit = 50000;
>  const float sizeUnitMultiplier = 8.0f;
>  const float sizeFinal = sizeUnit * sizeUnitMultiplier;
>  const float sizeTexture = sizeUnitMultiplier * 0.25f;
>
>  // left hand side of bounding box.
>  osg::Vec3 top_left(-sizeFinal, sizeFinal, altitude);
>  osg::Vec3 bottom_left(-sizeFinal, -sizeFinal, altitude);
>  osg::Vec3 bottom_right(sizeFinal, -sizeFinal, altitude);
>  osg::Vec3 top_right(sizeFinal, sizeFinal, altitude);
>  osg::Vec3 center(0, 0, 0);
>
>  osg::Geometry* const geom = new osg::Geometry;
>
>  osg::Vec3Array* const vertices = new osg::Vec3Array(4);
>  (*vertices)[0] = top_left;
>  (*vertices)[1] = bottom_left;
>  (*vertices)[2] = bottom_right;
>  (*vertices)[3] = top_right;
>  geom->setVertexArray(vertices);
>
>  osg::Vec2Array* const texcoords = new osg::Vec2Array(4);
>  (*texcoords)[0].set(0.0f, sizeTexture);
>  (*texcoords)[1].set(0.0f, 0.0f);
>  (*texcoords)[2].set(sizeTexture, 0.0f);
>  (*texcoords)[3].set(sizeTexture, sizeTexture);
>  geom->setTexCoordArray(0,texcoords);
>
>  osg::Vec3Array* const normals = new osg::Vec3Array(1);
>  (*normals)[0].set(0.0f,0.0f,1.0f);
>  geom->setNormalArray(normals);
>  geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
>
>  osg::Vec4Array* const colors = new osg::Vec4Array(1);
>  (*colors)[0].set(this->_color[0], this->_color[1], this->_color[2],
> this->_color[3]);
>  geom->setColorArray(colors);
>  geom->setColorBinding(osg::Geometry::BIND_OVERALL);
>
>  geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));
>
>  osg::Geode* const  geom_geode = new osg::Geode;
>  geom_geode->addDrawable(geom);
>
>  // set up the texture state.
>  this->_texture->setDataVariance(osg::Object::STATIC);
>  osg::StateSet* stateset = geom->getOrCreateStateSet();
>  stateset->setTextureAttributeAndModes(0, this->_texture.get(),
> osg::StateAttribute::ON);
>  stateset->setMode(GL_BLEND, osg::StateAttribute::ON);
>  stateset->setTextureAttribute(0, this->_texenv.get());
>  stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
>
>  osg::PolygonMode* const  polymode = new osg::PolygonMode;
>  polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,
> osg::PolygonMode::FILL);
>  stateset->setAttributeAndModes(polymode, osg::StateAttribute::OVERRIDE |
> osg::StateAttribute::ON);
>
>  group->addChild(geom_geode);
>  this->_transform->addChild(group);
>  this->_switch->addChild(this->_transform.get());
> }
>
>
>
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=44306#44306
>
>
>
>
>
> _______________________________________________
> 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

Reply via email to