The following code originated in the osgtexture2D. I was trying to boil it
down to the minimal essential components to achieve my objectives. I wanted
to create an image without loading it from a file. IIRC, I ran into the
problem before, but I don't recall what fixed it. If I load the image from a
file, I can then change the data with the result appearing in the scene. If
I call image->allocate() (which is commented out), that makes it behave as if
the data I put in the image isn't there. I can pull the data out, and print
it, or check its size and validity. But when I try to use it in the scene,
it's as if it's not there.
Any suggestions?
osg::Node* createWrapWall(osg::BoundingBox& bb,const std::string& filename)
{
osg::Group* group = new osg::Group;
osg::Geometry* geom = new osg::Geometry;
osg::Vec3Array* vertices = new osg::Vec3Array;
vertices->push_back(osg::Vec3(bb.xMax(),bb.yMax(),bb.zMax()));
vertices->push_back(osg::Vec3(bb.xMax(),bb.yMax(),bb.zMin()));
vertices->push_back(osg::Vec3(bb.xMax(),bb.yMin(),bb.zMin()));
vertices->push_back(osg::Vec3(bb.xMax(),bb.yMin(),bb.zMax()));
geom->setVertexArray(vertices);
osg::Vec2Array* texcoords = new osg::Vec2Array(4);
(*texcoords)[0].set(-1.0f,2.0f);
(*texcoords)[1].set(-1.0f,-1.0f);
(*texcoords)[2].set(2.0f,-1.0f);
(*texcoords)[3].set(2.0f,2.0f);
geom->setTexCoordArray(0,texcoords);
osg::Vec3Array* normals = new osg::Vec3Array(1);
(*normals)[0].set(-1.0f,0.0f,0.0f);
geom->setNormalArray(normals);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
osg::Vec4Array* colors = new osg::Vec4Array(1);
(*colors)[0].set(1.0f,1.0f,1.0f,0.5f);
geom->setColorArray(colors);
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));
osg::Geode* geom_geode = new osg::Geode;
geom_geode->addDrawable(geom);
group->addChild(geom_geode);
osg::Texture2D* texture(new osg::Texture2D);
osg::Image * image(osgDB::readImageFile(filename));
texture->setImage(image);
// image->allocateImage(128, 64, 1, GL_RGB ,GL_UNSIGNED_SHORT_4_4_4_4);
unsigned char* cptr(image->data());
const unsigned sz(image->getImageSizeInBytes());
for(unsigned i=0; i < sz;++i)
switch(i%4){
case 0:*cptr++=255;break;
case 1:*cptr++=0 ;break;
case 2:*cptr++=64 ;break;
case 3:*cptr++=255;break;
}
osg::StateSet* ss = geom->getOrCreateStateSet();
ss->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
ss->setMode(GL_BLEND,osg::StateAttribute::ON);
ss->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
return group;
}
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/