Re: [osg-users] Tiled textures on osg::Box
Hi Frans, If you want fine grained control over rendering then osg::Box/osg::ShapeDrawable are not the things to use. osg::Box is really just a shape primitive that exist to support mathematical primitives used in physics engines. ShapeDrawable does allow you to render these shapes but its just a convenience class that isn't intended for general purpose rendering or high performance. For full control I'd recommend creating the geometry using osg::Geometry, see the osggeometry example for details. Robert. On Thu, Feb 14, 2008 at 7:31 AM, Frans Fürst <[EMAIL PROTECTED]> wrote: > Hi everyone, > > I'm afraid I have a very simple question, but I didn't find answer in the > examples or tutorials. Perhaps you can give me a small hint.. > > I want to add texture to an new osg::Box, and I want to have it repeated. So > I tried: > > 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. > > Is there a way to have tiled textures on a osg::Box or will I have to build > my own boxes? > > Thanks a lot, > > Frans > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > > ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Tiled textures on osg::Box
Jean-Sébastien Guay wrote: >> m_osg_shape = new osg::ShapeDrawable( new osg::Box( >> osg::Vec3f( 0, 0, -0.005f ), 29.7f, 21.0f, 0.01f ) ); >>... >> >> 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). You could also assign a texture matrix that scales the texture coordinates to something useful for your purposes: osg::TexMat* tm = new osg::TexMat; tm->setMatrix(osg::Matrix::scale(2,2,2)); m_osg_shape->setAttributeAndModes(tm, osg::StateAttribute::ON); However, doing your own box also gives you more control over how texture coords are assigned so you may want to do that in the end anyway... /ulrich ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Tiled textures on osg::Box
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 PROTECTE
[osg-users] Tiled textures on osg::Box
Hi everyone, I'm afraid I have a very simple question, but I didn't find answer in the examples or tutorials. Perhaps you can give me a small hint.. I want to add texture to an new osg::Box, and I want to have it repeated. So I tried: 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->getOrCreateStateSet()->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. Is there a way to have tiled textures on a osg::Box or will I have to build my own boxes? Thanks a lot, Frans ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org