[osg-users] Texture is rendered strange

Thorsten Werner ThorstenWerner at gmx.net
Sat Nov 7 13:18:34 PST 2009


Hi,

Ive got a Problem. I have a Texture file loaded to a osg::Geometry. It is rendered completely different to what it looks like in the gimp. Why?

Here is the code:


Code:

 osg::Geometry* WidgElementGeometry = new osg::Geometry();
    osg::Vec3Array* WidgElementVert = new osg::Vec3Array;
    WidgElementVert->push_back(osg::Vec3(750,550,-1));
    WidgElementVert->push_back(osg::Vec3(800,550,-1));
    WidgElementVert->push_back(osg::Vec3(800,600,-1));
    WidgElementVert->push_back(osg::Vec3(750,600,-1));
    osg::DrawElementsUInt* WidgElementInd = new osg::DrawElementsUInt(osg::PrimitiveSet::POLYGON,0);
    WidgElementInd->push_back(0);
    WidgElementInd->push_back(1);
    WidgElementInd->push_back(2);
    WidgElementInd->push_back(3);
    osg::Vec2Array* texcoords = new osg::Vec2Array(4);
    (*texcoords)[0].set(0.0f, 0.0f);
    (*texcoords)[0].set(1.0f, 0.0f);
    (*texcoords)[0].set(1.0f, 1.0f);
    (*texcoords)[0].set(0.0f, 1.0f);
    WidgElementGeometry->setTexCoordArray(0,texcoords);
    osg::Texture2D* WidgElementTexture = new osg::Texture2D;
    WidgElementTexture->setDataVariance(osg::Object::DYNAMIC);
    osg::Image* WidgElementImage;
    WidgElementImage = osgDB::readImageFile("WidgElementCorner.tga");
    WidgElementTexture->setImage(WidgElementImage);
    osg::Vec3Array* WidgElementNormals = new osg::Vec3Array;
    WidgElementNormals->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));
    WidgElementGeometry->setNormalArray(WidgElementNormals);
    WidgElementGeometry->setNormalBinding(osg::Geometry::BIND_OVERALL);
    WidgElementGeometry->addPrimitiveSet(WidgElementInd);
    WidgElementGeometry->setVertexArray(WidgElementVert);
    osg::Geode* WidgGeode = new osg::Geode();
    WidgGeode->addDrawable(WidgElementGeometry);
    osg::StateSet* WidgElementStateSet = new osg::StateSet();
    WidgGeode->setStateSet(WidgElementStateSet);
    WidgElementStateSet->setTextureAttributeAndModes(0,WidgElementTexture, osg::StateAttribute::ON);
    WidgElementStateSet->setMode(GL_BLEND, osg::StateAttribute::ON);
    WidgElementStateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
    WidgElementStateSet->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);




Thank you!

Cheers,
Thorsten

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=19331#19331



-------------- next part --------------
A non-text attachment was scrubbed...
Name: Bildschirmfoto.png
Type: image/png
Size: 24859 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20091107/14b3350c/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: WidgElementCorner.png
Type: image/png
Size: 219 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20091107/14b3350c/attachment-0001.png>


More information about the osg-users mailing list