Hello Frans,
> m_osg_shape = new osg::ShapeDrawable( new osg::Box(
> osg::Vec3f( 0, 0, -0.005f ), 29.7f, 21.0f, 0.01f ) );
> osg::Image* image = osgDB::readImageFile( "gras.jpg" );
> osg::Texture2D* tex2d = new osg::Texture2D( image );
> tex2d->setWrap( osg::Texture::WRAP_S, osg::Texture::REPEAT );
> tex2d->setWrap( osg::Texture::WRAP_T, osg::Texture::REPEAT );
> m_osg_shape->getOrCreateStateSe
> t()->setTextureAttributeAndModes( 0, tex2d, osg::StateAttribute::ON );
>
> but the setWrap() command doesn't seem to have any effect for me. I
> guess I have to specify the relative alignment for the texture manually
> but I have no clue how I do this for a osg::Box. The examples only deal
> with manuallly built geoms.
The wrap modes only take effect if your geometry has texture coordinates
outside the 0.0 - 1.0 range. In the case of the osg::Box shapedrawable,
it generates texcoords that go from 0.0 to 1.0 on each face, in both the
s and t directions. So you'll never see wrapping on that.
You'll have to make your own box, and specify the texture coordinates
you want. For example 0.0 - 2.0 on each axis for each face will give you
a texture repeated twice (assuming you set up your texture as above).
It's not hard... Oh heck, I have the code here to create a basic box, so
here it is:
osg::Geometry* createBox()
{
osg::Geometry* box = new osg::Geometry;
// Vertices
osg::Vec3Array* vertices = new osg::Vec3Array;
vertices->push_back(osg::Vec3(-.5, -.5, -.5)); // 0
vertices->push_back(osg::Vec3( .5, -.5, -.5)); // 3
vertices->push_back(osg::Vec3( .5, -.5, .5)); // 5
vertices->push_back(osg::Vec3(-.5, -.5, .5)); // 1
vertices->push_back(osg::Vec3(-.5, -.5, .5)); // 1
vertices->push_back(osg::Vec3( .5, -.5, .5)); // 5
vertices->push_back(osg::Vec3( .5, .5, .5)); // 7
vertices->push_back(osg::Vec3(-.5, .5, .5)); // 4
vertices->push_back(osg::Vec3(-.5, -.5, -.5)); // 0
vertices->push_back(osg::Vec3(-.5, -.5, .5)); // 1
vertices->push_back(osg::Vec3(-.5, .5, .5)); // 4
vertices->push_back(osg::Vec3(-.5, .5, -.5)); // 2
vertices->push_back(osg::Vec3( .5, -.5, -.5)); // 3
vertices->push_back(osg::Vec3( .5, .5, -.5)); // 6
vertices->push_back(osg::Vec3( .5, .5, .5)); // 7
vertices->push_back(osg::Vec3( .5, -.5, .5)); // 5
vertices->push_back(osg::Vec3( .5, .5, -.5)); // 6
vertices->push_back(osg::Vec3(-.5, .5, -.5)); // 2
vertices->push_back(osg::Vec3(-.5, .5, .5)); // 4
vertices->push_back(osg::Vec3( .5, .5, .5)); // 7
vertices->push_back(osg::Vec3( .5, -.5, -.5)); // 3
vertices->push_back(osg::Vec3(-.5, -.5, -.5)); // 0
vertices->push_back(osg::Vec3(-.5, .5, -.5)); // 2
vertices->push_back(osg::Vec3( .5, .5, -.5)); // 6
box->setVertexArray(vertices);
// Normals
osg::Vec3Array* normals = new osg::Vec3Array;
normals->push_back(osg::Vec3( 0, -1, 0));
normals->push_back(osg::Vec3( 0, -1, 0));
normals->push_back(osg::Vec3( 0, -1, 0));
normals->push_back(osg::Vec3( 0, -1, 0));
normals->push_back(osg::Vec3( 0, 0, 1));
normals->push_back(osg::Vec3( 0, 0, 1));
normals->push_back(osg::Vec3( 0, 0, 1));
normals->push_back(osg::Vec3( 0, 0, 1));
normals->push_back(osg::Vec3(-1, 0, 0));
normals->push_back(osg::Vec3(-1, 0, 0));
normals->push_back(osg::Vec3(-1, 0, 0));
normals->push_back(osg::Vec3(-1, 0, 0));
normals->push_back(osg::Vec3( 1, 0, 0));
normals->push_back(osg::Vec3( 1, 0, 0));
normals->push_back(osg::Vec3( 1, 0, 0));
normals->push_back(osg::Vec3( 1, 0, 0));
normals->push_back(osg::Vec3( 0, 1, 0));
normals->push_back(osg::Vec3( 0, 1, 0));
normals->push_back(osg::Vec3( 0, 1, 0));
normals->push_back(osg::Vec3( 0, 1, 0));
normals->push_back(osg::Vec3( 0, 0, -1));
normals->push_back(osg::Vec3( 0, 0, -1));
normals->push_back(osg::Vec3( 0, 0, -1));
normals->push_back(osg::Vec3( 0, 0, -1));
box->setNormalArray(normals);
box->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
// Faces
box->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0,
vertices->size()));
// Colors
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1,1,1,1));
box->setColorArray(colors);
box->setColorBinding(osg::Geometry::BIND_OVERALL);
return box;
}
Just add the returned geometry as drawable to a geode. This code does
not specify texcoords, so I have left you a bit of work... :-) But you
should be able to figure it out. Check the doxygen for
Geometry::setTexCoordArray(unsigned int unit, Array* array). You need
one texcoord (Vec2) per vertex, btw.
Hope this helps,
J-S
--
______________________________________________________
Jean-Sebastien Guay [EMAIL PROTECTED]
http://www.cm-labs.com/
http://whitestar02.webhop.org/
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org