Hi Erik, That looks like a texture wrap issue. Try setting your texture wrap mode to CLAMP_TO_EDGE:
pTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); pTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); Cheers, Farshid On Mon, May 11, 2015 at 12:39 PM, Erik Hensens <[email protected]> wrote: > Hello all! > > I'm having trouble with image texture mapping a geode. Specifically, where > the top and the bottom of the image meet, there is a dark shadow effect > that I want to avoid. > > I've created the simplest example of how I'm attempting the texture > mapping and I've taken screenshots that show the unwanted shadow (please > see the attached screenshots and the overlay image itself). > > Below is the code I'm using. As you can see, it's very simple: just four > quadrangle faces that form four sides of an open-ended box. I've attempted > to map the overlay image around the entire box so that the top and bottom > meet at one of the four edges. > > Does anyone have any idea what I'm doing wrong or how I can modify my code > to get rid of the shadow effect? Thanks a bunch in advance! > > > Code: > // Create the new geode node > osg::ref_ptr < osg::Geode > pGeode = new osg::Geode; > > // Create the single new geometry > osg::ref_ptr < osg::Geometry > pGeometry = new osg::Geometry; > > // The vertex array to define the geometry shape > osg::ref_ptr < osg::Vec3Array > pVertices = new osg::Vec3Array; > > // Add face 1/4 quad vertices > pVertices->push_back(osg::Vec3(0.0f, 0.0f, 0.0f)); > pVertices->push_back(osg::Vec3(10.0f, 0.0f, 0.0f)); > pVertices->push_back(osg::Vec3(10.0f, 5.0f, 5.0f)); > pVertices->push_back(osg::Vec3(0.0f, 5.0f, 5.0f)); > > // Add face 2/4 quad vertices > pVertices->push_back(osg::Vec3(0.0f, 5.0f, 5.0f)); > pVertices->push_back(osg::Vec3(10.0f, 5.0f, 5.0f)); > pVertices->push_back(osg::Vec3(10.0f, 0.0f, 10.0f)); > pVertices->push_back(osg::Vec3(0.0f, 0.0f, 10.0f)); > > // Add face 3/4 quad vertices > pVertices->push_back(osg::Vec3(0.0f, 0.0f, 10.0f)); > pVertices->push_back(osg::Vec3(10.0f, 0.0f, 10.0f)); > pVertices->push_back(osg::Vec3(10.0f, -5.0f, 5.0f)); > pVertices->push_back(osg::Vec3(0.0f, -5.0f, 5.0f)); > > // Add face 4/4 quad vertices > pVertices->push_back(osg::Vec3(0.0f, -5.0f, 5.0f)); > pVertices->push_back(osg::Vec3(10.0f, -5.0f, 5.0f)); > pVertices->push_back(osg::Vec3(10.0f, 0.0f, 0.0f)); > pVertices->push_back(osg::Vec3(0.0f, 0.0f, 0.0f)); > > // Set the vertex array on the geometry > pGeometry->setVertexArray(pVertices); > > // Create the geometry's color array > osg::ref_ptr < osg::Vec4Array > pColors = new osg::Vec4Array; > pColors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); > > // Set the color array on the geometry > pGeometry->setColorArray(pColors); > pGeometry->setColorBinding(osg::Geometry::BIND_OVERALL); > > // Set the quad draw array on the geometry > osg::ref_ptr < osg::DrawArrays > pDrawArrays = new > osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, static_cast < GLsizei > >(pVertices->size())); > pGeometry->addPrimitiveSet(pDrawArrays); > > // Load the overlay image > osg::ref_ptr < osg::Image > pImage = osgDB::readImageFile("overlay.png"); > > // Create the image texture > osg::ref_ptr < osg::Texture2D > pTexture = new osg::Texture2D(pImage); > > // Create the texture coordinates array > osg::ref_ptr < osg::Vec2Array > pTexCoords = new osg::Vec2Array; > > // Set face 1/4 quad texture overlay coordinates > pTexCoords->push_back(osg::Vec2(0.0f, 0.0f)); > pTexCoords->push_back(osg::Vec2(1.0f, 0.0f)); > pTexCoords->push_back(osg::Vec2(1.0f, 0.25f)); > pTexCoords->push_back(osg::Vec2(0.0f, 0.25f)); > > // Set face 2/4 quad texture overlay coordinates > pTexCoords->push_back(osg::Vec2(0.0f, 0.25f)); > pTexCoords->push_back(osg::Vec2(1.0f, 0.25f)); > pTexCoords->push_back(osg::Vec2(1.0f, 0.50f)); > pTexCoords->push_back(osg::Vec2(0.0f, 0.50f)); > > // Set 3/4 quad texture overlay coordinates > pTexCoords->push_back(osg::Vec2(0.0f, 0.50f)); > pTexCoords->push_back(osg::Vec2(1.0f, 0.50f)); > pTexCoords->push_back(osg::Vec2(1.0f, 0.75f)); > pTexCoords->push_back(osg::Vec2(0.0f, 0.75f)); > > // Set 4/4 quad texture overlay coordinates > pTexCoords->push_back(osg::Vec2(0.0f, 0.75f)); > pTexCoords->push_back(osg::Vec2(1.0f, 0.75f)); > pTexCoords->push_back(osg::Vec2(1.0f, 1.0f)); > pTexCoords->push_back(osg::Vec2(0.0f, 1.0f)); > > // Set the geometry's texture coordinates array > pGeometry->setTexCoordArray(0, pTexCoords); > > // Get the geometry's stateset > osg::ref_ptr < osg::StateSet > pStateSet = > pGeometry->getOrCreateStateSet(); > > // Set the texture on the stateset > pStateSet->setTextureAttributeAndModes(0, pTexture, > osg::StateAttribute::ON); > > // Set the geometry's stateset > pGeometry->setStateSet(pStateSet); > > // Add the single drawable to the geode node > pGeode->addDrawable(pGeometry); > > // Add this new geode to the scene > pTopGroupNode->addChild(pGeode); > > > > Cheers, > Erik > > ------------------ > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=63711#63711 > > > > > _______________________________________________ > 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

