|
在OSG 2.4中,将纹理映射到一个四边形上,在纹理的边缘,即纹理坐标u,v为0或1时,会产生一个黑边,如何消除。代码如下:
osg::Image* image = osgDB:: readImageFile("earthmap1k.jpg");
if (!image) return NULL;
osg::StateSet* stateset = new osg:: StateSet;
osg::Texture2D* texture = new osg:: Texture2D;
texture->setImage(image);
stateset->setTextureAttributeAndModes(0, texture, osg:: StateAttribute::ON );
stateset->setMode( GL_LIGHTING, osg:: StateAttribute:ROTECTED );
osg::Geode* geode = new osg::Geode();
geode->setStateSet(stateset);
osg::Geometry* Geom = new osg::Geometry();
osg::Vec3Array* vertices = new osg::Vec3Array;
osg::Vec2Array* texCoords = new osg::Vec2Array;
vertices->push_back( osg::Vec3(-100, 0, -100) );
vertices->push_back( osg::Vec3(-100, 0, 100) );
vertices->push_back( osg::Vec3(0, 0, 100) );
vertices->push_back( osg::Vec3(0, 0, -100) );
texCoords->push_back(osg::Vec2(0, 0));
texCoords->push_back(osg::Vec2(0, 1));
texCoords->push_back(osg::Vec2(1, 1));
texCoords->push_back(osg::Vec2(1, 0));
Geom->setVertexArray(vertices);
Geom->addPrimitiveSet(new osg:rawArrays(osg:: PrimitiveSet:: POLYGON, 0, vertices->size()));
osg:: Vec4Array* colors = new osg:: Vec4Array;
colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
Geom->setColorArray(colors);
Geom->setColorBinding(osg:: Geometry:: BIND_OVERALL);
Geom->setTexCoordArray(0, texCoords);
geode->addDrawable(Geom); |
|