Hi,
I am texturing a disk (circle) I created with a square texture. The texture has
a transparent background so any parts of it that don't overlap the disk and
hang over the sides are transparent.
The code that does this is below. The Geode circleGeodeImage has been
previously created and added to the scene, but does not have a texture on it
until the code below does that.
When this is displayed, the image is on the disk as it should be, but it is
repeated multiple times in the -Z (down the screen) direction. The repeated
image overlaps itself so that the 2nd image starts about 25% from the top of
the disk and overlaps the 75% of the disk below that, and the 3rd image starts
about 50% from the top, etc.. So the top 25% is OK, the the overlapping is
happening below that.
I looked at the texture and verticies that are being used and they look correct
to me.
I tried clamping it to see what happened, but it made no differnce.
osg::ref_ptr<osg::Image> image = osgDB::readImageFile
("jet_fighter3-nobackground.png");
if ( ! image)
{
QMessageBox::critical (NULL, QObject::tr ("Image file is missing"),
QObject::tr ("jet_fighter3-nobackgroundof.png"));
return 1;
}
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D (image.get ());
osg::ref_ptr<osg::Vec2Array> texcoords = new osg::Vec2Array;
osg::Drawable *pDrawable = circleGeodeImage->getDrawable (0);
osg::Geometry *geom = pDrawable->asGeometry ();
osg::Vec3 *pVertex = (osg::Vec3 *) geom->getVertexArray ();
int vertCount = 0;
for (osg::Vec3Array::iterator iVertex = pVertexs->begin (); iVertex !=
pVertexs->end (); ++iVertex)
{
float xVertex = iVertex->x ();
float zVertex = iVertex->z ();
float x = (xVertex + 1.) / 2.;
float y = (zVertex + 1.) / 2.;
std::cout << "Map vertex " << xVertex << ", " << zVertex << " to
texture " << x << ", " << y << std::endl;
texcoords->push_back (osg::Vec2 (x, y));
vertCount++;
}
geom->setTexCoordArray (0, texcoords.get ());
texture->setWrap (osg::Texture::WRAP_R, osg::Texture::CLAMP);
texture->setWrap (osg::Texture::WRAP_S, osg::Texture::CLAMP);
translateNodeDiskRotate->getOrCreateStateSet ()->setTextureAttributeAndModes
(0, texture.get (), osg::StateAttribute::ON);
Thank you!
Cheers,
Zachary
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=46319#46319
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org